opportunity to see another database server

FIND A SOLUTION AT Academic Writers Bay

University of Wolverhampton
School of Mathematics and Computer Science
Student Number:
IoT Security Workshop 7

Lab Description
Every software framework, including ours, must end with a data visualization tool, for example in the form of a dashboard. In our case, we choose the use of Grafana, one of the most popular tools for generating dashboards. There are other tools, more or less expensive and powerful, all basically functioning in the same way so our example can be easily generalised. Our dashboards will be powered by data from databases. But, instead of using MySQL (already installed), I think it is a good opportunity to see another database server, specifically InfluxDB, particularly suitable and optimized to save time-series from sensors. The idea is therefore to use MySQL to save data in the long term, while InfluxDB for short (but fast) time windows.
Task 1, Install InfluxDB, the time-series database:
Start you VM
Open a terminal and type these commands
wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add –
Single line source /etc/lsb-release
sudo echo “deb https://repos.influxdata.com/ubuntu bionic stable” | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt update
sudo apt install influxdb
To check if the installation went fine, type
sudo systemctl status influxdb
and you should get the corresponding output
Which means the tool is installed but not running yet. To start it, and to restart it every system restart, type
sudo systemctl enable –now influxdb
Now, try again with
sudo systemctl status influxdb
and the new output should be similar to
where it stems (in green) that the database is running. (press Q to return to the terminal).
Now, we need to create a new user for the database. In the terminal, type
to connect to the database server. Now type the following commands to create a user and a database
Type “exit” to quit from the server shell and return to the terminal.
Using Internet, try to explain (with you own words) why a time-serie database is a better option to store data coming from iot devices. [MARKS]
Task 2, Modify our NODE-RED flow to save data in InfluxDB
In order to connect NODE-RED to our new database, we need to install the corresponding “nodes”. In the terminal, type
sudo npm install node-red-contrib-influxdb -g
Start node-red with
node-red -v
and open your browser to http://localhost:1880
In another terminal, start your sensor (see previous workshop) in order to see the mqtt messages in the debug window
Name of measurements
InfluxDB require a specific structure for the message, similar to the following
msg.payload = [
measurement: “weather_sensor”,
Measurement’s details
temp: 5.5,
light: 678,
Help to identify the sensor
humidity: 51
Current timestamp
timestamp: new Date()
return msg;
So we need to change our current message format, which is
In order to change the message structure, we need a “function” node (let’s call it “to InfluxDB”)
Double click on the new node and configure it as follows
As you can see, we are creating a new upload, following the structure required by InfluxDB. To check the resulting message, add a new “Debug” node
Click on the small rectangle on other debug nodes to temporally disable them, so to reduce the number of messages
If everything is correct, the resulting message should be similar to
Paste a screenshot of your message. [MARKS]
Now it is time to save those messages to InfluxDB. Add a new node of type “influxdb batch”
Double click on it and configure it as follows
Add a new server
The user/pwd we created before
The database we created before
Deploy the flow and fingers crossed!
To check if the database is receiving the data, open a new terminal and type
use iotdb
show measurements
select * from iot_device
you should see many rows similar to
The first column is the timestamp, expressed as the number of milliseconds from epoch; the second column is the id of our device, and the last column is the temperature.
Try to change the temperature (not 0) and refresh the terminal with
select * from iot_device
Paste a screenshot of your data. [MARKS]
Type “exit” to close the database and return back to the terminal.
Nice! Time to visualise the data.
Task 3, Install Grafana and create a dashboard
Leave NODE-RED and the sensor running in other terminals. In a new one, type
wget -q -O – https://packages.grafana.com/gpg.key | sudo apt-key add –
sudo add-apt-repository “deb https://packages.grafana.com/oss/deb stable main”
sudo apt update
sudo apt install grafana
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
Check if the server is running properly with
sudo systemctl status grafana-server
you should see in green “Active (running)” (press Q to return back to terminal)
Open a browser and go to http://localhost:3000
The default user is “admin” with password “admin”. Please login and then change the password to something more secure (for example, iotmodule, write it down!).
Create a new datasource for our dashboard
Click “Add data source”
Click on InfluxDB
Configure it as follows
Click on “Save & Test” and check that the datasource is working correctly.
Then, click “Back”.
Click on the left “Dashboards” and then “Manage”
Click “New dashboard”. Now you can create your dashboard, adding as many panels as you want. Each panel contains a chart or a widget and can be moved around the screen. Click on “Add a new empty panel”
In the bottom part of the screen, there is the “Query” section where you can select the data to be shown in the chart. Configure Query A as follows by clicking the corresponding values:
In the top-right, change the panel title to “Sensor temperature” and click Apply to confirm the first panel.
Doing so, the dashboard now contains a line-chart to display the historical values of the temperature. You can change the time-window by clicking on the top right
Set the time-window to 15 mins. Now, set the auto-refresh of the dashboard to 10sec
Now, move a bit the slider of our sensor in order to change its temperature. After 10sec, you should see the chart with the updated values.
Paste your screenshot of your chart. [MARKS]
It is also nice to have a second widget, showing the current (or last) value of the temperature. Since we need the same field (temperature), instead of creating a new panel, we can duplicate the existing one. Click on the arrow next to the panel’s title, then click “more” and then “Duplicate”
A second (identical) panel should appear. Click on the arrow next to its title and choose “Edit”.
On the right, expand the “visualisation” section and choose “Gauge”
Change the title to “Current Temperature”
Since the temperature is expressed as 0.1 C, we may want to divide the value in the query A
Add “math” and then write “/10”
Press Apply to confirm the new aspect of the widget. The resulting dashboard should be similar to
Paste your screenshot of your chart. [MARKS]
Save your dashboard by clicking and providing a name of your choice.
[Optional] You can try to add more panels, or to change the colours, or to play more with Grafana in general. The latter is so complex that it would require an entire course to master but I hope it is sufficient as a starting point for your own projects. This is the end of workshop 7. Please close all your terminals and shutdown the machine.

YOU MAY ALSO READ ...  Managing Own Personal and Professional Development
Order from Academic Writers Bay
Best Custom Essay Writing Services