NodeRED usage for MQTT client and server simulation

About

Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click.

Usage

To simulate Device and Server we can use Node red and publish and subscribe MQTT topics to send and receive messages.

https://cookbook.nodered.org/mqtt/connect-to-broker#problem

Installation

  1. Install Docker(Prerequisite)
  2. Install NodeRED using – https://nodered.org/docs/getting-started/docker
  3. Once installed you can then browse to http://{host-ip}:1880 to get the familiar Node-RED desktop.
  4. NODE-RED is now ready to be used.

Using with AWS 

  1. We can use X.509 certificate to connect to AWS IOT Core system
  2. Create a certificate, download Private Key, Public key, Certificate and store it at local file
  3. Download CA certificate for server authentication from 
    https://docs.aws.amazon.com/iot/latest/developerguide/server-authentication.html
    https://www.amazontrust.com/repository/AmazonRootCA1.pem
  4. Create a policy(Connect, publish and subscribe privileges should be with policy)
  5. Create a thing.
  6. Attach Policy to Certificate and Certificate to Thing.
  7. Now Open Node-Red http://{host-ip}:1880
  8. Start creating flow
  9. Select an mqtt out node and drag it to dashboard as shown.
  10. Double click on Node and start configuring.
  11. Select topic to publish, qos level, give a name to server and then select add-new-mqtt-broker and click on edit button as shown.
  12. Provide AWS server endpoint(You can get it from IOT core → settings), port = 8883, tick enable SSL/TLS connection, select “Use legacy mqtt support 3.1”, and Give name to this MQTT broker as shown
  13. Click on TLS configration and add new TLS configuration
  14. Name the TLS configuration, Add private key, Add public certificate and Amazon Root CA1 certificate.
    [Note- Due to some issue we are not able to validate server certificate so untick Verify server certificate]
  15. Save the configuration
  16. Once configuration is saved you can see Node connected to AWS as shown – 
  17. Now add Inject node and configure json data to be passed to AWS MQTT broker and connect it with Broker, Along with it add Debug node for debugging purpose and conncet Inject node to Debug as shown – 
  18. Now your MQTT client is ready to be used.
  19. Click on push button left to Inject Node to push data.

Leave a comment