Skip to content

3.1 Raspberry Pi setup using IOTStack

Graham Ross edited this page Jan 29, 2021 · 48 revisions

The benefit of using IOTStack to install ClassicMQTT is that you can include other docker images like InfluxDB and Grafana etc.

Raspberry Pi setup

  • 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 pi@192.168.0.25 (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 pi@192.168.0.25 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys'

Update the OS

  • sudo apt update

  • sudo apt full-upgrade (available on new versions of Pi)

  • sudo reboot

  • login again with ssh pi@192.168.86.25

Setup IOTstack:

  • Install git: sudo apt install -y git curl

  • cd ~

  • Get IOTStack from github using git: git clone https://github.com/SensorsIot/IOTstack.git IOTstack

  • cd ~/IOTstack

  • Run IOTStack: sudo ./menu.sh

  • IOTStack should install Python, Docker and Docker compose, if it doesn't, select "Native Installs" then select "Install Docker and Docker-Compose".

  • Reboot the pi when done.

Create the ClassicMQTT container using IOTstack:

note: If you have more than one classic please see the section below

  • cd ~/IOTstack

  • create a file called .env using nano .env

  • Add the following text to the file (use your classic's IP address and whatever name you want to call it)

CLASSIC=192.168.0.37

CLASSIC_PORT=502

CLASSIC_NAME=MyClassic

MQTT_ROOT=ClassicMQTT

MQTT_USER=ClassicPublisher

MQTT_PASS=ClassicPub123

  • Copy the compose-override.yml file from ClassicDIY/ClassicMQTT/code/Python to the IOTStack directory on the pi.

  • run sudo ./menu.sh and select Build Stack

  • Select: Portainer-ce, Eclipse-Mosquito and whatever else you plan on using (InfluxDB, Grafana...) using the space bar

  • Hit Enter when done.

  • Select Docker Commands and then Start stack.

  • You should see the following logs Build Stack log

  • exit menu.sh and run sudo docker ps

  • You should see the following docker containers Build Stack log

More than one classic?

If you have more than one classic you will need to add the extra parameters to the .env file and you will need to duplicate and modify the classic_mqtt block in the compose-override.yml file as shown below.

env

compose2 *indentation is important with yaml files, make sure both classic_mqtt and clssic_mqtt2 blocks have the same indentation.

Setup Portainer-ce: (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 Build Stack log

  • If everything works the ClassicMQTT logs should look like the following; Build Stack log

Setup Mosquito password: (IOTStack documentation https://sensorsiot.github.io/IOTstack/Containers/Mosquitto/)

  • The above installs the mosquito broker with no user credentials, if you want to add the user defined in the .env file above, execute the following

  • docker exec -it mosquitto sh

  • mosquitto_passwd -c /mosquitto/pwfile/pwfile ClassicPublisher

pw ClassicPub123

re-enter pw ClassicPub123

exit

Connect to MQTT broker using MQTTfx to test.

  • Download and install MQTT.fx

  • Connect to the MQTT broker using the Pi's IP and port 1883 Build Stack log

  • Subscribe to ClassicMQTT/#

  • Publish a wake command to the broker Build Stack log

  • You should see the following messages from ClassicMQTT Build Stack log

Clone this wiki locally