Compression and Uncompression Logic Format

In IoT Controller GZIP based compression is used and below is the sample code written in Python. This can be extended to any programming language of partner or cloud application.

Compression Logic Format (Performed on IoT Controller)

from io import BytesIO

import gzip

import json

#Beacon Payload (Dummy Value)

payload={"key":"value"}

compressed_body = BytesIO()

gz = gzip.GzipFile(fileobj=compressed_body, mode="wb")

gz.write(json.dumps(payload).encode("utf-8"))

gz.close()

#to_send is transmitted to cloud (partner application)

to_send = compressed_body.getvalue()

Uncompress Logic Format (To be implemented on partner application)

from io import BytesIO

import gzip

import json

#received by partner/cloud application

received_value = BytesIO(to_send)

to_receive = gzip.GzipFile(fileobj=received_value, mode='rb').read()

payload_rx = json.loads(to_receive.decode("utf-8"))

Sample Execution Format

$ python3

Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21)

[Clang 6.0 (clang-600.0.57)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

from io import BytesIO

import gzip

import json

#Beacon Payload (Dummy Value)

payload={"key":"value"}

compressed_body = BytesIO()

gz = gzip.GzipFile(fileobj=compressed_body, mode="wb")

gz.write(json.dumps(payload).encode("utf-8"))

16

gz.close()

#to_send is transmitted to cloud (partner application)

to_send = compressed_body.getvalue()

to_send

b'\x1f\x8b\x08\x00\xbdM\x94`\x02\xff\xabV\xcaN\xadT\xb2RP*K\xcc)MU\xaa\x05\x00\x1bH53\x10\x00\x00\x00'

#received by partner/cloud application

received_value = BytesIO(to_send)

to_receive = gzip.GzipFile(fileobj=received_value, mode='rb').read()

payload_rx = json.loads(to_receive.decode("utf-8"))