mayeranalytics / pySX127x

This is a python interface to the Semtech SX127x, HopeRF RFM9x, Microchip RN2483 long range, low power transceiver families.
GNU Affero General Public License v3.0
171 stars 116 forks source link

Converting the payload or data to Float #43

Closed nickyandre closed 1 year ago

nickyandre commented 1 year ago

Is that possible to convert the payload received in the Raspberry Pi to Float, Int, or String if yes how to do it? Could you please give me some idea how to do it. Thank you very much.

mayeranalytics commented 1 year ago

Ok that's a very broad question. The payload is binary, it can be anything you like, or whatever the sender specifies. In any case, you have to decode the payload, e.g. with Python struct. But there are all kinds of binary encodings. If you are free to decide the encoding, then msgpack is worth looking at. If you receive messages from some sensor then you need to read the specs of the sensor.

nickyandre commented 1 year ago

In this case i am sending accelerometer sensor data from microcontroller to Raspberry Pi. The Pi successfully received the data in the payload then decoded with utf8 and converted into variable named data according to the code. In this case we can encode the data using something else instead of utf8? like what you mention using struct?. The sensor is already processed by microcontroller in this case ESP32.

mayeranalytics commented 1 year ago

Utf8 would be very inefficient, unless you have pure text data. Have a look at msgpack, it supports many languages, you can use C to encode on the ESP32 and python on the Rasp to decode.