EthernetServer server get value of another variable?

I need the server EthernetServer (80) function; take the value of another variable, l this variable is already being read in the SD card and passed to the int variable localPort; I can actually print it on the serial and everything, but when trying EthernetServer server (localPort); not of right, remembering that IP and mask work already coming from the SD card port just is not passed to the server.

Has anyone experienced this have any idea why does not work?

without seeing your code it will be very difficult

OK,my fault,

I followed this tutorial and adapted for my application

//teste ler do cartão
byte myIP[4];//IP gravado no SD Card
byte myNM[4];//Mascara de rede gravada no SD Card
byte myPort[0];//Porta gravada no SD Card
unsigned int localPort = int(myPort[0]);
//int porta = localPort;
//teste ler do cartão

// MAC address from Ethernet shield sticker under board
byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//IPAddress ip(192, 168, 0, 136); // IP address, may need to change depending on network
EthernetServer server(1000); // create a server at port 80
File webFile; // the web page file on the SD card
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0; // index into HTTP_req buffer
boolean LED_state[11] = {0}; // stores the states of the 8 LEDs

I followed this tutorial

How about you follow this one, instead:

EthernetServer server(1000); // create a server at port 80

conflict between comment and code ....
I expect 1000 should be replaced by localport.

OK I already tried to do the replacement EthernetServer server (localPort);

and still does not answer the door


Checking Port 7777...
Warning: fsockopen() [function.fsockopen]: unable to connect to 189.4.25.142:7777 (Connection timed out) in /var/www/moodle/internas/networksresultado.php on line 375
Port 7777 does not appear to be open.


taking advantage which the command to print the serial port?

Serial.println (EthernetServer server (localPort));

byte myPort[0];//Porta gravada no SD Card
unsigned int localPort = int(myPort[0]);

An array explicitly sized to hold zero elements? WTF?

Then, you access beyond the end of the array, getting garbage, and assign that as localPort, Why?

OK wrong in the array and changed to [1], I want to do is read the SD card the network parameters without compiling the arduino to change these values??, just getting to the settings.txt containing IP-PORT-network mask, this code works on another project with UDP socket.

Summarized as follows and the debug code via serial monitor at the end

//teste ler do cartão
byte myIP[4];//IP gravado no SD Card pega valor normalmente
byte myNM[4];//Mascara de rede gravada no SD Card pega valor normalmente
byte myPort[1];//Porta gravada no SD Card
unsigned int localPort = int(myPort[1]);//pega o valor gravado no indice [0]
int porta = localPort;
//teste ler do cartão

// MAC address from Ethernet shield sticker under board
byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//IPAddress ip(192, 168, 0, 136); // IP address, may need to change depending on network
EthernetServer server(1000); // create a server at port 80
//EthernetServer server(localPort);
File webFile; // the web page file on the SD card
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0; // index into HTTP_req buffer
boolean LED_state[11] = {0}; // stores the states of the 8 LEDs

void loop(){}

void setup()
{

// disable Ethernet chip
pinMode(53, OUTPUT);//pino sd card mega no uno é o 10
digitalWrite(10, HIGH);
Serial.begin(9600);

// initialize SD card
Serial.println(“Initializing SD card…”);
if (!SD.begin(4)) {
Serial.println(“ERROR - SD card initialization failed!”);
return; // init failed
}
Serial.println(“SUCCESS - SD card initialized.”);
// check for index.htm file
if (!SD.exists(“index.htm”)) {
Serial.println(“ERROR - Can’t find index.htm file!”);
return; // can’t find index file
}
Serial.println(“SUCCESS - Found index.htm file.”);

//teste ler do cartão***************************************************************
//teste ler do cartão***************************************************************
//teste ler do cartão***************************************************************
File fh = SD.open(“network.txt”,FILE_READ);
char netBuffer[32];

if(!fh)
{
Serial.println(“SD open fail”);
return;
}

int chPos = 0;
int lineNo = 0;

while(fh.available())
{
char ch = fh.read();
if(ch == ‘\r’) {
chPos = 0;

switch(lineNo) {

case 0:
// Serial.print(“ip “);
sscanf(netBuffer,”%u.%u.%u.%u”,&myIP[0],&myIP[1],&myIP[2],&myIP[3]);
break;

case 1:
//Serial.print(“netmask “);
sscanf(netBuffer,”%u.%u.%u.%u”,&myNM[0],&myNM[1],&myNM[2],&myNM[3]);
break;

case 2:
//Serial.print(“Port “);
sscanf(netBuffer,”%u.%u.%u.%u”,&myPort[0]);
break;
}
//Serial.println(netBuffer);
lineNo++;
}
else if(ch == ‘\n’) {
// do nothing
}
else if(chPos < 31) {
netBuffer[chPos] = ch;
chPos++;
netBuffer[chPos] = 0;
}
}
fh.close();
int x;

Serial.print("\r\nip “);
for(x=0;x<4;x++) {
Serial.print(myIP,DEC);
if(x<3) Serial.print(”.");
}
Serial.print("\r\nnetmask “);
for(x=0;x<4;x++) {
Serial.print(myNM,DEC);
if(x<3) Serial.print(”.");
}
/* Serial.print("\r\nPort “);
for(x=0;x<4;x++) {
Serial.print(myPort[1],DEC);
if(x<3) Serial.print(”.");
}*/
Serial.println("\r\nStarting ethernet");
Ethernet.begin(mac,myIP,myNM,myPort);
Serial.println(Ethernet.localIP());
Serial.print(“Local Port:”);
Serial.println(localPort);

//teste ler do cartão***************************************************************
//teste ler do cartão***************************************************************
//teste ler do cartão***************************************************************

DEBUG NO MONITOR SERIAL

Initializing SD card…
SUCCESS - SD card initialized.
SUCCESS - Found index.htm file.

ip 192.168.0.140
netmask 255.255.255.0
Starting ethernet
192.168.0.140
Local Port:7777
GET /ajax_inputs&nocache=342140.20357467234 HTTP/1.1

OK wrong in the array and changed to [1]

You STILL can’t store 2 values in a one element array.

Please use code tags when posting code ==> # button above smiley's

CTRL-T in the IDE formats the code, makes it more readable.