flower-of-the-bridges / IoTAssignments

Project for the Internet of Things from the Engineering in Computer Science master course at Sapienza

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IoTWeatherStation

Description

This repository contains various material for the assignments made during Internet of Things course held at La Sapienza University of Rome.

First assignment

We need to develop a weather cloud platform, where:

  • A station (at least one) retrieves values (such as temperature, humidity...) from different sensors, and publish its state in a topic provided by an* MQTT Broker*, hosted by the Cloud Platform.
  • The MQTT broker triggers a procedure which stores the data in a record that will be inserted in a NoSql database.
  • A web application receives the data in order to show them to the final user.

This platform has been developed using the tools provided by the AWS Platform, such as IoTCore, DynamoDB and ElasticBeanstalk. here the main parts of the infrastructure , such as the client and the web application, are developed using the javascript programming language, upon the Node.js runtime. In particular:

  • the station is a CLI application, located in the environment_station that can be launched by using the following command. The values from the sensors are retrieved by calling the OpenWeather API and published through the topic provided in the configuration file. Then, we can launch many instances of it by typing
    node .\env_station.js *name of the city* *country code of the city* 
    
  • the web application, located in the server folder, must be filled with the .ebestension folder in order to be deployed on Elastic Beanstalk.

Instructions

After downloading the repository

git clone https://github.com/FlowerOfTheBridges/IoTWeatherStation

install the following dependencies using a packet manager of your choice (such as npm):

npm install axios

in order to call the weather API. Then

npm install aws-iot-device-sdk

in order to use the MQTTClient class, then

npm install aws-sdk

in order to retrieve data from DynamoDB. Last

npm install express
npm install body-parser

to run the server.

Last remarks

More insights on how to setup the AWS infrastructure can be found at the following article published on LinkedIn. Also, a demonstration of how the system works can be found in the video below.

Demonstration

Second Assignment

The weather station now must be deployed in a real microcontroller, so two new components were introduced:

  • riotos_app_mqttsn: is a RIOT-OS application were random values are published to a default topic of a MQTT-SN Broker (such as MOSQUITTO.RSMB) through a MQTT-SN connection. The command that needs to be prompted in the application shell to run the measurement process is
run <identifier> <ipv6 address of the broker> <port we're the broker is listening>
  • mqttsn_gateway: is a transparent gateway that translates the MQTT-SN messages of the RIOT-OS app in MQTT messages that will be send to AWS IoT Core platform. In particular it relies on the core package that was also used on the previous assignment. In particular, this package has the following updates:
    • MQTTClient constructor now needs to have two parameters: broker and config. While config remains the same as before, broker is a string that tells the type of broker we are going to use (it can be one of AWS or MOSQUITTO, were the latter must be local on port 1886). So in the main procedure main.js we need to create two connections by the usage of the following instructions:
    this.localClient = new MqttClient('MOSQUITTO', null);
    this.awsClient = new MqttClient('AWS', this.config);
    • VirtualStation class now has a new method, setSensorsFromRiot, that parses a message of the form
    <temp>|<hum>|<wind_dir>|<wind_int>|<rain>|<id>
    

Last remarks

A more hands-on tutorial on how to setup the RIOT application and the broker can be found on my LinkedIn profile.

Third Assignment

A RIOTOS application that send its data via LoRaWAN protocol can now be deployed by compiling the riotos_app_lorawn folder using the command:

  make -C iot_hw/riotos_app_lorawan clean all

In particular:

In particular a device must be registered with a device id of the form station_<city_name>, in order to be recognized correctly by the ttn_gateway.js script located inside the gateway folder. Its role is to retrieve data from TTN and then send it to AWS. So the following dependencies must be installed inside the gateway folder using a packet manager of your choice (such as NPM):

npm i ttn
npm i aws-iot-device-sdk

In order to make it work, two json files must be placed inside the gateway/resources folder, in a format similar to that of the sample files that can be found in the same folder.

Last remarks

A more hands-on tutorial on how to setup the RIOT-OS application and the gateway can be found on my LinkedIn profile.

Fourth Assignment

The folder crowdsensing contains a crowdsensing environment that detects if a user is moving or standing still. The system is made by:

  • an edge_based solution where the activity recognition model is computed by the user which will send the resulting activity status to the cloud. This solution is made by:
    • a mobile web application which reads data from the sensors, computes the model and sends the resulting status to the cloud through a WebSocket. In particular:
      • the browser running the page must support the Generic Sensor API and the Permissions API,
      • cookie must be enabled to give the possibility to the application to store the session identifier.
    • a dashboard where the user can see informations about the current session, such as the various samples that has been stored and the corresponding status
  • a cloud_based solution where the activity recognition model is computed by the cloud which will return the resulting activity status. This solution is made by:
    • a mobile web application which reads data from the accelerometer and sends its data to the cloud through a WebSocket. In particular:
      • the browser running the page must support the Generic Sensor API and the Permissions API,
      • cookie must be enabled to give the possibility to the application to store the session identifier.
    • a dashboard where the user can see informations about the current session, such as the various samples that has been stored and the corresponding status, along with the accelerometer information.

All those pages can be found on GitHub pages at the following links:

About the model

The activity recognition model computes the Signal Magnitude Area (SMA). If the SMA is below a given threshold of 1.5, it means that the user is standing still, otherwise is moving.

About the cloud

The cloud runs a serverless architecture by the usage of API Gateway and Lambda. The API Gateway runs a WS Endpoint with two routes:

  • store: saves the samples inside a DynamoDB table.
  • getsamples: retrieves all the samples from DynamoDB or only the ones within the last hour. The corresponding lambda functions can be found on the aws_lambda folder.

Last remarks

A more hands-on tutorial on how to setup the RIOT-OS application and the gateway can be found on my LinkedIn profile.

About

Project for the Internet of Things from the Engineering in Computer Science master course at Sapienza


Languages

Language:JavaScript 62.7%Language:HTML 21.5%Language:C 13.0%Language:Makefile 2.8%