-
Notifications
You must be signed in to change notification settings - Fork 14
3.1 Raspberry Pi setup using IOTStack
The benefit of using IOTStack to install ClassicMQTT is that it makes it easy to include other docker images like InfluxDB, Telegraf and Grafana. IOTStack will help you generate a docker-compose.yml file by merging the ClassicMQTT definitions specified in the compose-override.yml file and the other docker images you select in the 'Build Stack' (ex InfluxDB, Telegraf, Grafana, Portainer-ce).
Sample grafana dashboard
Portainer - Container list running on Raspberry PI
-
Flash the Raspberry Pi OS (32-bit) onto SD card using the Raspberry Pi Imager found at www.raspberrypi.org/software.
-
For headless setup, SSH can be enabled by placing a file named ssh onto the boot partition of the SD card (see www.raspberrypi.org/documentation/remote-access/ssh)
-
install sd card into rpi and power it up.
-
Find raspberry pi's IP address on your router and reserve address. (example used in this document is 192.168.0.25, yours will be different)
-
log in using ssh [email protected] (default password is raspberry)
-
run sudo raspi-config
-
select update then **Finish **when done
-
Change the default password using: passwd or use passwordless SSH access by copying your public key to rPi (see www.raspberrypi.org/documentation/remote-access/ssh/). Using powershell on Windows 10, execute: cat ~/.ssh/id_rsa.pub | ssh [email protected] 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys'
-
sudo apt update
-
sudo apt upgrade -y (available on new versions of Pi)
-
sudo reboot
-
login again with ssh [email protected]
The benefit of using IOTStack is that it makes it easy to include other docker images like InfluxDB, Telegraf, Portainer-ce and Grafana.
Before setting up IOTStack and docker, create a new group called docker and add the current user to the docker group.
- Create the docker group if it does not exist.
sudo groupadd docker
- Add the current user to the docker group.
sudo usermod -aG docker $USER
- Log in to the new docker group (to avoid having to log out / log in again; but if not enough, try to reboot):
newgrp docker
-
( IOTStack Wiki available at:` https://sensorsiot.github.io/IOTstack/Basic_setup/ )
cd ~ sudo apt install -y curl
curl -fsSL https://raw.githubusercontent.com/SensorsIot/IOTstack/master/install.sh | bash
say yes to everything
-
Required patches as per IOTstack documentation;
sudo bash -c '[ $(egrep -c "^allowinterfaces eth\*,wlan\*" /etc/dhcpcd.conf) -eq 0 ] && echo "allowinterfaces eth*,wlan*" >> /etc/dhcpcd.conf'
echo $(cat /boot/cmdline.txt) cgroup_memory=1 cgroup_enable=memory | sudo tee /boot/cmdline.txt
sudo reboot now
-
login again with ssh [email protected]
Copy the compose-override.yml file from ClassicDIY/ClassicMQTT/code/Python to the IOTStack directory on the pi using:
-
cd ~/IOTstack
-
sudo wget https://raw.githubusercontent.com/ClassicDIY/ClassicMQTT/master/code/Python/compose-override.yml
-
edit the compose-override.yml file using: sudo nano compose-override.yml
-
Change the IP address for CLASSIC= to your classic's IP address along with the name of your classic by updating CLASSIC_NAME=.
-
If you want to setup a user/password for the mosquitto MQTT broker, refer to create-username-and-password then include your user/password in the compose-overide.yaml file for the MQTT_USER= and MQTT_PASS=
-
If you have more than one classic you will need to uncomment the second classic_mqtt block and set your second classic's IP and Name as in the example below.
*indentation is important with yaml files, make sure both classic_mqtt and classic_mqtt2 blocks have the same indentation.
-
If you have an external or cloud based MQTT broker, set the MQTT_HOST and PORT to it's IP address or Name along with it's username and password as in the example below.
-
run ./menu.sh and select Build Stack
-
Select the following containers to build using the space bar to select: Grafana InfluxDB Mosquitto Portainer-CE Telegraf
-
hit enter when done.
-
select Docker Commands and then Start stack.
-
You should see the following logs
-
exit menu.sh and run docker ps
-
You should see the following docker containers
- cd ~/IOTstack/volumes/telegraf/
- sudo wget -O telegraf.conf https://raw.githubusercontent.com/ClassicDIY/ClassicMQTT/master/code/Python/telegraf.conf
- docker container restart telegraf
(IOTStack documentation https://sensorsiot.github.io/IOTstack/Containers/Portainer-ce/)
-
Browse 192.168.0.25:9000
-
Create an admin User & Password
-
Select: Docker (Manage the local Docker environment)
-
Connect
-
Select Containers from the Portainer Dashboard and click the logs Quick Actions Icon
-
If everything works the ClassicMQTT logs should look like the following;
-
Browse 192.168.0.25:3000
-
Use admin/admin as the default username/password, set a new password
-
Create a new InfluxDB datasource (Video tutorial)
-
URL: http://influxdb:8086
-
Database: mqtt_solar
-
User: dba
-
Password: supremo
-
HTTP Method: GET
-
Save & Test
-
Import sample dashboard from https://github.com/ClassicDIY/ClassicMQTT/blob/master/code/Python/grafana_dashboard.json
-
Download and install MQTT.fx
-
Connect to the MQTT broker using the Pi's IP and port 1883
-
Subscribe to ClassicMQTT/#
-
Publish a wake command to the broker ( ClassicMQTT/MyWorkshop/cmnd ["WAKE"] )
-
You should see the following messages from ClassicMQTT