Publish to a Channel Using Desktop MQTT Client

This example shows how to use a desktop MQTT client to publish to a channel. The example uses MQTT.fx, which is a JavaFX-based MQTT client. 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.

Prepare Software

1) Create a new channel, as shown in Collect Data in a New Channel.

2) Download and install MQTT.fx. This example was tested with MQTT.fx version 1.3.1.

Configure MQTT.fx Client

1) Configure the connection profile for the desktop MQTT client. Click the gear icon to the right of the profile name, and then the plus button on the lower left.

2) In the Connection Profile dialog box, enter the Broker Address mqtt.thingspeak.com and Port 1883. Click the Generate button to generate a unique Client ID.

3) Choose the User Credentials tab, enter any user name and your MQTT API key from your ThingSpeak Account > My Profile page.

Publish to Channel Feed

1) Click Connect to connect to the ThingSpeak MQTT broker.

2) Enter the following topic to publish data to a channel feed.

channels/<channelID>/publish/<apikey>

3) 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 the status message MQTTPUBLISH.

Publish to Channel Field

Alternatively, you can enter the following topic to publish to a channel field.

channels/<channelID>/publish/fields/field<fieldnumber>/<apikey>

Replace <channelID> with the channel ID, <fieldnumber> with field number that you 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.

See Also

|

Related Examples

More About