Closed nickyandre closed 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.
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.
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.
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.