diff --git a/Config.h b/Config.h
index fd31301..6f9b9a4 100644
--- a/Config.h
+++ b/Config.h
@@ -2,8 +2,8 @@
#define Config_h
const int WIFI_PORT = 99; // OR set to zero for no wifi
-const char WIFI_SSID[] = "BTHub5-M6PT"; // your network SSID (name)
-const char WIFI_PASS[] = "49de8d4862"; // your network password
+const char WIFI_SSID[] PROGMEM = "BTHub5-M6PT"; // your network SSID (name)
+const char WIFI_PASS[] PROGMEM = "49de8d4862"; // your network password
const long WIFI_BAUD_RATE=115200;
const long SERIAL_BAUD_RATE=115200;
diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp
index 241da63..f456b5f 100644
--- a/DCCEXParser.cpp
+++ b/DCCEXParser.cpp
@@ -9,7 +9,7 @@
#include "EEStore.h"
#include "DIAG.h"
-const char VERSION[]="99.666";
+const char VERSION[] PROGMEM ="99.666";
int DCCEXParser::stashP[MAX_PARAMS];
bool DCCEXParser::stashBusy;
@@ -178,7 +178,7 @@ void DCCEXParser::parse(Print & stream, const char *com) {
case 's': //
StringFormatter::send(stream,F("
"),DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON );
- StringFormatter::send(stream,F(""), BOARD_NAME, VERSION, __DATE__, __TIME__ );
+ StringFormatter::send(stream,F(""), BOARD_NAME, VERSION, __DATE__, __TIME__ );
// TODO Send stats of speed reminders table
// TODO send status of turnouts etc etc
return;
diff --git a/DCCEXParser.h b/DCCEXParser.h
index 5d0bd1c..23c1b47 100644
--- a/DCCEXParser.h
+++ b/DCCEXParser.h
@@ -31,5 +31,5 @@ struct DCCEXParser
};
-#define BOARD_NAME "not yet configured"
+#define BOARD_NAME F("not yet configured")
#endif
diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp
index 6d5e398..f50b285 100644
--- a/DCCWaveform.cpp
+++ b/DCCWaveform.cpp
@@ -87,7 +87,7 @@ void DCCWaveform::checkPowerOverload() {
if (lastCurrent < POWER_SAMPLE_MAX) delay = POWER_SAMPLE_ON_WAIT;
else {
setPowerMode(POWERMODE::OVERLOAD);
- DIAG(F("\n*** %s TRACK POWER OVERLOAD current=%d max=%d ***\n"), isMainTrack ? "MAIN" : "PROG", lastCurrent, POWER_SAMPLE_MAX);
+ DIAG(F("\n*** %S TRACK POWER OVERLOAD current=%d max=%d ***\n"), isMainTrack ? F("MAIN") : F("PROG"), lastCurrent, POWER_SAMPLE_MAX);
delay = POWER_SAMPLE_OVERLOAD_WAIT;
}
break;
diff --git a/Sensors.cpp b/Sensors.cpp
index 01b86d2..b406ea0 100644
--- a/Sensors.cpp
+++ b/Sensors.cpp
@@ -139,7 +139,7 @@ void Sensor::show(Print & stream){
void Sensor::status(Print & stream){
for(Sensor * tt=firstSensor;tt!=NULL;tt=tt->nextSensor){
- StringFormatter::send(stream,F("<%s %d>"), tt->active?"Q":"q", tt->data.snum);
+ StringFormatter::send(stream,F("<%c %d>"), tt->active?'Q':'q', tt->data.snum);
}
}
diff --git a/StringFormatter.cpp b/StringFormatter.cpp
index 5c1a2d3..5c64027 100644
--- a/StringFormatter.cpp
+++ b/StringFormatter.cpp
@@ -29,6 +29,7 @@ void StringFormatter::send(Print & stream,const __FlashStringHelper* format, va_
case '%': stream.print('%'); break;
case 'c': stream.print((char) va_arg(args, int)); break;
case 's': stream.print(va_arg(args, char*)); break;
+ case 'S': stream.print((const __FlashStringHelper*)va_arg(args, char*)); break;
case 'd': stream.print(va_arg(args, int), DEC); break;
case 'b': stream.print(va_arg(args, int), BIN); break;
case 'o': stream.print(va_arg(args, int), OCT); break;
diff --git a/WifiInterface.cpp b/WifiInterface.cpp
index a1204ae..c5195ba 100644
--- a/WifiInterface.cpp
+++ b/WifiInterface.cpp
@@ -4,8 +4,10 @@
#include "StringFormatter.h"
-const char READY_SEARCH[]="\r\nready\r\n";
-const char OK_SEARCH[]="\r\nOK\r\n";
+const char PROGMEM READY_SEARCH[] ="\r\nready\r\n";
+const char PROGMEM OK_SEARCH[] ="\r\nOK\r\n";
+const char PROGMEM END_DETAIL_SEARCH[] ="@ 1000";
+const char PROGMEM PROMPT_SEARCH[] =">";
bool WifiInterface::connected=false;
DCCEXParser WifiInterface::parser;
@@ -19,7 +21,7 @@ void WifiInterface::setup() {
DIAG(F("\n++++++ Wifi Setup In Progress ++++++++\n"));
connected=setup2();
// TODO calloc the buffer and streamer and parser etc
- DIAG(F("\n++++++ Wifi Setup %s ++++++++\n"), connected?"OK":"FAILED");
+ DIAG(F("\n++++++ Wifi Setup %S ++++++++\n"), connected?F("OK"):F("FAILED"));
}
bool WifiInterface::setup2()
@@ -29,38 +31,39 @@ bool WifiInterface::setup2()
delay(1000);
StringFormatter::send(Serial1,F("AT+RST\r\n")); // reset module
- if (!checkForOK(10000,READY_SEARCH)) return false;
+ checkForOK(5000,END_DETAIL_SEARCH,true); // Show startup but ignore unreadable upto ready
+ if (!checkForOK(5000,READY_SEARCH,false)) return false;
StringFormatter::send(Serial1,F("AT+CWMODE=1\r\n")); // configure as access point
- if (!checkForOK(10000,OK_SEARCH)) return false;
+ if (!checkForOK(10000,OK_SEARCH,true)) return false;
- StringFormatter::send(Serial1,F("AT+CWJAP=\"%s\",\"%s\"\r\n"),WIFI_SSID,WIFI_PASS);
- if (!checkForOK(20000,OK_SEARCH)) return false;
+ StringFormatter::send(Serial1,F("AT+CWJAP=\"%S\",\"%S\"\r\n"),WIFI_SSID,WIFI_PASS);
+ if (!checkForOK(20000,OK_SEARCH,true)) return false;
StringFormatter::send(Serial1,F("AT+CIFSR\r\n")); // get ip address //192.168.4.1
- if (!checkForOK(10000,OK_SEARCH)) return false;
+ if (!checkForOK(10000,OK_SEARCH,true)) return false;
StringFormatter::send(Serial1,F("AT+CIPMUX=1\r\n")); // configure for multiple connections
- if (!checkForOK(10000,OK_SEARCH)) return false;
+ if (!checkForOK(10000,OK_SEARCH,true)) return false;
StringFormatter::send(Serial1,F("AT+CIPSERVER=1,%d\r\n"),WIFI_PORT); // turn on server on port 80
- if (!checkForOK(10000,OK_SEARCH)) return false;
+ if (!checkForOK(10000,OK_SEARCH,true)) return false;
return true;
}
-bool WifiInterface::checkForOK( const int timeout,char * search) {
+bool WifiInterface::checkForOK( const int timeout, const char * waitfor, bool echo) {
long int time = millis()+timeout;
- byte locator=0;
- DIAG(F("\nWifi setup Check:"),search);
+ char *locator=waitfor;
+ DIAG(F("\nWifi setup Check: %S\n"),waitfor);
while( time > millis()) {
while(Serial1.available()) {
int ch=Serial1.read();
- Serial.write(ch);
- if (ch!=search[locator]) locator=0;
- if (ch==search[locator]){
+ if (echo) Serial.write(ch);
+ if (ch!=pgm_read_byte_near(locator)) locator=waitfor;
+ if (ch==pgm_read_byte_near(locator)) {
locator++;
- if (!search[locator]) {
+ if (!pgm_read_byte_near(locator)) {
DIAG(F("\nOK after %dms\n"),millis()-time+timeout);
return true;
}
@@ -127,7 +130,7 @@ void WifiInterface::loop() {
if (streamer.available()) { // there is a reply to send
StringFormatter::send(Serial1,F("AT+CIPSEND=%d,%d\r\n"),connectionId,streamer.available());
streamer.write('\0');
- if (checkForOK(1000,">")) Serial1.print((char *) buffer);
+ if (checkForOK(1000,PROMPT_SEARCH,true)) Serial1.print((char *) buffer);
}
loopstate=0; // go back to looking for +IPD
}
diff --git a/WifiInterface.h b/WifiInterface.h
index 3a8205f..f3cc383 100644
--- a/WifiInterface.h
+++ b/WifiInterface.h
@@ -3,6 +3,8 @@
#define WifiInterface_h
#include "DCCEXParser.h"
#include "MemStream.h"
+#include
+#include
class WifiInterface {
@@ -13,7 +15,7 @@ class WifiInterface {
private:
static DCCEXParser parser;
static bool setup2();
- static bool checkForOK(const int timeout, char * search);
+ static bool checkForOK( const int timeout, const char* waitfor, bool echo);
static bool connected;
static byte loopstate;
static int datalength;