AttA plays well with Node-RED
Today I explain how to test your AttA simulation scripts with Node-RED.
Node-RED introduction
Node-RED is a project from IBM http://nodered.org/. This is a tool that allows to visually define connections, triggers, ⊠between things.
I wanted to check if AttA was compliant with Node-RED. But, first of all, we have to install Node-RED (you need NodeJS and npm):
sudo npm install -g node-red
Then, you have to install CoAP support thanks to the project node-red-contrib-coap:
cd ~/.node-red
npm install node-red-contrib-coap
Before running Node-RED, we are going to create an AttA script simulation.
AttA simulation
I want to simulate 2 MQTT Gateway and 1 CoAP Gateway:
You can find the source here: https://github.com/ant-colony/atta/blob/master/sandbox/iot_demo/iot.groovy
MQTT Broker
You need a MQTT Broker:
You can find the source here: https://github.com/ant-colony/atta/blob/master/sandbox/iot_demo/mqtt-broker.js
- start the broker (the complete sample https://github.com/ant-colony/atta/blob/master/sandbox/iot_demo/), run
npm install
, then./broker.sh
- start the simulation script:
./iot.sh
(you need Atta Project, and you have to build the project jar)
Define connections with Node-RED
First, we have to run Node-RED:
node-red
And now, open your browser http://127.0.0.1:1880/
Define our MQTT connection
- 1: Dragân drop a mqtt input from the left column to the workspace
- 2: Double-Click on the mqtt node to setup the broker and to subscribe to a a topic
Remember, the gateway publishes data on this topic: home/g1/sensors
- 3: Dragân drop an output (debug) node from the left column to the workspace
- 4: Link the input node and the output node
- 5: Double-Click on the output node to setup the properties (notice the property
to
is set withdebug tab
)
- 6: Now, click on the Deploy button (at the top right corner), and then select the debug tab (in the right column)
- 7: You can do the same thing for the other MQTT gateway (donât forget to deploy to see data of the new gateway):
# Add a log file
I want to store data in a log file:
- 1: Dragân drop a storage file node from the left column to the workspace
- 2: Double-Click on the file node to setup the properties
- 3: Link the file node to the 2 mqtt nodes, and deploy
Now you have a my.iot.log
file with all the data
Define our CoAP connection
- 1: To query a CoAP resource, dragân drop a function âcoap requestâ node from the left column to the workspace
- 2: Double-Click on the coap request node to setup the properties
Remember, the path resource of the CoAP is work
and the CoAP port is 5686
- 3: You have to define a trigger to run the request: dragân drop a input âinjectâ node to the workspace
- 4: Double-Click on the trigger node to setup the properties
- 5: Link the trigger node to the CoAP request node
- 6: Create an output (debug) node, link it to the CoAP request node and push the deploy button. Now you can see the CoAP data too:
Thatâs all. Node-RED is a very interesting project, an now Iâm sure that it plays well with Atta (a good test tool for me).
Stay tuned to the next episode. I think, I will play with Aedes and AttA.
Have a nice day!
Tweet