This example shows how to use a desktop MQTT client such as MQTT.FX, which is a JavaFX based MQTT client, to publish to a channel. If you have more than one sensor value that you want to send to ThingSpeak™, you can choose to publish multiple values to a channel feed. If you have only one sensor, you can publish a single value to a channel field.
Create a new channel, as shown in Collect Data in a New Channel.
Download and install MQTT.fx. This example was tested with MQTT.fx version 1.3.1.
Configure the connection profile for the desktop MQTT client. Press the gear icon to the right of the profile name, and then the plus button on the lower left.
In the Connection Profile dialog box, enter the
Broker Address
mqtt.thingspeak.com
and Port
1883
. Press the Generate button to
generate a unique Client ID.
Choose the User Credentials tab, enter any user name and your MQTT API Key from your ThingSpeak Account > My Profile page.
Click Connect to connect to the ThingSpeak MQTT broker.
Enter the topic channels/<channelID>/publish/<apikey>
to
publish data to a channel feed.
Replace <channelID>
with the channel
ID and <apikey>
with the write API key of
the channel. Enter the message to publish to the channel feed. This PUBLISH
message
publishes a value of 45 to field 1 and 60 to field 2 of the specified
channel, along with a status message MQTTPUBLISH
.
Alternatively, you can enter the topic channels/<channelID>/publish/fields/field<fieldnumber>/<apikey>
to
publish to a channel field.
Replace <channelID>
with the channel
ID, <fieldnumber>
with field number that
want to update, and <apikey>
with the write
API key of the channel. Enter the message to publish to the channel
field. This PUBLISH
message publishes a value of
45 to field 1 of the specified channel.
Publish to a Channel Feed | Publish to a Channel Field Feed