Created
July 24, 2019 07:02
-
-
Save futureshocked/af6e2c46761f68f80c35570d729a1859 to your computer and use it in GitHub Desktop.
Simple URL parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void setup() { | |
| Serial.begin(9600); | |
| while (!Serial) | |
| {} | |
| // put your setup code here, to run once: | |
| String str = "GET /?led06=1"; | |
| int led_index = str.indexOf("led"); | |
| int equal_index = str.indexOf("="); | |
| int led_pin = str.substring(led_index+3,equal_index).toInt(); // Find the substring that contains the pin number, | |
| // and convert it into an int | |
| // ** Single value pair parsing ** | |
| int led_val = str.substring(equal_index+1,str.indexOf("HTTP")).toInt(); // Find the substring that contains the value, | |
| // and convert it into an int | |
| //Show the substring indexes and values for debugging | |
| Serial.print("led_index, equal_index, led_pin, led_val: "); | |
| Serial.print(led_index); | |
| Serial.print(", "); | |
| Serial.print(equal_index); | |
| Serial.print(", "); | |
| Serial.print(led_pin); | |
| Serial.print(", "); | |
| Serial.print(led_val); | |
| } | |
| void loop() { | |
| // put your main code here, to run repeatedly: | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment