Hi Sara, I am working through the ESP32 course. I am at the server section where you (or Rui) say the following…
“Because the substrings we are looking for are always on index 6, we can add an if statement to detect the content of the request. “
I don’t understand this index 6 part. Would the index change if I were to use a different string, say ‘/?choice=timer’ as the request generated by the button? If the index would be different in that case, can you explain why and how I could work out what it would be. If it would be the same (6) please explain why.
Alternatively, perhaps you could point me to where there is an explanation. Thanks.
Aha… I think I get it….
The request string is “b’GET /?led=on” and the “b” is at index 0, therefore the searched string (/?led=on) starts at index 6, correct?
Hi Richard.
Yes. That’s correct.
Alternatively, instead of using that method, you can use the find() function instead to search for a specific string within another string.
That function will return a number if found or -1 if not found. So, you can also create an if statement based on that condition.
Here you can find more information about the find() method: https://www.geeksforgeeks.org/python-string-find/
I hope this helps.
Regards,
Sara