-
-
Notifications
You must be signed in to change notification settings - Fork 11
FanPico MQTT Tutorial
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.
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.
First, head to io.adafruit.com and sign up for a free account.
Next, we need to obtain MQTT login and password so that FanPico can connect to MQTT broker.
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.
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
Next we need to decide what data to send to MQTT server and how often.
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).
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
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
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
Next we save configuration changes and reset the unit to get it to enable MQTT client.
CONF:SAVE
*RST
After few minutes, we should start seeing data in the Feeds section in io.adafruit.com web interface:
After we have data feeding into adafruit.io, we can create dashboards from our data.
Under Dashboards menu, click "New Dashboard" button:
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:
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.
Go to "Feeds" menu and click "New Feed" button to create the command topic (feed):
Create feed with the command topic name ("fanpico_cmd"):
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:
As a test we can update virtual sensor temperature using "WRITE:VSENSOR 42.0":
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:
Check latest response by clicking the "View" link: