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: create a Gateway template, register a gateway device, dynamically register children.
image: a gateway device with two BLE children |
My previous post reviews what a gateway is, in a cloud context. Check it out if you're looking for a definition.
In this post, I review the internals of the example that Avnet and OnSemi made.
The photo at the top of this blog shows an Avnet IIoT gateway, with two OnSemi IoT devices.
The gateway is cloud savvy. The two clients are just BLE capable.
The example teaches the gateway how to exchange data of the OnSemi satellites to the cloud. It 'll even be able to send commands to one of the clients.
image source: the demo device's children listed on the iotconnect.io portal
Gateway Template
this is a revisit and extend of a topic handled earlier when I registered a simple device.
An iotconnect.io device can be connected if it complies with a known template.
A template is something you set up on the cloud. You can see it as an agreement or API. It defines what your remote device(s) can do.
image source: the different types of devices (and templates) on the iotconnect.io portal
iotconnect.io has a range of template types. The Device template (used in the 5 first posts) can manage things that have attributes and/or can handle commands directly. It's one self-contained object.
The Gateway template we're using here can do different things. It's goal is not to handle its own attributes*. The goal is to safely exchange data from the IoT devices surrounding it.
When you use a gateway template, your unit will be be able to exchange the template-defined data and commands from/with any object that it decides to support.
It's your duty to learn the gateway how to detect, accept and register trusted devices.
reminder: If a device is smart enough to connect to the cloud by itself, you typically don't use a gateway in-between.
The gateway is your tool to exchange data from devices that aren't cloud-capable, like BLE , sub-1 GHz, LoRaWan, ...
image source: create a gateway template on iotconnect.io portal
When creating a template, take care that at least one attribute is created, and that it's of type Int.
*An Edge Gateway template can do the combination: have its own attributes and manage child devices.
Register Gateway Device and Children
The example program that runs on the gateway validates the template name registered in the ~/IoTConnectSDKonboard.py Python script.
It checks if it can authenticate with the user info you provided in the config.
Then it checks if the template for our device exists
AUTH_BASEURL = my_config_parser_dict["CloudSystemControl"]["http_auth_token"]
TEMPLATE_BASEURL = my_config_parser_dict["CloudSystemControl"]["http_device_template"]
DEVICE_BASEURL= my_config_parser_dict["CloudSystemControl"]["http_device_create"]
username = my_config_parser_dict["CloudSystemControl"]["username"]
password = my_config_parser_dict["CloudSystemControl"]["password"]
solution_key = my_config_parser_dict["CloudSystemControl"]["solution-key"]
ACCESS_TOKEN = get_auth(username, password, solution_key)
if ACCESS_TOKEN == None:
myprint("authentication failed")
return 0
#---------------------------------------------------------------------
template_name = "zt" + str(serial_number)
available_name = str(my_config_parser_dict["CloudSystemControl"]["template_name"])
if (available_name != ""):
template_name = available_name
header = {
"Content-type": "application/json",
"Accept": "*/*",
"Authorization": ACCESS_TOKEN
}
#---------------------------------------------------------------------
# Get template attribute by searchText
myprint(template_name)
template = get_template(template_name)
if template != None:
myprint("Device template already exist...")
deviceTemplateGuid = template['guid']
return 1
If the template does not exist, the example will generate one in CloudConfigureDevice().
This will only work if the user you provide is allowed to create a template.
A typical application will have the template prepared and deployed before the first devices try to connect.
Once the application is running, it will check for registered client types (children).
Avnet has added a discovery function in the child library's _init_py script, named handleDiscovery().
As example, the OnSemi library contains discovery functions that can detect an OnSemi RLS10 sensor tag and an RSL10 Camera tag.
When one of these devices is in the neighbourhood, and the firmware is recognised, the dynamic registration of the device happens.
Shown here for the OnSemi RSL10 camera kit:
CameraType = (result['applicationversion'][:6] == "SS_COL") + 1
myprint("CameraType " + str(CameraType))
if CameraType == 1:
result1 = OnBoard.AddChildDevice("SmartShotBlackWhite", "smartshot", dev.addr.replace(':',''))
else:
result1 = OnBoard.AddChildDevice("SmartShotColor", "smartshot", dev.addr.replace(':',''))
if CameraType == 1:
data = {
'addr':dev.addr,
'guid':str(result1),
'type': CameraType,
'name': "SmartShotBlackWhite" + dev.addr.replace(':',''),
'bootloaderversion': result['bootloaderversion'],
'fotastackversion': result['fotastackversion'],
'applicationversion': result['applicationversion'],
'buildid': result['buildid'],
'supportsfota': result['supportsfota']
}
That's not the only thing that happens. A data exchange task is registered to tell the Gateway to deliver the child's data to the cloud at a defined interval.
If you want to validate this, check these files in the avnet user home directory:
IoTConnectSDKengine.py IoTConnectSDK.conf IoTConnectSDKonboard.py IoTPluginSmartSense\__init__.py IoTPluginSmartSense\IoTConnectSDK.conf
This post may be lean on the way the SDK runs, gets configured and how it uses the iotconnect.io REST api.
That's handled in other posts of this series.



