Become a leader in the IoT community!
Join our community of embedded and IoT practitioners to contribute experience, learn new skills and collaborate with other developers with complementary skillsets.
Join our community of embedded and IoT practitioners to contribute experience, learn new skills and collaborate with other developers with complementary skillsets.
Hi everyone,
I have a problem with the string function indexOf() that I don’t understand.
My board with the ESP32 module is connected via RS485 (on UART1) to another board. This second board can send me its data if I ask them sending a magic word. If this word is sent and received correctly, the board asks me the password sending me the word PASSWORD. The only other msg that I can receive from the second board is PASSWORD ERRATA.
So, as you can see in the picture below, I receive the msg, and I check if the msg contains the words PASSWORD and ERRATA. In the case shown in the picture, I received the msg PASSWORD, but the instruction “posizione1 = msg.indexOf(“PASSWORD”);” don’t recognize it (as you can see in the serial monitor, posizione1 has the value -1).
What am I doing wrong? I know that indexOf can check strings, the sintax seems to be correct, but it doesn’t work.
Any suggestion ?
Thanks, Stefano.
[edit]
in a new sketch I defined “String msg = “PASSWORD”; “, then asking for “posizione = msg.indexOf(“PASSWORD”);” I have the correct result. I continue to not understand. Both in the new sketch and in the original program, the variables are global.
CONTRIBUTE TO THIS THREAD