0

I have to decode a message received in this form b'\r\x01\x00\x00\x00' from a device. The only way to do this is to convert a Python function to Javascript, I've tried to do this but the unpacking operation doesn't work like in Python, obviously.

This is the python code:

def DecodeData(self, data):
    try:
        n = struct.unpack('b',bytes(data[0:1]))[0]
        print(n)
        id , type, m = self._DecodeId(n)
        value = struct.unpack(type, bytes(data[1:]))[0]/m
        return (id, value)
    except Exception as e:
        print(e)
        pass

I have to run the Javascript code in Datacake Payload-Decoder section and the result should be ('CIN_3', 1.0), or something like that.

Hope anyone can help me.

zhulien
  • 5,145
  • 3
  • 22
  • 36

0 Answers0