I am having an issue with my variable declaration anything that is directly after the space below mydns doesn't return a value when referenced if I move a different var there it behaves the same and if I move it somewhere else as long as it isn't directly below mydns it works fine. Any help would be appreciated.
#include <SPI.h>
#include <SdFat.h>
#include <Ethernet.h>
const uint8_t chipSelect = 4; //SD chip select pin
SdFat sd; //file system object
byte mac[] = {0xDE,0xAD,0xBE,0xEF,0xFE,0xED}; //Default MAC
byte ip[] = {192,168,168,168}; //Default IP
IPAddress sn;
IPAddress gw;
IPAddress mydns;
char test[] = "test";
char mywebhost[] = "mywebhost";
boolean lastconnected = true;
boolean hostrequest = true;
unsigned long lastwebrequest = 0;
unsigned long webrequestintvl = 60000;
int failedrequests = 0;
#define buffermax 50
int buffersize;
char buffer[buffermax];
boolean startbuffer = false;
EthernetServer server(80);
EthernetClient client;
void MyFileRead(char* myfile) {
Serial.print("My File: ");
Serial.println(myfile);
const int line_buffer_size = 30;
char sdbuffer[line_buffer_size];
ifstream sdin(myfile);
while (sdin.getline(sdbuffer, line_buffer_size, '\n') || sdin.gcount()) {
if(strncmp(sdbuffer, "mac", 3) == 0) {
sscanf(sdbuffer, "mac=%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
} else if (strncmp(sdbuffer, "ip", 2) == 0) {
sscanf(sdbuffer, "ip=%u.%u.%u.%u", &ip[0], &ip[1], &ip[2], &ip[3]);
} else if (strncmp(sdbuffer, "sn", 2) == 0) {
sscanf(sdbuffer, "sn=%u.%u.%u.%u", &sn[0], &sn[1], &sn[2], &sn[3]);
} else if (strncmp(sdbuffer, "gw", 2) == 0) {
sscanf(sdbuffer, "gw=%u.%u.%u.%u", &gw[0], &gw[1], &gw[2], &gw[3]);
} else if (strncmp(sdbuffer, "dns", 3) == 0) {
sscanf(sdbuffer, "dns=%u.%u.%u.%u", &mydns[0], &mydns[1], &mydns[2], &mydns[3]);
}
}
}
void WebRequest() {
Serial.print("Requesting: ");
Serial.println(test);
Serial.print("Requesting: ");
Serial.println(mywebhost);
Serial.println("LastConnected: ");
Serial.println(lastconnected);
Serial.println("Request: ");
Serial.println(hostrequest);
}
void setup() {
Serial.begin(9600);
delay(500);
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
Serial.println("Initialization Failed.");
sd.initErrorHalt();
}
Serial.println("Initialization Done.");
char myfile[] = "ipconf.txt";
MyFileRead(myfile);
WebRequest();
delay(500);
Ethernet.begin(mac,ip,mydns,gw,sn);
Serial.print("IP Address: ");
Serial.println(Ethernet.localIP());
}
void loop() {
}