Skip to content

FanPico MQTT Tutorial

Timo Kokkonen edited this page Dec 31, 2023 · 14 revisions

FanPico MQTT Client

FanPico has MQTT Client (starting from firmware version 1.6.0) that can send periodic status updates to a MQTT broker. There is also support to subscribe a "command" topic to receive commands.

FanPico MQTT Client with adafruit.io

This is short tutorial on setting up FanPico to work with Adafruit MQTT Server (io.adafruit.com). This covers configuring FanPico to connect to Adafruit MQTT broker and to send periodic status updates and then creating a simple dashboard from the data.

dashboard sample

Create (free) Adafruit account

First, head to io.adafruit.com and sign up for a free account.

Obtain MQTT Credentials

Next, we need to obtain MQTT login and password so that FanPico can connect to MQTT broker.

adafruit_menubar

Click the yellow key icon on the tool bar to obtain "IO Key". Username is your adafruit user ID and the "active key" is the password you need.

adafruit_iokey

Configure MQTT Server and Credentials

Now we can configure MQTT server on our FanPico unit:

SYS:MQTT:SERVER io.adafruit.com
SYS:MQTT:USER username
SYS:MQTT:PASS aio_XXXXXXXXXXXXXXXXXXXXXXXX

Configure Topics

Next we need to decide what data to send to MQTT server and how often.

Temperature Sensors

Our FanPico has sensor1 setup to measure intake air temperature and sensor2 setup to measure exhaust air temperature.

We'll want to monitor all sensors, we'll configure MQTT topic for temperature sensors and enable sending temperature updates to MQTT servers every 60 seconds:

SYS:MQTT:TOPIC:TEMP username/feeds/fanpico_temp%d
SYS:MQTT:INT:TEMP 60
SYS:MQTT:MASK:TEMP 1-3

"%d" in the topic name will be substituted with the sensor number. And "MASK" is used to specify which sensors should send updates (default is none).

Fan Speeds

Next we configure FAN1, FAN2, and FAN5 ports to send current fan RPM data periodically to MQTT server.

SYS:MQTT:TOPIC:FANRPM username/feeds/fanpico_fan%d_rpm
SYS:MQTT:INT:FANRPM 60
SYS:MQTT:MASK:FANRPM 1-2,5

Motherboard Fan Speed Signals

Next we configure MBFAN1 port to send PWM (duty cycle) that motherboard is sending).

SYS:MQTT:TOPIC:MBFANPWM username/feeds/fanpico_mbfan%d_pwm
SYS:MQTT:INT:MBFANPWM 60
SYS:MQTT:MASK:MBFANPWM 1

General Status and Command Topics

Next we configure topic names for periodic status updates (in JSON) format as well as command and response topics for sending commands to FanPico.

SYS:MQTT:TOPIC:STATUS username/feeds/fanpico_status
SYS:MQTT:INT:STATUS 600
SYS:MQTT:TOPIC:COMMAND username/feeds/fanpico_cmd
SYS:MQTT:TOPIC:RESPONSE username/feeds/fanpico_response

Save Configuration and Reset

Next we save configuration changes and reset the unit to get it to enable MQTT client.

CONF:SAVE
*RST

Check Feeds

After few minutes, we should start seeing data in the Feeds section in io.adafruit.com web interface:

feeds

Create a DashBoard

After we have data feeding into adafruit.io, we can create dashboards from our data.

Under Dashboards menu, click "New Dashboard" button:

new dashboard

For example, here is simple dashboard that uses the motherboard (MBFAN1) PWM signal to display a gauge and two line graphs for FAN RPM signals and the Temperature signals:

fanpico_dashboard

Sending Commands

When command topic is configured on FanPico, it will subscribe to that topic and wait for commands. By default only "WRITE" commands are allowed, but if SYS:MQTT:SCPI ON has been issued then any SCPI commands will be accepted.

Create Command Topic

Go to "Feeds" menu and click "New Feed" button to create the command topic (feed):

new feed

Create feed with the command topic name ("fanpico_cmd"):

create feed

Send Command

After command feed (topic) has been created go to the feed by clicking it in the list of feeds under "Feeds" menu.

Use the "Add Data" button to send commands:

add data

As a test we can update virtual sensor temperature using "WRITE:VSENSOR 42.0":

send command

Check Command Result

Since we earlier configured a "response topic", FanPico will send responses to commands it receives. (If no response topic is configured then unit won't respond to commands, but will still execute them if they're allowed).

Go to the "fanpico_response" feed:

response feed

Check latest response by clicking the "View" link:

response message