I am communicating with my GoPro via ESP8266 and GET requests.
One of the replies returns a set of predefined number and what I would like to do is extract the number on position "38". This is what the reply looks like in full:
SEND OK
+IPD,4,163:HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: 2016年4月24日 03:13:40 GMT
Server: Cherokee/1.2.101b150714_bd80061 (UNIX)
Content-type: application/json
OK
+IPD,4,972:3c0
{"status":{
"1":1,"2":1,"3":0,"4":0,"6":0,"8":0,"9":0,"10":0,"11":0,"13":0,"14":0,"15":0,"16":0,"17":1,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"26":0,"27":0,"28":18,"29":"","30":"xxx","31":0,"32":0,"33":0,"34":7933,"35":5039,"36":0,"37":4,"38":0,"39":4,"40":"%10%04%18%03%0D%28","41":0,"42":0,"43":1,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"54":29698976,"55":1,"56":4,"57":1022279,"58":0,"59":0,"60":500,"61":2,"62":0,"63":0,"64":0},
"settings":{"1":0,"2":9,"3":6,"4":1,"5":2,"6":1,"7":1,"8":0,"9":0,"10":0,"11":1,"12":1,"13":1,"14":0,"15":4,"16":0,"17":2,"18":2,"19":2,"20":0,"21":1,"22":2,"23":0,"24":2,"25":0,"26":4,"27":0,"28":2,"29":1,"30":10,"31":0,"32":0,"33":0,"34":1,"35":2,"36":1,"37":2,"38":0,"39":4,"40":0,"41":13,"42":8,"43":0,"44":8,"45":8,"46":0,"47":0,"48":0,"49":0,"50":1,"51":1,"52":0,"53":0,"54":0,"55":1,"56":1,"57":1,"58":1,"59":0,"60":8,"61":1,"62":700000,"63":4,"64":1,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":1}}
0
OK
As you can see, position 38=0 (...,"38":0,...). The number 0 will increment. So I would like to find the string "38":
and do something with following numbers until ,
.
What is the correct way to grab that number from the serial reply and echo or do something with it?
-
Are you using an Arduino to see the serial reply ? Or are you directly connected to the ESP8266 via USB?Aswin P J– Aswin P J2016年04月24日 03:20:45 +00:00Commented Apr 24, 2016 at 3:20
-
USB <-> Teensy <-> ESP ~~~~ GoProFid– Fid2016年04月24日 14:36:33 +00:00Commented Apr 24, 2016 at 14:36
1 Answer 1
Since you are being returned JSON, you can use the jsoncpp library found here To split your return to an array. Then you simply retrieve whatever item you want using array index notation.
Here is another helpful post on creating arrays of strings in C++ from JSON. C++ and JSON
-
I ended up using github.com/bblanchon/ArduinoJson and Serial.find();Fid– Fid2016年04月25日 19:57:42 +00:00Commented Apr 25, 2016 at 19:57