Float to bytearray conversion for sigfox payload



  • @tttadam I strongly recommend you convert the data to some integer representation (e.g. multiplying by 100 and truncating to an integer), depending on expected range and desired accuracy. It will make things much simpler for you, and if you pick the right integer size, will probably save you a few bytes, which for media like LoRa or Sigfox, can be essential.



  • @robert-hh Thanks for the tip. Both of them worked. The first is when I send it as a string (it's temperature data), the second when I send it as byte. But I am not sure how to decode the second one. If you have some tips, or link to other discussion that would be great.

    2018-11-03 21:42:35 32352e3539383034 ASCII: 25.59804
    2018-11-03 21:37:55 a404d241 ASCII: ...A

    My main goal is that send some cordinates also alongside sensor data, but I got the message size.
    Is there a way to compress my sentence?
    My sentence is like this:([47.45194, 'N'] [19.02091, 'E']);temp;25.68384



  • @tttadam There a quite a few options. Just to name two:

    • You can use struct.pack("f", float_number), which gives the shortest representation (4 bytes), or
    • you make a string out of it, with str(float_number).encode(), which returns a readable bytearray of varying length.

    Packing is one aspect, but you have to unpack it too. There was a post a few days ago dealing with that task.



Pycom on Twitter