Skip to content

alitaqizadeh/IOT-with-RaspberryPi-Node-Red

Repository files navigation

Simple IOT project with Raspberry Pi and Nod-Red

Introduction

Raspberry Pi

The Raspberry Pi is a credit-card-sized computer that plugs into your TV and a keyboard. It is a capable little computer which can be used in electronics projects, and for many of the things that your desktop PC does, like spreadsheets, word processing, browsing the internet, and playing games. It also plays high-definition video.

Nod-Red

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.The light-weight runtime is built on Node.js, taking full advantage of its event-driven, non-blocking model. This makes it ideal to run at the edge of the network on low-cost hardware such as the Raspberry Pi as well as in the cloud.

What do we want?

We want to get latest price of famous CryptoCurrencies and send it via email to users.

Project steps

  • We installed Raspberry Pi board and configured network before.

  • From June 2018 Node-RED can be installed from the Pi Menu - Preferences - Recommended Software application installed on the Raspbian SD card image that can be downloaded from RaspberryPi.org otherwise We should connect to Raspberry pi with ssh and install Nod-Red on it so we can use this command:
bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)
  • After the installation for using email module we should install it too. Go to ~/.nod-red and run the following command:
npm i node-red-node-email
  • Now we can run node-red with the following command:
node-red

  • As you see at the image on top Nod-Red served on port 1880 so we can access Nod-Red from anywhere with the following address:
http://<Raspberry Pi IP adress>:1880

  • We can now start our project. first of all we need to add a start point so add "Inject" node to our project and set the attribute "Payload" to true and for continuous job set attribute "Repeat" to interval.

  • After that we want to get the informations of CryptoCurrencies. I used CoinMarketCap API. You should add "Http Request" node to your flow and set the address of the service you want to get informations.

  • We should convert http request to json format to get informations that we want so we added "JSON" node to our flow.

  • We need a function to extract data that we want from the previous node. we added "Function" node and write some codes as bellow(we set cryptos attribute for the main variable msg):

var item;
var newMsg = {};
for (item in msg.payload.data) {
    newMsg[msg.payload.data[item].name] = msg.payload.data[item].quotes.USD.price+' $';
}
msg.cryptos = newMsg;
return msg;

  • In this step we have msg.cryptos but the default main variable in this system is msg with payload attribute(msg.payload) that we can call it later so we should add "Change" node to change the variable msg.payload to msg.cryptos.

  • After we prepared our data we should email it so we added "email" node to our flow and set our email username and password and the target email.

  • Now we can check our email and see the results.

  • We can beautify the json result in any beautifier web site. I choosed Code Beautify.

Conclusion

We made a system with Raspberry Pi and Node-RED which get json package data from an API and extract it for our use and send it via email service rapidly and easily.

You can check other fantastic projects in hasker.io website.

Also you can contact me with this email: alitaqizadeh@gmail.com

❤️

About

Simple IOT project with Raspberry Pi and Nod-Red

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published