I have organized the code a little better
Oh yes it is a huge improvement !
Put yield whenever I find its necessary
i would change you loop() like this :
void loop() {
// ESP.wdtFeed(); // there is no need for this, we just had a yield() at the end of loop
//and that resets the wdt as well
wifi_connecting(); //handle if lost connection
yield();
wifi_newClient(); //check if there is any new client
yield();
wifi_anyClient(); //check if there is any client at all
yield();
blink_led(); //handle the debug LED issues
yield();
readTelnet(); //read messages from Telnet Clients and handle them
yield();
wifi_uart_telnet(); //check UART for data and send to all telnet clients
yield();
wifi_resend(); //resend stored data to all clients who doesn't answer (but still connected)
// yield(); // at the end of loop() there is no need for yield() it is automatic.
}
The ESP.wdtDisable() method is to use hardware WDT instead software WDT as I've found here
you may as well just use the software wdt, the timeout for it is about 2.5s,
I think the name of this is handoff, can ESP8266 handle it?
i think it can, though i haven't experiment with it. Once the siganl gets to weak for connection (below -90) it would need to connect to another node, i suspect you would need to explicitly tell it to do so using wifi.begin(), which does cause a temporary 'drop-out' in the connection. i actually have no such network in place around here (i live on 45sqM)
At the network side, others devices like cellphones or tablets is handling it very well
Oh yes, well, but is not automatic, they have code making sure that happens, they automatically connect to any known network, if the network that is the strongest known network has a different name, they'll connect to that one. You might want to set the boundary for weak network a little higher (-85) as to anticipate a change over. Keep in kind that while scanning you are also disconnected.
All in all, what issues do you have now ?
There are a few pointers that sprung in to mind while going through your code.
void blink_led() {
bool already_blinking = false;
if (flag_hasClient)
i suspect this function is supposed to be non-blocking led blink, in that case already_blinking should be
static bool already_blinking = false;
the same would go for a few other global variables that could be static locals, but this one changes functionality.
String read_serial, data[MAX_SRV_CLIENTS], data_ant[MAX_SRV_CLIENTS];
Although on an ESP you do not have to worry about memory nearly as much as on an AVR, and the String class is definitely doing a much better job of managing the memory used, it is still a good idea to do some managing yourself if you want to use a global String, that you modify locally. (check out the .reserve() function from the String class ) What is said about memory fragmentation is true, it can cause your program to fail unexpectedly even if it has been running just fine for a really long time already (months maybe even, though in the current setup i don't think it ever really would)
if (EEPROM.read(EEPROM_SAVE_POSITION) != EEPROM_SAVE_1) {
DEBUG = DEBUG_DEFAULT;
if (DEBUG) EEPROM.write(DEBUG_SAVE_POSITION, 1);
else EEPROM.write(DEBUG_SAVE_POSITION, 0);
EEPROM.write(EEPROM_SAVE_POSITION, EEPROM_SAVE_1);
EEPROM.commit();
}
else if (EEPROM.read(DEBUG_SAVE_POSITION) == 1) {
DEBUG = true;
Serial.println();
Serial.println("Debug mode on");
}
else DEBUG = false;
though this is a neat solution, keep in mind the flash is guaranteed for only about a thousand writes, and that is not an awful lot, though i guess you would not turn the debug on & off all the time.
and uhmm, who taught you this ?
data[i] = "";
}
readSerial:
while (Serial.available()) {
c = Serial.read();
if (c != '\n' && c != '\r')
for (int i = 0; i < MAX_SRV_CLIENTS; i++)
if (flag_client[i])
data[i].concat(c);
yield();
}
for (int i = 0; i < MAX_SRV_CLIENTS; i++) {
if (flag_client[i])
if (data[i] == "P")
goto readSerial;
if (rssi[i])
hasMsg[i] = false;
There must be a more elegant way of achieving the same loop rather than using 'goto'
Personally i would make 'readSerial' a bool function, and where it has 'goto' put
yield();
return false;
and then make a line that does
while (!readSerial());
or something like that.