Lesson 5: Paho and Crossbar.io
Lab 5A: Eclipse Mosquitto and Eclipse Paho
On Windows, download and install Mosquitto
Go to System Properties > Environment Variables > Path > New, and enter C:\Program Files\Mosquitto
On macOS, install and start Mosquitto with
brew install mosquitto
brew services start mosquitto
On Raspberry Pi, install and run Mosquitto to subscribe on one terminal and publish on another
$ sudo apt update
$ sudo apt install mosquitto mosquitto-clients
$ mosquitto_sub -h localhost -v -t " \$ SYS/#"
Press control-c to stop mosquitto_sub
$ service mosquitto status
$ netstat -tln
$ mosquitto_sub -h localhost -v -t test/topic &
$ mosquitto_pub -h localhost -t test/topic -m " Hello"
Intall Paho and run code to subscribe on one terminal and publish on another
$ sudo pip3 install -U paho-mqtt
$ git clone https://github.com/eclipse/paho.mqtt.python.git
$ cd ~ /iot/lesson5
$ python3 client.py
Terminal 1 (press control-c to stop)
Terminal 1 (press control-c to stop)
$ python3 sub-multiple.py
$ python3 pub-multiple.py
Terminal 1 (press control-c to stop)
On Raspberry Pi OS (Bullseye), change /opt/vc/bin/vcgencmd to /usr/bin/vcgencmd in system_info.py
Copy ~/iot/lesson5/system_info.py to ~/demo
Copy ~/iot/lesson5/subraspi.py to ~/demo
Copy ~/iot/lesson5/pubraspi.py to ~/demo
Replace topic "Raspberry Pi" with a unique hostname in both subraspi.py and pubraspi.py
Run subraspi.py on Terminal 1 and pubraspi.py on Terminal 2
Terminal 1 (press control-c to exit)
$ cd ~ /demo
$ cp ~ /iot/lesson5/subraspi.py .
$ nano subraspi.py
$ python3 subraspi.py
Terminal 2 on Raspberry Pi or another computer (press control-c to exit)
$ cd ~ /demo
$ cp ~ /iot/lesson5/system_info.py .
$ cp ~ /iot/lesson5/pubraspi.py .
$ nano pubraspi.py
$ python3 pubraspi.py
Optional Lab 5B: Crossbar.io
Docker Desktop download for macOS or Windows
Docker Engine for Linux (CentOS, Debian, Fedora, Raspberry Pi OS, and Ubuntu)
$ docker version
$ docker images
$ docker
$ docker run --rm hello-world
$ docker run -it ubuntu bash
# pwd
# ls
# cat /etc/os-release
# date
# exit
On Raspberry Pi, install Docker
Install Docker on Raspberry Pi OS by following these instructions
Run cURL to download data from example.com with or without the progress meter
Run Docker commands and hello-world
Add pi to the Docker group as a non-root user, logout SSH, and reconnect SSH for this to take effect
$ man curl
$ curl example.com
$ curl -o example.txt example.com
$ cat example.txt
$ sudo docker version
$ sudo docker images
$ sudo docker run --rm hello-world
$ sudo docker images
$ sudo usermod -aG docker pi
$ logout
Run Crossbar.io router on Raspberry Pi Terminal 1
$ git clone https://github.com/crossbario/crossbar-examples
$ cd crossbar-examples/getting-started
$ tree
$ docker pull crossbario/crossbar-armhf
$ docker run -v $PWD :/node -u 0 --rm --name=crossbar -it -p 8080:8080 crossbario/crossbar-armhf
Open a browser and go to 192.168.x.xxx:8080/info (or 127.0.0.1:8080/info via VNC Viewer) to view the Crossbar.io node information
Run publish-client on Raspberry Pi Terminal 2
$ sudo pip3 install -U autobahn[twisted,encryption,serialization,xbr]
$ cd crossbar-examples/getting-started
$ cd .crossbar
$ ls
$ cat config.json
$ cd ..
$ cd 1.hello-world
$ python3 client_component_publish.py
Run subscribe-client on Raspberry Pi Terminal 3
$ cd crossbar-examples/getting-started/1.hello-world/
$ python3 client_component_subscribe.py
Press control-c to stop subscribe-client > publish-client > router