Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Publish to a Channel Using Desktop MQTT Client

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.

  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.

  3. 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.

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

  5. Click Connect to connect to the ThingSpeak MQTT broker.

  6. 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.

See Also

|

Related Examples

More About

Was this topic helpful?