This project was made to present a complete LoRa solution.
This is the second part of a complete workshop that includes:
1 - Setting Up Laird Sentrius RG1xx LoRa Gateway
2 - Environmental Sensing Using LoRa and STM32
3 - Connecting STM32 LoRa Discovery Kit to AWS IoT
To start this project we suppose that you already did all the other steps of the workshop and it's already receiving the sensors data in The Things Network.
We will use Node-Red to integrate the sensors data from The Things Network to AWS IoT. So, we will need to create an EC2 Instance, install Node-Red, create a thing in AWS IoT and finally configure the Node-Red to receive data from TTN and forward to AWS IoT.
1) Creating and configuring EC2 InstanceAccess AWS Console (create an account if you don't have it).
In the home page, select All Services > Compute > EC2
Click in the button Lauch Instance to create a instance.
Select Ubuntu Server 16.04 LTS at Step 1:
Select the instance type t2.micro at Step 2 and click in "Next: Configure Instance Details"
On the Configure Security Group tab (Step 6), click Add Rule, select Type Custom TCP Rule
, Port Range 1880
and Source Anywhere
. Click Review and Launch to proceed.
Review the information and click Launch button. A new window will ask you to configure a key pair. Select Create a new key pair, name it and click Download key pair.
Save the .pem file in a safe place. Finally, click Lauch instances to start the EC2 service.
After some minutes instancing the service, the console will show you the Lauch Status. Click View Instances, get the Public DNS (IPv4) and follow the next steps.
If you are not using an Windows machine, follow the steps in AWS Guide and go to Step 3.
Download and install PuTTY. Start the PuTTYgen (Start menu > All Programs > PuTTY > PuTTYgen), click Load and select the .pem file generated by AWS
Select RSA as the type of key and click Save private key.
Now, start PuTTY (Start menu > All Programs > PuTTY > PuTTY).
Get the Public Instance
In Category > Session > Host Name, enter ubuntu@public_dns_name
, Port 22
and Connection Type SSH
In Category > Connection > SSH > Auth, browse for your private key (.ppk) file:
Get back to Category > Session, in Saved Session give a name and click Save to save the configuration
Finally, click Open to start the session
Now, you need to install node.js and Node-RED:
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs build-essential
sudo npm install -g node-red
Configure Node-RED to start automatically if your instance is restarted:
sudo npm install -g pm2
pm2 start `which node-red` -- -v
pm2 save
pm2 startup
Access Node-RED using your browser:
http://<your-instance-ip-or-dns>:1880/
Go to AWS Console and select AWS IoT.
On the left panel, select Manage Things and click on Create button on the right.
Give a name to the thing and click Create Thing
Click on the created thing, select Security and Create Certificate.
Download the 3 certificates and click Activate:
In the same page, right-click on the Download link of the root CA and select "Save as...". Save the file using the name rootCA.pem in the same folder of the certificates.
Click Done.
Get back to AWS IoT. On the left panel select Secure > Policies. Click on the Create button on the right.
Give a name to the policy. On Action enter iot:*
, Resource ARN *
, check the box Allow on Effect and click Create.
Go to Secure > Certificates again and select the created certificate.
Click on Actions > Attach policy
Select the created policy and click Attach.
Click on Actions > Activate
On the left panel, select Test. The AWS IoT will show the MQTT client, on the right side, click on Connected as iotconsole... > View endpoint
Get the Endpoint adress to configure Node-RED on the Step 6.
Install and execute WinSCP. Create a New Site, select protocol SFTP, enter Host name public_dns_name
, Port 22
, User ubuntu
and click Advanced...
On Environment > Shell > Shell, select sudo su -
On SSH > Authentication > Private key file, select the private key (.ppk) file. Click Ok.
Click Save and Login.
On the left screen, browse to the AWS IoT certificates.
On the right screen, Right-click > New > Directory... Create a directory using the name certs
.
Select on the left screen the certificate, private key and rootCA. Drag and drop to right screen inside the certs folder.
Access your NodeRED instance using your browser:
http://<your-instance-ip-or-dns>:1880/
Click on menu button on the right top and select manage palette.
On Install tab, search for ttn
. Install the node-red-contrib-ttn.
Drag and drop the nodes ttn message and inject to the flow.
Double-click ttn node to edit the properties. Enter a name to the node, click on the edit button to Add new ttn app using your The Things Network application configuration:
Enter the Device ID from TTN, leave the Field blank. Click Done.
On left panel, at "output" drag and drop a debug and mqtt node. Connect the nodes as below:
Double click mqtt node. Click on the edit button to Add new mqtt-broker.
Enable secure (SSL/TLS) connection and click on the TLS Configuration edit button to Add new tls-config.
Enable Use key and certificates from local files and enter the location and name of respective files uploaded through WinSCP on Step 5. Click Update.
Enter on Server the AWS IoT Endpoint
, Port 8883
, Client ID AWS Thing ID
. Click Update.
Enter a Topic lora_device_01
, QoS 0
, and name it the node. Click Done.
Finnaly, click Deploy to finish and start the Node-RED application.
Access AWS IoT > Test. On the Subsctription topic, enter lora_device_01
, click Subscribe to topic.
The MQTT Client shows all the messages received in AWS IoT. You can click on timestamp button in Node-RED to send some data to test or you can wait for data from The Things Network.
Congratulations! You finished the this LoRa Workshop.
Subscribe and be up to date for new applications and integrations!
Comments