installation instructions for rpi pico
This commit is contained in:
parent
675092c39b
commit
3737721fee
56
README.md
56
README.md
@ -29,12 +29,14 @@ While there are many software packages for installing an MQTT broker, probably t
|
|||||||
|
|
||||||
Installation on Linux (debian):
|
Installation on Linux (debian):
|
||||||
|
|
||||||
```sudo apt install mosquitto-dev```
|
```sudo apt install mosquitto mosquitto-clients```
|
||||||
|
|
||||||
Once you have installed the broker, it will automatically start as a service that will run in the background, and clients can connect to it.
|
Once you have installed the broker, it will automatically start as a service that will run in the background, and clients can connect to it.
|
||||||
|
|
||||||
In Mosquitto version 2+ extra security was implemented requiring clients to connect with authentication. This is overkill for many purposes, so we will allow clients to connect anonymously by editing the configuration file.
|
In Mosquitto version 2+ extra security was implemented requiring clients to connect with authentication. This is overkill for many purposes, so we will allow clients to connect anonymously by editing the configuration file.
|
||||||
|
|
||||||
|
On Ubuntu:
|
||||||
|
|
||||||
Locate `/etc/mosquitto/mosquitto.conf`
|
Locate `/etc/mosquitto/mosquitto.conf`
|
||||||
|
|
||||||
Open the file for editing:
|
Open the file for editing:
|
||||||
@ -61,10 +63,62 @@ To allow connections through the firewall on port 1883 (the MQTT port) you can w
|
|||||||
|
|
||||||
Note that you can get a lot more specific with UFW rules, including limiting access to certain applications or IP addresses.
|
Note that you can get a lot more specific with UFW rules, including limiting access to certain applications or IP addresses.
|
||||||
|
|
||||||
|
# Using the MQTT Client
|
||||||
|
|
||||||
|
Once the broker is up and running, and the firewall is configured to allow connections, clients can connect. This is very easy to test on the local machine, because the Mosquitto installation come with a client you can use from the command line.
|
||||||
|
|
||||||
|
MQTT organizes messaging by topics that clients can both publish to and subscribe to for updates. The topics can include anything.
|
||||||
|
|
||||||
|
On the machine where we installed the broker we can test by subscribing and publishing to the "godot" topic.
|
||||||
|
|
||||||
|
`mosquitto_sub -v -h 127.0.0.1 -t "godot/#"`
|
||||||
|
|
||||||
|
This subscribes the mosquitto client to hear updates from the broker running on 127.0.0.1 (the local machine) for any message in the "godot" topic.
|
||||||
|
|
||||||
|
In a new window, lets test publishing a message.
|
||||||
|
|
||||||
|
`mosquitto_pub -h 127.0.0.1 -t "godot/abcd" -m "Bingo!"`
|
||||||
|
|
||||||
|
In the first window, you'll see the message appear.
|
||||||
|
|
||||||
|
From this you can see that devices can be either publishers, subscribers, or both. Any devices on the same network can use their client to communicate back and forth with this messaging.
|
||||||
|
|
||||||
|
### What you can do with this:
|
||||||
|
|
||||||
|
MQTT clients are pretty ubiquitous since they are just based on TCP, a very common protocol.
|
||||||
|
|
||||||
|
If the client can be made to run on something like a microcontroller, messaging can be used to do things such boards are great at - controlling hardware.
|
||||||
|
|
||||||
|
In the next section, we will get an MQTT client working on the Raspberry Pi Pico W, a popular microcontroller built on the RP2040 chip.
|
||||||
|
|
||||||
|
To achieve this, we will need to:
|
||||||
|
|
||||||
|
* Flash the board with the language of choice (we are using MicroPython)
|
||||||
|
* Install an MQTT client written in that language
|
||||||
|
* Write code that connects to the network and uses the client code to connect to the broker
|
||||||
|
* Interpret the MQTT messaging into control of hardware
|
||||||
|
|
||||||
|
# MQTT on MicroPython
|
||||||
|
|
||||||
|
Let's begin by prepping the board for programming
|
||||||
|
|
||||||
|
In the 'resources' folder you will find specific instructions, along with the UF2 file that is needed to flash the board with MicroPython. Once that is done you'll need to have a code editor that has support for connecting to the board.
|
||||||
|
|
||||||
|
Thonny is the code editor commonly used for this.
|
||||||
|
|
||||||
|
If you do not have Thonny installed, you can follow these instructions.
|
||||||
|
|
||||||
|
Ubuntu:
|
||||||
|
|
||||||
|
`sudo apt install Thonny`
|
||||||
|
|
||||||
|
Once completed you should be able to connect to the RP2040 with Thonny.
|
||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
|
|
||||||
* Mosquitto man pages https://mosquitto.org/man/
|
* Mosquitto man pages https://mosquitto.org/man/
|
||||||
* Godot MQTT client https://github.com/goatchurchprime/godot-mqtt
|
* Godot MQTT client https://github.com/goatchurchprime/godot-mqtt
|
||||||
* Install broker/client on Linux http://www.steves-internet-guide.com/install-mosquitto-linux/
|
* Install broker/client on Linux http://www.steves-internet-guide.com/install-mosquitto-linux/
|
||||||
|
* Install broker/client on RPI https://randomnerdtutorials.com/how-to-install-mosquitto-broker-on-raspberry-pi/
|
||||||
* Core Electronics RP2040 guide https://core-electronics.com.au/guides/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/
|
* Core Electronics RP2040 guide https://core-electronics.com.au/guides/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/
|
||||||
* RP2040 client https://github.com/micropython/micropython-lib/tree/master/micropython/umqtt.simple
|
* RP2040 client https://github.com/micropython/micropython-lib/tree/master/micropython/umqtt.simple
|
||||||
|
Loading…
Reference in New Issue
Block a user