77 lines
1.7 KiB
Markdown
Raw Normal View History

2016-01-31 16:19:38 -06:00
# Adafruit MQTT Library example with support
2016-01-31 18:57:43 -06:00
This example illustrates Publish an arbitrary data packet using the Adafruit MQTT library to an MQTT feed which can then be parsed by the included python subscriber client.
2016-01-31 19:02:57 -06:00
2016-01-31 19:15:46 -06:00
## Installing and configuring Mosquitto (minimal working setup)
2016-01-31 19:22:40 -06:00
####On Raspberry Pi/Linux:
2016-01-31 19:15:46 -06:00
2016-01-31 19:02:57 -06:00
```bash
sudo apt-get install mosquitto
2016-01-31 19:15:46 -06:00
cd /etc/mosquitto/
2016-01-31 19:22:40 -06:00
#See "Both" Setup Instructions Below
2016-01-31 19:02:57 -06:00
```
2016-01-31 19:03:23 -06:00
####On a Mac:
2016-01-31 19:02:57 -06:00
```bash
brew install mosquitto
2016-01-31 19:15:46 -06:00
cd /usr/local/etc/mosquitto
2016-01-31 19:22:40 -06:00
#See "Both" Setup Instructions Below
2016-01-31 19:15:46 -06:00
```
2016-01-31 19:22:40 -06:00
####Both
2016-01-31 19:15:46 -06:00
```bash
sudo nano mosquitto.conf
```
2016-01-31 19:22:40 -06:00
Now we have to enable a password file to correctly interface with the Adafruit MQTT library. Scroll about two thirds of the way down until you see:
2016-01-31 19:15:46 -06:00
```bash
# -----------------------------------------------------------------
# Default authentication and topic access control
# -----------------------------------------------------------------
```
You should see `#password_file` about a paragraph after that.
Change
```bash
#password_file
```
To
```bash
password_file pwfile
2016-01-31 19:02:57 -06:00
```
2016-01-31 19:15:46 -06:00
Now `ctrl-x` to save and exit.
2016-01-31 19:02:57 -06:00
2016-01-31 19:22:40 -06:00
You're almost done! We just have to create and populate the password file we just configured. The default user names are:
-#####Arduino publisher:
--Username: TestUser
--Password: TestUser
```bash
touch pwfile #create the password file
```
2016-01-31 19:00:38 -06:00
## Using Example Python Subscriber:
2016-01-31 18:57:43 -06:00
2016-01-31 19:22:40 -06:00
Install dependencies if haven't already
2016-01-31 18:59:14 -06:00
```bash
2016-01-31 18:57:43 -06:00
cd ../Adafruit_MQTT_Library/examples/mqtt_arbitrary_buffer/python_subscriber
pip install -r requirements.txt
2016-01-31 18:59:14 -06:00
```
2016-01-31 18:57:43 -06:00
2016-01-31 19:22:40 -06:00
Run python script with default values and watch your parsed data print out.
2016-01-31 18:59:14 -06:00
```bash
2016-01-31 18:57:43 -06:00
python subscriber.py
2016-01-31 18:59:14 -06:00
```
2016-01-31 18:57:43 -06:00
2016-01-31 19:00:38 -06:00
Use help to see a list of modifiable options
2016-01-31 18:59:14 -06:00
```bash
2016-01-31 18:57:43 -06:00
python subscriber.py -h
2016-01-31 18:59:14 -06:00
```