wiki:iot/avnetiotconnect

Version 4 (modified by Ryan Erbstoesser, 4 weeks ago) (diff)

add next steps

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/

Gateworks GW5910 SBC:

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
    • 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
        

Getting Started

  • Access the Avnet IoT Dashboard here:
  • Setup a template and device on the Avnet Platform with instructions here:
  • 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. gateworks1 was used for the demo.
      • Environment should be set as AVNETPOC
  • 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

Source Demo Code Reference

# 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 = "AVNETPOC"

        uniqueId = "gateworks1"
        cpId = "MkFTRDcxXTItMfZBNy00NzdFLfk2QfAtMzU4NjVGNDdGNDk3sWFjY2Vzc0tFWSfjMzNsc3MwNsFm"

        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)

Download all attachments as: .zip