Search code examples
pythonhexiot

How to encode string to hex for sending downlink to iot devices?


According to this document

enter image description here

I need to send downlink of type 080100ff to open the supply of the socket.

However, I can not send 080100ff since I got this error The payload field is not a valid hexadecimal payload in upper case.

Here is my so far works in python

'080100ff'.encode('utf-8').hex() -> 3038303130306666

I can send it now, but I think it is incorrectly hex encoded because the device is not turned on


Solution

  • In your example you are converting a hexadecimal string (080100ff) into hexadecimal value. You already have the hexadecimal value, it is: 080100ff

    Would that work?

    bytes.fromhex('080100ff')