Well the following is my code that reads from sd card (which it does pretty well accurately)
#include <SD.h>
File myFile;
char input[200], ip_add[16], dns[16], port[5], ssid[32], pass[50];
String ip_string, dns_string, ssid_string, pass_string, port_string;
int count=0, initial=0, counter=0;
boolean run=false;
void setup()
{
Serial.begin(9600);
// Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT);
if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
//Serial.println("initialization done.");
// Open the file for reading:
myFile = SD.open("settings.txt", FILE_READ);
if (myFile) {
Serial.println("settings.txt:");
count = 0;
// read from the file until there's nothing else in it:
while (myFile.available()) {
//Serial.write(myFile.read());
input[count++] = myFile.read();
}
Serial.print(input);
for (int i=5; i < 201; i++){
if (input[i] == '='){
initial = i+1;
counter++;
}
if (input[i] == ','){
int set = i;
if (counter == 1){
for (int a=initial;a < set; a++ ){
ip_add[a-initial] = input[a];
}
}
if (counter == 2){
for (int a=initial;a < set; a++ ){
dns[a-initial] = input[a];
}
}
if (counter == 3){
for (int a=initial;a < set; a++ ){
port[a-initial] = input[a];
}
}
if (counter == 4){
for (int a=initial;a < set; a++ ){
ssid[a-initial] = input[a];
}
}
if (counter == 5){
for (int a=initial;a < set; a++ ){
pass[a-initial] = input[a];
}
counter == 0;
}
//initial = 0;
//set = 0;
}
}
Serial.println("IP: ");
Serial.println(ip_add);
Serial.println("DNS: ");
Serial.println(dns);
Serial.println("Port: ");
Serial.println(port);
Serial.println("SSID: ");
Serial.println(ssid);
Serial.println("PASS: ");
Serial.println(pass);
ip_string = ip_add;
dns_string = dns;
port_string = port;
ssid_string = ssid;
pass_string = pass;
run = true;
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening settings.txt");
}
}
void loop()
{
if (run == true) {
Serial.print("$$");
delay(200);
Serial.print("set ip address " + ip_string);
Serial.print("\r");
delay(200);
Serial.print("set ip nm " + dns_string);
Serial.print("\r");
delay(200);
Serial.print('set ip localport' + port_string);
Serial.print("\r");
delay(200);
Serial.print("set wlan ssid " + ssid_string);
Serial.print("\r");
delay(200);
Serial.print("set wlan phrase " + pass_string);
Serial.print("\r");
delay(200);
Serial.print("save");
Serial.print("\r");
delay(200);
Serial.print("exit");
Serial.print("\r");
delay(200);
run = false;
}
}
and then after extracting some info some serial statments are made which just work till:
$$set Jp (and not ip whereas it should be ip)address 192.168.0.155