MQTT - alanbjohnston/CubeSatSim GitHub Wiki

MQTT with Adafruit.io - AIO

These instructions are to configure the Raspberry Pi Pico W in the CubeSatSim Main board to connect to the Adafruit.io service over your WiFi network.

You will need the Arduino IDE software installed on your computer and an account on adafruit.io to view the sensor data published using MQTT. The code can be modified to use other IDEs.

Setup Arduino IDE Environment

You will need to follow the steps here to get the Arduino IDE installed and libraries loaded so you can modify the code for the Raspberry Pi Pico W: Adding New Sensors

Instead of adding a new sensor, you should compile and upload this code: https://github.com/alanbjohnston/CubeSatSim/tree/master/stempayload/Payload_BME280_MPU6050_AIO which supports the built-in BME-280 and MPU-6050 sensors on the Main board and adds support for Adafruit.io

Configuring for Adafruit.io

To use this code, you will need to create a Free account at https://io.adafruit.com/

You will need to configure your Adafruit.io account information and your WiFi credentials. When you open the Payload_BME280_MPU6050_AIO.ino file inside the Arduino IDE v1.8 application, select the tab labeled edit_this_config_and_rename.h

Note: You might need to widen the window to see this tab.

Select the pulldown arrow and select Rename.

At the bottom, edit the filename until it just says config.h

Then select OK.

Open the Adafruit.io Overview page (The URL will be io.adafruit.com/your_username/overview where your_username is your Adafruit login ID):

Select the yellow key icon in the upper right to show you API key:

Copy the two lines listed under "Arduino" that have these two lines:

#define IO_USERNAME "your_username"

#define IO_KEY "your_key"

Paste them into the config.h file in Arduino:

Scroll down in the file and put your WiFi login information by editing these two lines:

#define WIFI_SSID "your_ssid"

#define WIFI_PASS "your_pass"

Connect your computer running the Arduino IDE to your Raspberry Pi Pico W on the Main PCB with a micro USB Cable.

Under Tools and Port, make sure your Pico W is selected.

Compile and Upload the code using the Right Arrow icon in the top right. If it works, you should end up with this message or something similar:

If you get errors, it probably means you haven't selected the right Port or you are missing a required Arduino Library. Go back to the Adding New Sensors instructions and make sure you can upload code starting with Blink.

If you open the Serial Monitor (Magnifying Glass icon in the top right of the window) you should see these messages, in addition to the usual payload and squelch messages:

Connecting to Adafruit IO…

Then:

Successfully connected to Adafruit IO! Status: Adafruit IO connected.

And then:

Waiting to send Adafruit IO

And:

Sending to Adafruit IO -> 25.11 1013.85 -5.01 56.93 0.02 -0.08 1.03

These messages will scroll by quickly, so you might need to uncheck the Autoscroll box in the Serial Monitor window to see them.

If you see these messages, it indicates that your Pico W has connected to your WiFi and uploaded the sensor data using MQTT to the Adafruit.io cloud.

Configuring the Adafruit.io Dashboard

To display the data, follow these steps to setup your Dashboard:

Open your Adafruit.io account and go to the Overview page. Scroll down and you should see your CubeSatSim sensor data under Live Data. You shouldn't see any errors under Live Errors:

Now we need to create a Dashboard to display the data. Select the Dashboards tab:

Select the New Dashboard button:

Give your Dashboard and name and a Description then select Create:

Select New Block to display data:

Select Line Chart for a moving graph:

Select at least one Feed from the list, for example select temperature from the BME 280 sensor and select Next step:

Give it Block Title, and select the desired Show History period:

Scroll down and select Create Block and you will see it in the Dashboard:

I found I needed to reload the Dashboard to start to see live data being displayed:

If you want the Dashboard to be visible to anyone else, you need to change the Privacy setting in the Dashboard Settings by selecting the Gear icon in the upper left:

Select the Dashboard Privacy slider and you will get this confirmation box:

After you select Confirm, the Dashboard will be visible to anyone on the internet with the URL:

You can share the URL as adafruit.io/your_username/dashboards/dashboard_name where your_username is your Adafruit login and dashboard_name is what you called the Dashboard. For my account ku2y for dashboard named CubeSatSim the URL would be:

Here's how it looks in another browser: