Skip to content
Snippets Groups Projects
Name Last commit Last update
host_vars
roles
README.md
playbook.yml
sctrain.sh

SCTrain-IoT-rpi

This project serves as an illustration of an IoT system that utilizes the MQTT protocol for data collection, stores the data in InfluxDB, and visualizes it using Grafana.

What we need

  • Raspberry pi 4
  • micro SD card
  • Power supply for Raspberry pi
  • Some IoT devices ( Bluetooth, WiFi modules ....)

Create IoT System on RPI

  • Downloand and install raspberry pi imager https://www.raspberrypi.com/software/.
  • Flash Raspbian 64bit Lite to SD card (you can configure WiFi and SSH key before flashing)
  • Get IP address of Raspberry pi (from your router or by command: nmap -sP 192.168.8.0/24 # ip change for your network)
  • ssh to your Rpi. (ssh pi@ip_address_of_your_rpi)
  • switch to root (sudo su -)
  • Copy and run sctrain.sh script (Copy text from script and paste to th stript on rpi: nano sctrain.sh add permission to execute chmod +x strain.sh and run script ./sctrain.sh )
  • Pray !!!
  • If everything finished well, go to http://IPofYourRPI:8086 to configure influxdb.
  • set username, password, organization as it4i, initial bucket name as it4i.
  • create write/read token, on data/tokens.
  • copy token and past it on /etc/telegraf/telegraf.conf, find outputs.influxdb_v2 section and replace text "changeme".
  • You can test mqtt connection by some mqtt tool (mqtt explorer)
  • test send mqtt data to topic it4i/test data in json format { "test": 1 } and explore this data on influxdb.
  • Add ESP32 Iot device to send data. ( need to change wifi credentials and mqtt IP on code ). https://code.it4i.cz/sccs/sctrain-iot-esp32
  • Go to http://IPofYourRPI:3000 and connect to grafana (admin:admin)
  • Add datasource.
  • Dashboard, dashboard and dashboards.

What this script do?

  • Script install git, ansible and clone this repository.
  • Run ansible playbook to do all the magic.

Role packages

install standart packages, like vim, wget, telnet ...

Role grafana

Install grafana and start and enable sevice grafana-server.service

Role influxdb

Install influxdb and telegraf from DEB package. Configure telegraf from template. Start and enable influxdb and telegraf.

Role mqtt

Install packages for mqtt, such as mosquitto and mosquitto-clients. Configure mosquitto from template. start and enable mosquitto service.

Extra Add mi flora

https://github.com/ThomDietrich/miflora-mqtt-daemon