logo elektroda
logo elektroda
X
logo elektroda

How to extract data from the ESP8266 response: +IPD,5:Hello or +IPD,13:Hello, Again!

rafikAVR 1770 8
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 15551861
    rafikAVR
    Level 16  
    Hello
    after trying hard I have managed to get up and running and communicate with the ESP8266 .
    Sending a UDP packet to ESP , ESP spits out on the UART :
    +IPD,5:Hello
    or
    +IPD,13:Hello, Again!

    what is the best way to extract from the reply : Hello or Hello, Again! ?

    I put the answer from ESP into arrays ,
    but type checking :
    buffor[0] == "+" && buffor[1] == "I" .... up to "," then there can be 2 numbers and each in a different place in the array (how do I put buffor[5] = 1 and buffor[6] = 3 into number 13 in order to extract the data calmly afterwards ?)
  • ADVERTISEMENT
  • #2 15552116
    grko
    Level 33  
    Use functions from the standard library: sscanf .
  • ADVERTISEMENT
  • #3 15552150
    Anonymous
    Anonymous  
  • #4 15552585
    rafikAVR
    Level 16  
    GrzegorzKostka wrote:
    Use functions from the standard library: sscanf .


    ok
    but how to use sscanf with volatile uint8_t array ?
    (I receive the data in an interrupt)
  • #5 15552650
    Anonymous
    Anonymous  
  • ADVERTISEMENT
  • #6 15552967
    grko
    Level 33  
    @Piotrus_999
    Quote:

    Of course when using sscanf you must be sure!!! Of course when using sscanf you have to be sure that you have the whole message in the buffer and not, for example, half of it, and that you will scan the next half in the second scan - this is not possible....


    Obviously nonsense. The sscanf function returns a value. It is sufficient for the buffer to be null terminated. The algorithm is simple:
    - you collect characters in the buffer until you get an end-of-line character
    - add an '-' at the end
    - fire sscanf like this:

    Code: C / C++
    Log in, to see the code


    @Piotrus_999 You were supposed to write a parser for this sort of thing. Why don't you upload it here then we'll see how much better it is than sscanf.
  • ADVERTISEMENT
  • #7 15553077
    Anonymous
    Anonymous  
  • #8 15553155
    grko
    Level 33  
    Quote:

    what is nonsense? that it has to have the whole message to scan? and not e.g.; "+IPD,13:Hel" and in the second reading "lo, Again!"

    I don't know what you mean.



    The point is that your use case is from outer space. Data over the UART comes in sequentially, byte by byte, not in packets: "+IPD,13:Hel" , "lo, Again!" .
  • #9 15553170
    Anonymous
    Anonymous  
ADVERTISEMENT