Not a programmer, trying to be a musician.....
A few years ago I wrote a program to control my MIDI BOSS ME-5 footpedal. For those who do not know what that is: It is an effect apparatus that shapes the signal of a musical instrument (in my case a guitar). The settings of various parameters is controllable by MIDI.
The program is written as a web server and runs on any Linux machine. I used extensive javascripting, PHP, JQuery, Ajax and CSS scripts. It works just fine on a raspberry zero W.
Yesterday I decided to port it to the ESP8266. It can handle a webserver so why not?
After some research how to approach this I wrote a setup with ESPAsyncWebServer and the SoftwareSerial libs. MIDI is similar to RS232, albeit with an odd baudrate 31250. The hardware UART can then be used for debugging purposes.
Whenever the website is started, the (javascript) client will import the current settings of the ME-5. It holds 2240 bytes. So the snippet of the code checks whether there's data available and reads it from the softserial port until it reaches 2240 bytes. This is in nature not a save protocol, when something goes wrong or even when the ME-5 is not connected this results in an endless loop:
sendMIDI(SYSREQ, paramsNr); // send the curse to ME-5 to get the settings.
responsestring[0] = 0;
buf[0] = 0;
i=0;
while (i < 2240) { // not save, endless loop. Add timeout somewhere...
if (MIDI_OUT_Serial.available()) {
SYSDT[i] = MIDI_OUT_Serial.read();
// Serial.print(i);
// Serial.print(" ");
// Serial.print(SYSDT[i], HEX);
// Serial.print(" ");
sprintf(buf, "%02X", SYSDT[i]);
Serial.print(buf);
Serial.print(" ");
strcat(responsestring, buf);
i++;
if (!(i%35)) Serial.println();
}
}
As you can see I commented out a few Serial.print statements as the soft WDT would trigger if these are uncommented. I did not research this in detail, maybe the softserial did overflow at some point, maybe hte ESP8266 is thinking that it just takes too long.
When I disconnect the ME-5 (turn it off actually) the Soft WDT will trigger pretty fast, I think less then a second after the query is send to return the data.
This is too short a time to implement a timeout routine. What I want is a 'catch routine' to catch all contingencies, e.g 'disconnected', 'did not receive 2240 bytes within a given time'.. 'received only 2230 bytes'... and soforth. And without triggering the (Soft) WDT. At that point I loose all control and cannot debug other possibilities.
Maybe reset the WDT at certain intervals?
I read somewhere that the ESPAsyncWebServer lib is critical with yield and delay statements.
Pls comment.....