Skip to content

girolamo-giordano/PurAir_SCIOT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PurAir: Serverless Computing For IoT Project

Introduction

The idea is to simulate an environment which an IoT sensor tracks the air quality of a given room, and send an allert to the user when the value of air's quality is low. The user can decide to start the air purifier to improve the air quality, and then keep track the status of air purifier. The tools used are: Nuclio, RabbitMQ, Docker, Node.js, Telegram.

Nuclio

Nuclio is an high-performance "serverless" framework focused on data, I/O, and compute intensive workloads. It is used to deploy functions that are triggered by data sent to an MQTT topic, these data are processed and then used to perform certain actions, such as sending them to a specific MQTT queue.

RabbitMQ

RabbitMQ is a messaging broker - an intermediary for messaging. It is used to receive data generated by MQTT clients or Nuclio functions which will then be consumed by other clients.

Telegram

Telegram is a messaging app that has 400 million active users, allows you to create and publish your own bot. Within this project, the bot is used as a client to manage and perform some actions on the air purifier based on the data received.

Node.js

Node.js (Node) is an open-source development platform for executing JavaScript code server-side. In this project it is used to create the telegram bot and clients where the data published in the MQTT queues will be displayed.

Docker

Docker is an open platform for developing, shipping, and running applications allowin to separate your applications from your infrastructure. Docker is used to run Nuclio and RabbitMQ.


The libraries used in the project are:

  • Telegraf: Telegraf is used for the creation of the bot and its commands.
  • Amqplib: amqplib allows you to connect, send and consume messages from MQTT queues.
  • dotenv: dotenv is a zero-dependency module that loads environment variables from a .env file

Architecture

To simulate the sensor data of the air purifier, we can use two tools:

  • Use an MQTT client from your smartphone.
  • Use the function sendrandomair present in the yaml_functions folder

The value sent by one of the two previous choices is an integer and indicate the percentage of air quality. This value is published to the RabbitMQ topic "iot/sensors/air".

At this point a Nuclio function is triggered: consumeair.

This function process and check its value. If the value is < 50 it sent the value to the RabbitMQ queue "iot/sensors/alarm" and also to the RabbitMQ queue "iot/sensors/log". If the value is >= 50 the value is sent only to RabbitMQ queue "iot/sensors/log".

At this point in the Telegram bot the message in the "iot/sensors/alarm" is intercepted and the message is sent to the user. The user can choose to start purificator air, and if it's do this, a message that represent the status of the purificator air will go to the RabbitMQ queue "iot/sensors/purair". From this queue is possible to get the message that inform the status of purificator air.

Architecture

Installation

  • First of all we need to run RabbitMQ and Nuclio:

    • Open two terminals, to run RabbitMQ using docker type:

      docker run -p 9000:15672  -p 1883:1883 -p 5672:5672  cyrilix/rabbitmq-mqtt
    • On the second terminal, to run Nuclio using docker type:

      docker run -p 8070:8070 -v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp nuclio/dashboard:stable-amd64
  • Update and deploy functions:

    • Browse to Nuclio Dashboard to open the homepage of Nuclio.
    • Create new project and call it PURAIR.
    • Press 'Create function', 'Import' and upload the two functions that are in the yaml_functions folder.
    • In both, change the already present IP with your IP; also in the tab regarding the trigger.
       connect("amqp://guest:guest@INSERT_YOUR_IP:5672")
    • Press 'Deploy'.
  • Create personal Telegram Bot:

    • Open Telegram and search for BotFather.
    • Press start and type /newbot.
    • Follow the instructions gived by BotFather and give it a name and an unique id.
    • Copy and paste the Token that BotFather gave you in the BOT_TOKEN in env file;
  • Install all dependencies, start Telegram bot's server, AirStatus client and Logger:

    • Open .env file and insert your IP address instead of 'INSERT_YOUR_IP' in the field IP.
    • Install requirements:
     npm install
    • Open three terminals, to run the bot.js using Node.js type:
      node bot.js
    • on the second, to run the client that tracks the status of the air purifier type:
      node status_air.js
    • on the last one, to run the logger client type:
     node logger.js
  • Now we can use the Telegram client:

    • Open Telegram
    • Run bot using /start

After all this steps, you can use the sendrandomair function on Nuclio or MQTT client from your smartphone. If the value is < 50, you will be notified on the bot and asked to make a decision.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages