- Install AWS nodes in Node-RED
- Register the IOT2000 as a Thing in the AWS IoT Core
- Place certificates on the IOT2000
- Make an inbound (MQTT Subscribe) flow
- Make an outbound (MQTT Publish) flow
The starting position for this blog is that you have a Simatic IOT20XX connected to a network, with access to internet and a functioning Node-RED running.
Take care that it's running. If not, run:
node /usr/lib/node_modules/node-red/red &
Check the system date of the IOT20x0 and correct if needed. If it's wong, the installation can fail for invalid certificates.
date --set "20 June 2019 19:08:00"
First step is to add the AWS MQTT nodes:
Open the Node-RED editor in your browser: http://<ip>:1880
When successful, you can see this in the console where you started Node-RED:
Three new nodes appear in your palette:
This ends step 1: Getting the AWS nodes.
2. Register IOT2000 as a Thing in AWS IoT CoreThe starting position is that you have an AWS subscription. The Free Tier one will do.
Navigate to the IoT Core service, then Manage -> Things - > Create
Create a single thing.
I've named my Thing IOT2020 and created a new Thing Type IOT2020 (optional)
Then single-step created new certificates (we will not use them :).
The only one you need to download at this point is amazon's root certificate: https://www.amazontrust.com/repository/AmazonRootCA1.pem
Click activate
Click Done
Go to your Thing again by clicking Manage -> Things- > IOT2020
Click Interact
Copy the https endpoint URL. You'll need that later in your Node-RED flow.
Click on Connect a Device -> Get Started
Select Linux and Node.js -> Next
click Download connection kit for Linux/OSX
click Next Step
Now leave this page active. We'll test the connection from the IOT2020 in the next step, and the result will be shown here.
3. Place Certificates on the IOT2000The download that we just made contains our certificates.
On the IOT2020, under your home folder make this directory structure:
cd ~mkdir .agentcd .agentmkdir certscd certs
Now transfer the downloaded zip from your pc to that new directory certs.
I use winSCP for that.
Then execute the commands listed on the AWS webpage you left open from the previous step:
unzip connect_device_package.zip
If you get an error (the zip version on the IOT may not support the format), unzip all on your pc and move them to the certs folder separately.
chmod +x start.sh./start.sh
This installs the kit. The process takes a while and you'll get something like this:
At the end of the install (it took a long time on my box, approx. 30 minutes, but there's an animated progress bar to show you're still alive), a message appears that says Connecting.
If you keep the AWS webpage open in the background as I did above, you'll see a first message arriving from AWS to your IOT. Success #1 !!
If you type something in the "Send a Mesage" box and press Send, you'll see the message arriving at your IOT2020:
Once done, click ctrl-c to stop the exchange.
4. Make an Inbound (MQTT Subscribe) FlowAll is ready to test from Node-RED now. Open the Node-RED editor in your browser and create a new flow, namd AWS in
From the input pallet, get the aws-mqtt node, and from the output palette a debug block. Connect them.
Double-click on the aws-mqtt node and enter topic_1 as topic. Then Add new aws-iot-device.
Name: AWS
Type: mqtt broker
client (MUST BE IDENTICAL to the name you gave the Thing in AWS IoT core !!!): IOT2020
endpoint: what you copied ins tep 2. If you've lost it, go back to Manage -> Things -> IOT2020 -> Interact and copy the Rest API endpoint
Add, then Done.
Don't deploy yet. The policy that was created when generating the test kit does not allow access from a client named IOT2020. Let's change:
Go to Secure-> Policies -> Iot2020-Policy and Edit Policy Document.
Add a fourth line to this part (the XXXXX:XXXXXXXX is specific to you):
"Resource": ["arn:aws:iot:XXXXX:XXXXXXXX:client/sdk-java","arn:aws:iot:XXXXX:XXXXXXXX:client/basicPubSub","arn:aws:iot:XXXXX:XXXXXXXX:client/sdk-nodejs-*"]
It should look like(note the comma added to line 3!)
"Resource": ["arn:aws:iot:XXXXX:XXXXXXXX:client/sdk-java","arn:aws:iot:XXXXX:XXXXXXXX:client/basicPubSub","arn:aws:iot:XXXXX:XXXXXXXX:client/sdk-nodejs-*","arn:aws:iot:XXXXX:XXXXXXXX:client/IOT2020*"]
Set as default and save
Now go to your Node-RED flow and deploy it.
At the right top side, click on the debug button, so that we can see the payload once AWS IoT has sent us something.
Go to the IoT Core page, select Test
Go to the Publish part of the page, enter topic_1 and click Publish to topic.
Navigate back to your Node-RED page and you'll see the that the message arrived. Success #2
5. Make an Outbound (MQTT Publish) FlowCreate a new flow called AWS out.
From the input pallet, take an inject node, from the output pallet an aws-mqtt node. Connect them.
Double click on the inject node, set payload to JSON and enter: { "name": "Hello, world!" }
Leave the rest as is, don't enter a topic.
Double-click on the aws-mqtt node. Select the device AWS that we created in the previous step (we reuse it. It contains the correct settings).
The topic: topic_2
Again, don't deploy yet, we have to set up the test page to show the result.
Go to the IoT Core page, and select Test again.
On the Subscribe section, enter topic topic_2
Click on Subscribe to topic. Ignore the Publish part that appears in the test screen.
Go to the Node-RED flow and deploy it.
Click on the small button left of the inject node. This will push the JSON message we just created to AWS.
You get a success popup, and the label Done appears under the aws-mqtt node.
In the AWS test page, the message shows. It arrived! Success #3
That's it. I hope this helps you to get started with AWS integration on the Siemens Simatic IOT2020 (or 2040). Do you know a simpler method? Please comment.
Comments