Yes well that does covers the connections, but stil the type of unit you are using is unknown.
Still let's just focus on a single slave for now.
The ESP8266 has hwSerial and an additional TX [in that can be used for debugging depending on the specific board you plan to use there are some more options, but still i am confident that your issue is with the String class.
there is Serial Input Basics which is known to work reliably if implemented correctly.
If you think that is overkill, just a simple separator in your transmission will help a lot already.
digitalWrite (MAX_PIN, HIGH);
RS485.print("-001");
delay(50);
digitalWrite (MAX_PIN, LOW);
The delay(50); is actually rather a lot at 9600bps a byte takes a bit under 1ms to transmit
and at the receiving end.
String recv = "";
uint8_t rxChars = 3;
bool start = false;
while (Serial.available() && rxChars) {
char c = Serial.read();
if (start) {
recv += c;
rxChars--;
}
if (c == '-') start = true;
if (!Serial.available()) delay(1);
}
anyway something like that, you should at least test every character that comes in and see if it fits what you are expecting.
Well the main thing will be to get rid of any String variables that will not be destroyed on completion of the process. I know it's more tricky to handle, but memory fragmentation will in the end just crash the processor and when you reach that point, you will still have to do it..
Oh yeah, how far apart are you units ? and eh, if you are planning to use WiFi, why do you bother with the RS485 to begin with ? why not just read the sensor and post or make available on a local webserver ?