UCL-IIOT - Data Loggings on Raspberry Pi

by Obayda_haj in Circuits > Arduino

324 Views, 3 Favorites, 0 Comments

UCL-IIOT - Data Loggings on Raspberry Pi

Dashboard.png

This instructable was created by Obayda Haj Hamoud and Sidse Henriksen for a school project.

The main idea is collecting data from alight sensor, logging the data to a database wirelessly on a raspberry pi and monitor that data through a dashboard created using Node red .

Building the Circuit

Circuit_bb.jpg

Requirements

Hardware:

● NodeMcu

● Raspberry pi

● Photocell light sensor

● Led

● Resistor

● Jumber cables

Software:

● Node Red

● Mosquitto server

● Mysql data base (phpmyadmin)

● Arduino IDE

Arduino Code

The following code is used to call the mosquitto broker installed on raspberry pi and get the published data.

'The final arduino file is inserted in the end of this instrutable'

void callback(String topic, byte* message, unsigned int length) { 
 Serial.print("Message arrived on topic: ");
 Serial.print(topic);
  Serial.print(". Message: ");
  String messageLight;

Installing Software on Raspberry Pi

1. Installing MQTT Broker on Raspberry pi.

- Open a Terminal and insert the following commands line by line:

wget  http://repo.mosquitto.org/debian/mosquitto-repo.g...

 sudo apt-key add mosquitto-repo.gpg.key
cd /etc/apt/sources.list.d/

- For jessie version

sudo wget  http://repo.mosquitto.org/debian/mosquitto-jessie...

in case you have wheezy version on Raspberry pi, insert the
following command instead

sudo wget  http://repo.mosquitto.org/debian/mosquitto-wheezy...

- Updating the source list

apt-get update

- installing the broker

apt-get install mosquito 

apt-get install mosquitto-clients

2. Installing MYSQL data base for the server

- Installing apache server

sudo apt install apache2

- Installing PHP

sudo apt install php php-mbstring

- Confirming PHP is working:

- delete the file “index.html” in the directory “/var/www/html”. by inserting the command:

sudo rm /var/www/html/index.html

- Create index.php file

echo "<?php phpinfo ();?>"> /var/www/html/index.php

- Install MYSQL

sudo apt install mysql-server php-mysql

- Verify that MySQL is working correctly. First create a MYSQL user and password.

sudo mysql -u root -p

- Replace ‘username’ and ‘password’ with your chosen username and password

GRANT ALL PRIVILEGES ON mydb.* TO 'username'@'localhost' IDENTIFIED BY 'password';

- Installing PHPMyAdmin

sudo apt install phpMyAdmin

- Check that PHPMyAdmin is working properly by inserting the following line in your web browser:

http://127.0.0.1/phpmyadmin

- If you still get an error, it could be because PHPMyAdmin has moved to another directory. In this case, try the command and check again.

sudo ln -s /usr/share/phpmyadmin/var/www/html/phpMyAdmin

Node Red

Node-RED - Google Chrome 3_31_2019 10_03_08 AM.png

Mosquito mqtt node has been used to read data from the light

sensor convert it to integer with a Change node and then create a gauge and set the data to database reading format which will be inserted into database (mydb) afterwards with SQL Insert function .

After the data has been inserted to mydb, it will be used to create a chart to be monitored from the dashboard.

Max form has been created to specify the max amount of readings should be shown on the chart form starting from the first reading to max inserted by the user interface.

node red dashboard

Final files