Use Dragino device with Amazon AWS-IOT

From Wiki for Dragino Project
Jump to: navigation, search

Introduction

AWS IoT is a platform that enables you to connect devices to AWS Services and other devices, secure data and interactions, process and act upon device data, and enable applications to interact with devices even when they are offline.

In the AWS-IoT page, there are lots of instructions. in this page. we will show the fastest way to test connection between Dragino Devices LG01(with firmware version > 4.1.1) and AWS-IoT platform.

AWS-IOT.png



Set up AWS-IoT account

Create AWS-IOT account The AWS-IOT provide 1 year free use. User can create the AWS-IoT account and enter Aws -IoT page as below the setting page in:

AWS-IoT Dash Board


Configure a device

Go to tab and configure a device


Select Platform

Select the platform


Register a Thing

Register a Thing


Download Certificate

Download Certificate for this thing


Setup finish

Set up finish



Upload Certificate files to LG01

Before connection, we need to put the required certificate in LG01.

Download root-CA.crt

unzip the connect_device_package.zip and open the file start.sh. copy the command start with curl. run this command in LG01 linux console and download the root-CA.crt

root@dragino-16aa24:~# curl https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-xxxxxxxx-Public-Primary-Certification-Authority-G5.pem > root-CA.crt
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1758  100  1758    0     0     99      0  0:00:17  0:00:17 --:--:--   446
root@dragino-16aa24:~#


Transfer certificate files to LG01

the connect_device_package.zip include other certificate files such as: Dragino-Test-Device.cert.pem, Dragino-Test-Device.private.key, Dragino-Test-Device.public.key. transfer them into LG01 /root directory.

after above, the /root directory will include below files:

  • root-CA.crt
  • Dragino-Test-Device.cert.pem (will be different name for different things)
  • Dragino-Test-Device.private.key (will be different name for different things)
  • Dragino-Test-Device.public.key (will be different name for different things)



Data Communication via MQTT in Linux Console

We can use different methods to connect AWS IoT , below shows how to use them in the Linux Side. after Linux side test is ok. User can in the LG01 Arduino side to call the Linux command for purpose.

Use ASW-IoT Python MQTT SDK

1. Download aws-iot-device-sdk-python
2. Unzip it and transfer to LG01
3. Set up python SDK

root@dragino-16aa24:~/aws-iot-device-sdk-python-master# python setup.py install
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/AWSIoTPythonSDK
copying AWSIoTPythonSDK/__init__.py -> build/lib/AWSIoTPythonSDK
copying AWSIoTPythonSDK/MQTTLib.py -> build/lib/AWSIoTPythonSDK
creating build/lib/AWSIoTPythonSDK/core
copying AWSIoTPythonSDK/core/__init__.py -> build/lib/AWSIoTPythonSDK/core
creating build/lib/AWSIoTPythonSDK/exception
copying AWSIoTPythonSDK/exception/operationTimeoutException.py -> build/lib/AWSIoTPythonSDK/exception
copying AWSIoTPythonSDK/exception/operationError.py -> build/lib/AWSIoTPythonSDK/exception
copying AWSIoTPythonSDK/exception/__init__.py -> build/lib/AWSIoTPythonSDK/exception
copying AWSIoTPythonSDK/exception/AWSIoTExceptions.py -> build/lib/AWSIoTPythonSDK/exception
creating build/lib/AWSIoTPythonSDK/core/shadow
copying AWSIoTPythonSDK/core/shadow/deviceShadow.py -> build/lib/AWSIoTPythonSDK/core/shadow
copying AWSIoTPythonSDK/core/shadow/shadowManager.py -> build/lib/AWSIoTPythonSDK/core/shadow
copying AWSIoTPythonSDK/core/shadow/__init__.py -> build/lib/AWSIoTPythonSDK/core/shadow
creating build/lib/AWSIoTPythonSDK/core/util
copying AWSIoTPythonSDK/core/util/progressiveBackoffCore.py -> build/lib/AWSIoTPythonSDK/core/util
copying AWSIoTPythonSDK/core/util/__init__.py -> build/lib/AWSIoTPythonSDK/core/util
copying AWSIoTPythonSDK/core/util/offlinePublishQueue.py -> build/lib/AWSIoTPythonSDK/core/util
copying AWSIoTPythonSDK/core/util/sigV4Core.py -> build/lib/AWSIoTPythonSDK/core/util
creating build/lib/AWSIoTPythonSDK/core/protocol
copying AWSIoTPythonSDK/core/protocol/__init__.py -> build/lib/AWSIoTPythonSDK/core/protocol
copying AWSIoTPythonSDK/core/protocol/mqttCore.py -> build/lib/AWSIoTPythonSDK/core/protocol
creating build/lib/AWSIoTPythonSDK/core/protocol/paho
copying AWSIoTPythonSDK/core/protocol/paho/__init__.py -> build/lib/AWSIoTPythonSDK/core/protocol/paho
copying AWSIoTPythonSDK/core/protocol/paho/client.py -> build/lib/AWSIoTPythonSDK/core/protocol/paho
creating build/lib/AWSIoTPythonSDK/core/protocol/paho/securedWebsocket
copying AWSIoTPythonSDK/core/protocol/paho/securedWebsocket/securedWebsocketCore.py -> build/lib/AWSIoTPythonSDK/core/protocol/paho/securedWebsocket
copying AWSIoTPythonSDK/core/protocol/paho/securedWebsocket/__init__.py -> build/lib/AWSIoTPythonSDK/core/protocol/paho/securedWebsocket
warning: build_py: byte-compiling is disabled, skipping.
 
running install_lib
creating /usr/lib/python2.7/site-packages/AWSIoTPythonSDK
creating /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core
creating /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/util
copying build/lib/AWSIoTPythonSDK/core/util/progressiveBackoffCore.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/util
copying build/lib/AWSIoTPythonSDK/core/util/__init__.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/util
copying build/lib/AWSIoTPythonSDK/core/util/offlinePublishQueue.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/util
copying build/lib/AWSIoTPythonSDK/core/util/sigV4Core.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/util
copying build/lib/AWSIoTPythonSDK/core/__init__.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core
creating /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/shadow
copying build/lib/AWSIoTPythonSDK/core/shadow/deviceShadow.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/shadow
copying build/lib/AWSIoTPythonSDK/core/shadow/shadowManager.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/shadow
copying build/lib/AWSIoTPythonSDK/core/shadow/__init__.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/shadow
creating /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol
creating /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol/paho
creating /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol/paho/securedWebsocket
copying build/lib/AWSIoTPythonSDK/core/protocol/paho/securedWebsocket/securedWebsocketCore.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol/paho/securedWebsocket
copying build/lib/AWSIoTPythonSDK/core/protocol/paho/securedWebsocket/__init__.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol/paho/securedWebsocket
copying build/lib/AWSIoTPythonSDK/core/protocol/paho/__init__.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol/paho
copying build/lib/AWSIoTPythonSDK/core/protocol/paho/client.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol/paho
copying build/lib/AWSIoTPythonSDK/core/protocol/__init__.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol
copying build/lib/AWSIoTPythonSDK/core/protocol/mqttCore.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol
copying build/lib/AWSIoTPythonSDK/__init__.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK
copying build/lib/AWSIoTPythonSDK/MQTTLib.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK
creating /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/exception
copying build/lib/AWSIoTPythonSDK/exception/operationTimeoutException.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/exception
copying build/lib/AWSIoTPythonSDK/exception/operationError.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/exception
copying build/lib/AWSIoTPythonSDK/exception/__init__.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/exception
copying build/lib/AWSIoTPythonSDK/exception/AWSIoTExceptions.py -> /usr/lib/python2.7/site-packages/AWSIoTPythonSDK/exception
warning: install_lib: byte-compiling is disabled, skipping.
 
running install_egg_info
Writing /usr/lib/python2.7/site-packages/AWSIoTPythonSDK-1.1.1-py2.7.egg-info
root@dragino-16aa24:~/aws-iot-device-sdk-python-master#


4. Run Python command

Open the start.sh file. there is a example command:

python aws-iot-device-sdk-python/samples/basicPubSub/basicPubSub.py -e an5tk94sdgjat.iot.us-west-2.amazonaws.com -r root-CA.crt -c Dragino-Test-Device.cert.pem -k Dragino-Test-evice.private.key

notice:

  • The directory maybe aws-iot-device-sdk-python-master, not aws-iot-device-sdk-python
  • Run this command in the same directory as /root., where the certificate files we place in previous step.


5. Check Python Output

Reference Pythong output shows the MQTT Pub and SUB command



Use mosquitto MQTT client

Since firmware 4.2.0, the mosquitto client is pre-installed. Use mosquitto mqtt client will be faster than using Python script.

below is the command to publish a message to a topic:

mosquitto_pub -h an5tk94sdgjat.iot.us-west-2.amazonaws.com -p 8883 -t mqtt/test -m 30.5 --cafile root-CA.crt  --cert Dragino-Test-Device.cert.pem  --key Dragino-Test-Device.private.key

and the command to subscribe to a topic:

mosquitto_sub -h an5tk94sdgjat.iot.us-west-2.amazonaws.com -p 8883 -t mqtt/test --cafile root-CA.crt  --cert Dragino-Test-Device.cert.pem  --key Dragino-Test-Device.private.key

above commands are run in the /root directory so has the same directory as the certificate files.

User can open two Linux console windows and check the result as below.

MQTT AWS Connection output

Result in AWS-IoT Server

Dashboard shows a successful connection from LG01
Dashboard shows message status