ICP_5 - akkipant/IoT-Fall-2019 GitHub Wiki
Introduction:
This lab was about using NODE-RED for IoT applications. This is a browser-based graphical coding tool where we require to wire different blocks called nodes for a specific application. Every code is called a flow. Any additional functionality required is to be written in a JavaScript code into the functions block. Built-in libraries can be used to save functions. We had to capture the weather data from OpenWeatherMap and send it in the form of mail and tweet.
Objectives:
Two objectives of this lab were:
- To get OpenWeatherMap data in Node-Red and extract meaningful data from it and send it as an E-mail.
- Also to send the data in the form of a Tweet.
Approaches/Methods:
Our approach was to first create a user account on OpenWeatherMap. Then, create a flow for getting data from it and sending it as an E-Mail. Secondly, send the data as a Tweet. Twitter required an application for a developer account as it was a lengthy process.
Workflow:
-
We first created a user account on OpenWeatherMap. Obtained the API key for it.
-
We installed Node-Red through command window. Type following commands:
npm
npm install -g --unsafe-perm node-red
node-red
In browser open http://localhost:1880
-
We created a node to get the weather data after installing the OpenWeather node. In Command window type:
npm install node-red-node-openweathermap
-
Then we added an E-Mail output node from the social section.
-
We changed the settings in g-mail to set a 2-way authentication from the "Google Account-->Security" and to set an app password. We configured the node with the Email address and the app password.
-
We then added a debug node and deployed the flow. We verified the output. We then added a 'functions' node to extract only the description from OpenWeatherMap and send it as an output. The function is written in JavaScript.
-
Last step was to send the output as a Tweet. We opened a Twitter account and also signed-up for the developer's account. The application process is tedious but finally, we obtain the API keys after creating an app on twitter.
-
We added a Tweet output node and provided the API and security API keys. Deployed the flow and verified the output on the debug window.
Flow Diagram:
Parameters:
- API Keys are required for the OpenWeathermap, Gmail, and Twitter.
- For extracting the description, use msg.payload = msg.payload.description.
Video:
Sending_Email_and_Tweet_through_Node-Red
Evaluation and Discussion:
- Initially the Node-Red was not accepting the API key of OpenWeathermap. There was some error while setting the city name and country. We tried to paste API key multiple times and changing the text format to all lowercase, all uppercase, etc. formats and finally succeeded with the all-lowercase format for city name.
- Setting up a Twitter developer account was also a time-consuming process.
Conclusion:
Through this lab, we learned the basics of Node-Red. We were introduced to the input, output and function nodes. We learned to configure the input/output nodes with API keys and passwords. Creating functions requires JavaScript and is a challenge for non-coders. Overall, Node-red is an interesting visual programming tool for IoT applications.