AVNET's iotconnect.io cloud platform is an online service that you can use to send data to, and then show it on a dashboard. In this blog series I'm learning the Python SDK and integrating BLE devices. In this post: the SDK plug-in functionality to add the RSL10 sensor kit as a Bluetooth Low Energy node. Like the previous blog, the technique in this post can be used on other devices supported by the SDK. When you use it outside the context of the Avnet portal, you can learn BLE integration from it too. |
SDK Support for Plug-in modules
In the IoTConnect SDK, a plugin is a subdirectory with a specific naming pattern IoTPlugin*.
The SDK looks for subdirectories with that name, and tries to __import__() them.
As a natural effect, Python will execute a file called __init__.py if it is in that directory.
So it's partly custom code to find the plugins, then using standard Python constructs to let those register themselves in the SDK.
Additionally, this part of the example also searches for any file in the folder or subfolder called IoTConnectSDK.conf. If files exist, their config is imported before starting to import modules.
if (int(my_config_parser_dict["CloudSystemControl"]["systemconfigured"]) == 0): # Setup factory defaults configs = cmdline("find . -name IoTConnectSDK.conf") myprint(configs) configs = configs.splitlines() for item in configs: config = configparser.ConfigParser() item = item[2:len(item)] myprint(item) if (item.find(str("Plugin").encode(encoding='UTF-8')) != -1): config.read(mystr(item,'utf-8')) print("Importing PluginCfg " + mystr(item,'utf-8')) my_config_parser_plugin_dict = {s:dict(config.items(s)) for s in config.sections()} my_config_parser_dict.update(my_config_parser_plugin_dict) plugins = cmdline("find . -name 'IoTPlugin*'") plugins = plugins.splitlines() for item in plugins: item = item[2:len(item)] print("Importing Plugin " + mystr(item,'utf-8')) m = __import__(mystr(item, 'utf-8')) m.__init__(m,globals()) globals().update(m.__dict__)
At this point, submodules and configuration is known, and submodules had a chance to initialise themselves.
I've executed a few commands from the prompt to show what kind of info the Python script is getting from the OS:
The remainder of the code will check via REST calls if the template for the RSL10 application exists in iotcloud.io.
When all checks are ok, the device is enrolled.
The IoTPluginRssi that comes with the example is the only part of the code that speaks BLE.
As far as the SDK is concerned, the module can generate valid objects.
It's up to the module now to implement the physical interaction with the RSLE10.
I will review that in the next post.
If you wonder what the ON Semiconductor RSL10 kit is, check out these 2 recent road tests: RSL10 Sensor Development Kit and ON Semi RSL10-SENSE-DB-GEVK Sensor Board.
Here you can see it in action in an end-to-end sensor to cloud application, with the SmartEdge gateway collecting and uploading the sensor data.
For a detailed review of the cloud dashboard, check part 5: A Cloud User Experience Example.