Changes between Initial Version and Version 1 of iot/avnetiotconnect


Ignore:
Timestamp:
05/11/2020 03:58:38 PM (4 years ago)
Author:
Ryan Erbstoesser
Comment:

start page from private wiki

Legend:

Unmodified
Added
Removed
Modified
  • iot/avnetiotconnect

    v1 v1  
     1[[PageOutline]]
     2= Avnet !IoTConnect Cloud Solution with Gateworks SBC
     3
     4The 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.
     5
     6Avnet, 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 [https://www.gateworks.com/products/ 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.
     7
     8Gateworks 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.
     9
     10Gateworks is a manufacture of single board computers and Avnet provides the cloud and optional software services.
     11
     12Avnet IoTConnect site: [https://www.iotconnect.io/]
     13
     14[[Image(iotconnect.jpg,700px)]]
     15
     16== Requirements
     17 * Avnet IoTConnect Trial or Full Account (contact Gateworks support)
     18 * [https://www.gateworks.com/products/ Gateworks Single Board Computer] (Ventana GW5220 was used for demo)
     19  * Ubuntu Bionic Operating System (although other OS's could work, they have not been tested)
     20  * Software packages in software requirements below
     21 
     22
     23=== Software Requirements
     24 * Python packages on the Gateworks SBC
     25  *
     26{{{
     27#!bash
     28apt-get update
     29apt-get install python2.7 python3.7 python-paho-mqtt python3-paho-mqtt python-pip python3-pip
     30}}}
     31 * Avnet Python IoT SDK
     32  * Download using wget or transfer to the Gateworks SBC
     33   * [https://help.iotconnect.io/documentation/sdk-reference/device-sdks-flavors/download-python-sdk/ Python SDK with Symantec and X.509 Auth Support]
     34   * Note NodeJS SDK is also available
     35  * Unzip archive (may require apt-get install unzip utility)
     36  * Install archive on Gateworks SBC
     37   *
     38{{{
     39#!bash
     40cd iotconnect-sdk/
     41pip install iotconnect-sdk-2.0.tar.gz
     42}}}
     43
     44
     45== Getting Started
     46 * Access the Avnet  IoT Dashboard here:
     47  * [https://avnet.iotconnect.io/dashboard]
     48 * Setup a template and device on the Avnet Platform with instructions here:
     49  * deviceID used for demo is gateworks1
     50  * [https://help.iotconnect.io/knowledgebase/on-boarding-raspberry-pi/]
     51 * Edit the demo python script (iotconnect/sample/gateworks.py)
     52  * Three pieces of required data to be modified in the demo code using something like the 'vi' editor:
     53   * CPID is the company ID, a special key found on the Avnet IoT Dashboard under Settings -> Company Profile
     54   * DeviceID (Unique ID) is the device id. gateworks1 was used for the demo.
     55   * Environment should be set as AVNETPOC
     56 * Run the Python script from the Gateworks SBC command line:
     57  *
     58{{{
     59
     60root@bionic-ventana:~iotconnect-sdk/sample# python gateworks.py
     61Protocol Initialized...
     6241.3
     63[{'data': {'Temperature': '41.3', 'Humidity': '42'}, 'uniqueId': 'gateworks1', 'time': '2020-05-08T22:31:42.000Z'}]
     64
     65Publish data sucessfully... 2020-05-08 22:31:42.000
     66}}}
     67 * Verify the data in the Devices area on the Avnet IoT Connect cloud site:
     68  * Device telemetry showing actual board temperature and simulated humidity:
     69[[Image(device-telemetry.png,900px)]]
     70  * Device graph showing temperature and simulated humidity
     71[[Image(devicegraph.png,900px)]]
     72  * Devices listing:
     73[[Image(devices-Capture.PNG,900px)]]
     74
     75== Further IoT Reading
     76 * [https://www.gateworks.com/iot-gateway/ Gateworks Flexible IoT Gateway Primer]
     77 * [https://www.gateworks.com/smart-asset-monitoring-iot/ Gateworks Smart Asset Monitoring IoT Primer]
     78 * [http://trac.gateworks.com/wiki/iot/azurelorademo Gateworks IoT Gateway with Lora and Azure]
     79 * [http://trac.gateworks.com/wiki/iot Gateworks IoT Wiki Page]
     80
     81== Source Demo Code Reference
     82{{{
     83#!python
     84# Compatible with python 2.* version
     85import sys
     86import os.path
     87from iotconnect import IoTConnectSDK
     88import json
     89import time
     90import random
     91from datetime import datetime
     92
     93def callbackMessage(msg):
     94    if msg:
     95        print("\n--- Command Message Received ---")
     96        print(str(msg['ack']))
     97        print(str(msg['ackId']))
     98        print(str(msg['command']))
     99        print(str(msg['uniqueId']))
     100
     101def callbackTwinMessage(msg):
     102    if msg:
     103        print("\n--- Twin Message Received ---")
     104        print(json.dumps(msg))
     105
     106def main(argv):
     107 while True:
     108    try:
     109        env = "AVNETPOC"
     110
     111        uniqueId = "gateworks1"
     112        cpId = "MkFTRDcxXTItMfZBNy00NzdFLfk2QfAtMzU4NjVGNDdGNDk3sWFjY2Vzc0tFWSfjMzNsc3MwNsFm"
     113
     114        with IoTConnectSDK(cpId, uniqueId, callbackMessage, callbackTwinMessage, env) as sdk:
     115            try:
     116                dataArray = []
     117
     118                aObj = {}
     119                temp = float(open('/sys/class/hwmon/hwmon0/temp1_input', 'r').read().strip())/1000
     120                print(temp)
     121                aObj["Temperature"] = str(temp)
     122                aObj["Humidity"] = str(random.randint(40,50))
     123
     124
     125                dObj = {
     126                       "uniqueId": "gateworks1",
     127                       "time": datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.000Z"),
     128                       "data" : aObj
     129                        }
     130                dataArray.append(dObj)
     131                print(dataArray)
     132                if len(dataArray) > 0:
     133                        sdk.SendData(dataArray)
     134            except Exception as ex:
     135                print(ex.message)
     136                sys.exit(0)
     137    except Exception as ex:
     138        print(ex.message)
     139        sys.exit(0)
     140    time.sleep(10)
     141
     142
     143if __name__ == "__main__":
     144    main(sys.argv)
     145
     146}}}