Version 7 (modified by 5 years ago) ( diff ) | ,
---|
Avnet IoTConnect Cloud Solution with Gateworks SBC
The Internet of Things is revolutionizing the way the world works by having nearly any and every device connected to the internet for control and monitoring.
Avnet, a large US distributor of electronics has created an IoT Cloud Software Platform based on the Microsoft Azure framework. This allows for devices, such as a Gateworks Single Board Computer, to send data to the cloud for analysis, alerts, storage and more. Typical data comes from sensors, such as temperature, humidity, vibration, GPS location. These sensors can be connected over many different interfaces, such as I2C, SPI, RS485, RS232, ADC, and BLE. Gateworks offers many ways to connect to the cloud, including, but not limited to, Cellular, WiFi, Satellite Modem and Ethernet.
Gateworks has created a simple demo in which the onboard temperature sensor is probed and the data is sent using the Avnet IoT SDK in Python to the cloud over MQTT.
Gateworks is a manufacture of single board computers and Avnet provides the cloud and optional software services.
Avnet IoTConnect site: https://www.iotconnect.io/
Requirements
- Avnet IoTConnect Trial or Full Account (contact Gateworks support)
- Gateworks Single Board Computer (Ventana GW5220 was used for demo)
- Ubuntu Bionic Operating System (although other OS's could work, they have not been tested)
- Software packages in software requirements below
Software Requirements
- Python packages on the Gateworks SBC
-
apt-get update apt-get install python2.7 python3.7 python-paho-mqtt python3-paho-mqtt python-pip python3-pip
-
- Avnet Python IoT SDK
- Download using wget or transfer to the Gateworks SBC
- Python SDK with Symantec and X.509 Auth Support
- Note NodeJS SDK is also available
- Unzip archive (may require apt-get install unzip utility)
- Install archive on Gateworks SBC
-
cd iotconnect-sdk/ pip install iotconnect-sdk-2.0.tar.gz
-
- Download using wget or transfer to the Gateworks SBC
Getting Started
- Access the Avnet IoT Dashboard here:
- Setup a template and device on the Avnet Platform with instructions here:
- deviceID used for demo is gateworks1
- https://help.iotconnect.io/knowledgebase/on-boarding-raspberry-pi/
- Edit the demo python script (iotconnect/sample/gateworks.py) created by Gateworks to upload actual board temperature and simulated humidity every 60 seconds.
- Three pieces of required data to be modified in the demo code using something like the 'vi' editor:
- CPID is the company ID, a special key found on the Avnet IoT Dashboard under Settings -> Company Profile
- DeviceID (Unique ID) is the device id. Something like device1 was used for the demo.
- Environment should be set as what is provided by the Avnet support team
- Three pieces of required data to be modified in the demo code using something like the 'vi' editor:
- Run the Python script from the Gateworks SBC command line:
-
root@bionic-ventana:~iotconnect-sdk/sample# python gateworks.py Protocol Initialized... 41.3 [{'data': {'Temperature': '41.3', 'Humidity': '42'}, 'uniqueId': 'gateworks1', 'time': '2020-05-08T22:31:42.000Z'}] Publish data sucessfully... 2020-05-08 22:31:42.000
-
- Verify the data in the Devices area on the Avnet IoT Connect cloud site:
- Device telemetry showing actual board temperature and simulated humidity:
- Device graph showing temperature and simulated humidity
- Devices listing:
Next Steps
- Other sample scripts exist in the samples directory, including the example_py2.py
- Connect more data from other sensors connected to other bus's
- Explore on the IoTConnect platform to analyze, monitor and notify on the uploaded data
- Expand the demo to have the Gateworks SBC act as an IoT Gateway for many sensors
Further IoT Reading
- Gateworks Flexible IoT Gateway Primer
- Gateworks Smart Asset Monitoring IoT Primer
- Gateworks IoT Gateway with Lora and Azure
- Gateworks IoT Wiki Page
- Gateworks IoT Smart Factory Primer
Source Demo Code Reference
The below code is gateworks.py that was used in the demo above. Please note to change the cpId.
# Compatible with python 2.* version import sys import os.path from iotconnect import IoTConnectSDK import json import time import random from datetime import datetime def callbackMessage(msg): if msg: print("\n--- Command Message Received ---") print(str(msg['ack'])) print(str(msg['ackId'])) print(str(msg['command'])) print(str(msg['uniqueId'])) def callbackTwinMessage(msg): if msg: print("\n--- Twin Message Received ---") print(json.dumps(msg)) def main(argv): while True: try: env = "enter_evn_name_here" uniqueId = "enter_device_id_here_example_device1" cpId = "enter_company_id_here_from_avnet_portal" with IoTConnectSDK(cpId, uniqueId, callbackMessage, callbackTwinMessage, env) as sdk: try: dataArray = [] aObj = {} temp = float(open('/sys/class/hwmon/hwmon0/temp1_input', 'r').read().strip())/1000 print(temp) aObj["Temperature"] = str(temp) aObj["Humidity"] = str(random.randint(40,50)) dObj = { "uniqueId": "gateworks1", "time": datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.000Z"), "data" : aObj } dataArray.append(dObj) print(dataArray) if len(dataArray) > 0: sdk.SendData(dataArray) except Exception as ex: print(ex.message) sys.exit(0) except Exception as ex: print(ex.message) sys.exit(0) time.sleep(60) if __name__ == "__main__": main(sys.argv)
Attachments (6)
- iotconnect.jpg (222.0 KB ) - added by 5 years ago.
- devicegraph.png (93.8 KB ) - added by 5 years ago.
- devices-Capture.PNG (53.6 KB ) - added by 5 years ago.
- device-telemetry.png (99.0 KB ) - added by 5 years ago.
- gw5910small.png (318.2 KB ) - added by 5 years ago.
- avnetdiagram.jpg (232.3 KB ) - added by 5 years ago.
Download all attachments as: .zip