This file documents the steps to add Python3.11 support for MQTT payload of ProtoBuf type in Bevywise IoT Simulator and Bevywise MQTT broker.
Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data.
- Write .proto file according to the requirement (screen.proto is used as an example here).
- Compile the .proto file using protobuf compiler. $ protoc --python_out=. screen.proto The compiler generates a Python file.(screen_pb2.py) (Note:) Refer https://grpc.io/docs/protoc-installation/ to install the latest version of Protobuf compiler.
Bevywise MQTTRoute is a highly extendable & reliable MQTT Broker fuelling powerful data management to build large scale IoT applications / solutions. https://www.bevywise.com/mqtt-broker/
- Copy the compiled protoBuf Python class file (eg. screen_pb2.py) to Bevywise/MQTTRoute/extensions/
- Copy custom_store.py to Bevywise/MQTTRoute/extensions/
- In the the method "handle_Received_Payload()" in Bevywise/MQTTRoute/extensions/custom_store.py, replace the imported ProtoBuf class name with the one used. If required this method can be modified. (Note: If the sample screen_pb2.py is used, modifications to custom_store.py are not required.)
- Set CUSTOMSTORAGE = ENABLED in Bevywise/MQTTRoute/conf/data_store.conf
- Google protobuf needs to be installed in MQTTRoute/lib. This can be done by installing it via pip into the lib folder ($ pip install protobuf==4.21.12 -t MQTTRoute/lib)
- Run MQTTRoute In Linux based machines, $ cd Bevywise/MQTTRoute/bin $ sh runbroker.sh
Bevywise IoT Simulator is a simulation tool to simulate tens of thousands of MQTT clients in a single box. https://www.bevywise.com/iot-simulator/
- Copy the compiled protoBuf class file (eg. screen_pb2.py) to Bevywise/IoTSimulator/lib folder.
- Copy default_interceptor.py to Bevywise/IoTSimulator/extensions/
- In the the method "on_before_send()" in Bevywise/IoTSimulator/extensions/default_interceptor.py, replace the imported ProtoBuf class file with the one used. If required this method can be modified. (Note: If the sample screen_pb2.py is used, modifications to default_interceptor.py are not required.)
- Run IoTSimulator In Linux based machines, $ cd Bevywise/IoTSimulator/bin $ sh runsimulator.sh
- In Simulator UI, enable Interceptor and point to interceptor file, by choosing 'Enabled' on Settings(Gear Icon)->Advanced->Python Interceptor. If the default interceptor is not used, then the file path to the new file should be put in 'Python File' text box.
- In Simulator UI, choose/create a device, and an event that corresponds to the .proto file.
- Choose a device
- Click on '+' and choose an event (eg. Instant)
- Enter a topic name.
- Select JSON as Message Type. Enter keys and values corresponding to the .proto file used. For the sample screen_pb2.py, paste the following into the message text area {"luminance": "100-1000-RANGE", "color_depth": "65M-CONSTANT", "temperature": "1-100-RANGE", "ntsc": "45-60-RANGE", "contrast_ratio": "200:1-CONSTANT", "backlight_longevity": "20000-60000-RANGE", "touch_type": "capacitive-CONSTANT", "viewing_tech": "oled-CONSTANT"}
Deserialized data will be available in handle_Received_Payload() method in Bevywise/MQTTRoute/extensions/custom_store.py This method handle_Received_Payload() can be extended to store the deserialized data in any database of your choice.