I am working on a sensor project where I need to process the results that have been read into a serial buffer. I am looking for the line that contains a +IPD at the beginning and then want to process the remainder of the string as key value pairs. This is what I have so far.
if(wait_for_esp_response(3000, "Unlink")){
dbg.print("Contents of buffer inside of getSensorConfig is: ");
dbg.println(buffer);
dbg.println("End of buffer dump................");
if(strncmp(buffer, "+IPD,", 5)==0) {
// return format: +IPD,ch,len:sensor config data
dbg.println("We have +IPD!");
sscanf(buffer+5, "%d,%d", &ch_id, &packet_len);
if (packet_len > 0) {
pb = buffer+5;
while(*pb!='\r\n') pb++;
pb++;
dbg.print("Printing contents of pb.....");
dbg.println(pb);
}
}
I know that I have a buffer full of of string data as I can println dump the contents of buffer and get the following:
Contents of buffer inside of getSensorConfig is:
AT+CIPSEND=1,74
GET /methods/getsensorconfig?keyId=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SEND OK
+IPD,1,136:current.enabled=true,led.enabled=true,led.frequency=300,temp.enabled=false,temp.frequency=60,time.frequency=86400,time.now=1422035449201
OK
OK
Unlink
End of buffer dump................
I thought I could simply strncmp to locate the line beginning with +IPD and and read character by character into pb until \r\n is found.
The problem is that I never seem to be getting into the if block.
Any suggestions on how to do this?
Thanks,
Stephen