okay I though I was done but it looks like I have one more issue with the setting file it when I try and get the unitID it retrieves it in the buffer but does not display it correctly as a byte it is meant to be 1000 no idea how come it is 232
... inside the Loop
Mac Address Print Out = mac=DE:AD:BE:EF:FE:ED
IP Address Print Out = ip=192.168.3.177
Unitid Address Print Out = unitid=1000
Connecting to network
Mac: DE:AD:BE:EF:FE:ED
IP: 192.168.3.177
Unitid: 232
IP Address Set = 192.168.3.177
the only thing I have added was
byte unitid[1] = {0};
else if(strncmp(buffer, "unitid", 6) == 0)
{
Serial.print("Unitid Address Print Out = ");
Serial.println(buffer);
// buffer contains ipvalues
sscanf(buffer, "unitid = %u", &unitid[1]);
}
Serial.print("Unitid: ");
Serial.println( unitid[1]);
Serial.print("Unitid: ");
Serial.println( unitid[1]);
#include <SdFat.h>
#include <SdFatUtil.h>
#include <Ethernet.h>
#include <SPI.h>
#define SD_SELECT 4
#define ETHERNET_SELECT 10
/************ ETHERNET STUFF ************/
//byte macz[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//byte ip[] = { 192, 168, 3, 177 };
EthernetClient client;
byte mac[6] = {0};
byte ip[4] = {0};
byte st_dns[4] = {0};
byte gateway[4] = {0};
byte subnet[4] = {0};
byte unitid[1] = {0};
EthernetServer server(80);
/************ SDCARD STUFF ************/
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
SdFat sd;
// SD chip select pin
const uint8_t chipSelect = 4;
// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))
void setup() {
Serial.begin(9600);
pinMode(SD_SELECT, OUTPUT);
digitalWrite(SD_SELECT, HIGH); // disable SD card
pinMode(ETHERNET_SELECT, OUTPUT);
digitalWrite(ETHERNET_SELECT, HIGH); // disable Ethernet
// Initialize SdFat or print a detailed error message and halt
// Use half speed like the native library.
// change to SPI_FULL_SPEED for more performance.
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
const int line_buffer_size = 50;
char buffer[line_buffer_size];
// *******************************Configuration file setting************************************************************
//must be stored in root and like eg.
//mac=DE:AD:BE:EF:FE:ED
//ip=192.168.3.177
//unitid=1000
//
ifstream sdin("CONFIG.TXT");
Serial.println("... inside the Loop");
while (sdin.getline(buffer, line_buffer_size, '\n') || sdin.gcount())
{
if(strncmp(buffer, "mac", 3) == 0)
{ Serial.print("Mac Address Print Out = ");
Serial.println(buffer);
// buffer contains mac values
sscanf(buffer, "mac=%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
}
else if(strncmp(buffer, "ip", 2) == 0)
{
Serial.print("IP Address Print Out = ");
Serial.println(buffer);
// buffer contains ipvalues
sscanf(buffer, "ip = %u.%u.%u.%u", &ip[0], &ip[1], &ip[2], &ip[3]);
}
else if(strncmp(buffer, "unitid", 6) == 0)
{
Serial.print("Unitid Address Print Out = ");
Serial.println(buffer);
// buffer contains ipvalues
sscanf(buffer, "unitid = %u", &unitid[1]);
}
// More record checking/parsing
}
// ******************************Pint out Setting************************************************************
Serial.println("Connecting to network");
Serial.print("Mac: ");
Serial.print( mac[0], HEX);
Serial.print(":");
Serial.print( mac[1], HEX);
Serial.print(":");
Serial.print( mac[2], HEX);
Serial.print(":");
Serial.print( mac[3], HEX);
Serial.print(":");
Serial.print( mac[4], HEX);
Serial.print(":");
Serial.println( mac[5], HEX);
Serial.print("IP: ");
Serial.print( ip[0]);
Serial.print(".");
Serial.print( ip[1]);
Serial.print(".");
Serial.print( ip[2]);
Serial.print(".");
Serial.println( ip[3]);
Serial.print("Unitid: ");
Serial.println( unitid[1]);
Ethernet.begin(mac, ip);
Serial.print("IP Address Set = ");
Serial.println(Ethernet.localIP());
delay(1000);
}
void loop() {
// nothing happens after setup
}