Using with Python
Installing from PyPI
Install the latest stable version from PyPI:
Make sure to have the latest pip
pip install --upgrade pipthen
pip install TheengsDecoderInstalling a development version
Building this module requires scikit-build and cmake. If not already installed you will need to open a terminal and execute:
pip install scikit-build
sudo apt-get install cmakeMake sure to have the latest pip
pip install --upgrade pipThen clone the repository and install the latest development version:
git clone --recursive https://github.com/theengs/decoder.git
cd decoder/python
cp -r ../src .
pip install .Using
Import the TheengsDecoder in your Python modules as:
import TheengsDecoderThe library includes a BLE decoder example. To run the example, open the folder ScanAndDecode in a terminal and type 'python ScanAndDecode.py`
If Theengs Decoder recognized a device, it will print a message like the example below, otherwise None.
TheengsDecoder found device: {"brand":"Xiaomi","model":"LYWSD03MMC","model_id":"LYWSD03MMC_ATC","tempc":26.3,"tempf":79.34,"hum":49,"batt":29,"volt":2.487}Additionally the example will print the properties of the device as well as the brand and model using the getProperties and getAttributes methods. The output of these looks like:
{"properties":{"volt":{"unit":"V","name":"voltage"},"x_axis":{"unit":"int","name":"x_axis"},"y_axis":{"unit":"int","name":"y_axis"},"z_axis":{"unit":"int","name":"z_axis"},"tempc":{"unit":"°C","name":"temperature"},"hum":{"unit":"%","name":"humidity"}}}
brand: Mokosmart , model: BeaconX ProThese functions are useful for passing the data to HomeAssistant or other home automation/monitoring services.
Methods
decodeBLE(string)Returns a string with the decoded data in JSON format or None.getProperties('model_id string')Returns the properties (string) of the given model ID or NonegetAttribute('model_id string', 'attribute string')Return the value (string) of named attribute of the model ID or None.