As I explained in yesterday’s article, I was unhappy about not connecting to Amazon AWS IoT cloud for my presentation at Electronica 2016. In the last post I showed you how to build an Amazon AWS IoT MQTT Client in the WICED WiFi SDK that can Publish to the Amazon Message Broker. Now I need to build a WICED App that can Subscribe to the ROBOT_POSITION topic and receive messages from the MQTT broker. This series of articles is broken up like this:
- Amazon IoT & MQTT (Part 1)
- Modify & Test the WICED Publisher App (Part 1)
- Modify & Test the WICED Subscriber App (Part 2)
- Modify the Application to talk I2C to the PSoCs (Part 3)
Modify the WICED Subscriber App
As with the previous article, start by copying the App from the apps–>demo–>aws_iot–>pub_sub–>subscriber into your directory. In my case that will be apps–>emb2017–>subscriber. Then update the application “Name:” and “VALID_PLATFORMS” in the Makefile. Remember that the App name must be unique.
Then modify the DCT to have your networking information. Don’t forget that the DCT is the device configuration table for WICED WiFi and is used to store the mostly static information (like network, passwords etc).
The next step is to make a few modifications to the actual firmware. Specifically,
- (line 60) Change the MQTT Broker IP address to the one assigned by Amazon
- (line 61) Change the TOPIC to “ROBOT_POSITION”
- (line 103) Print the message to the console
In the last article I copied the Transport Layer Security (TLS) keys from Amazon into the resources–>apps–>aws_iot directory. For this application I will use exactly the same keys. Then, create a new make target for the App and program the board.
Test the WICED WiFi Subscriber App
To test the application I will, once again, use the Amazon AWS IoT web MQTT Client to send messages to my board. In the screen shot below you can see the console window of the 943907AEVAL1F board. After programming it:
- starts up
- gets WICED and ThreadX going
- connects to my network (WW101WPA, gets a DHCP address: 198.51.100.16)
- Find the IP address of the MQTT broker (22.214.171.124)
- Opens an MQTT connection to Amazon.
When I publish the message “20304050” using the MQTT Client to the “ROBOT_POSITION” topic, you can see that it comes out on the console of the WICED WiFi development kit.
That proves that we have end-to-end communication. In the last article, I will fix up the Publisher and Subscriber application to read and write the I2C connection so that it can actually do the Robot ARM control.