Publish to a Channel Feed
Publish message to update multiple channel fields simultaneously with MQTT
Topic
channels/<channelID>/publish
Description
channels/
updates a channel
feed by publishing a message to the specified topic. Replace <channelID>
/publish<channelID>
with your ThingSpeak channel ID. To learn more about configuring your channel, see Channel Properties. To update multiple parameters simultaneously, see Payload Parameters.
Add any necessary Payload Parameters.
Set the
PUBLISH
messages to have aQoS
value of0
.Set the connection
RETAIN
flag to0
(off).Set the connection
CleanSession
flag to1
(true
).
To learn more about these flags, see the MQTT v3.1.1 specification.
Input Arguments
Payload Parameters
Specify the optional payload parameters for the PUBLISH
message as a string
with Name=Value
arguments, separated by &
. For
example: field1=100&field2=50&lat=30.61&long=40.35
If the
parameter definition string contains any special characters, it must be URL (percent) encoded
(application/x-www-form-urlencoded).
field1
Data to be entered in field 1 of a channel.
For example:
field1=100
fieldx
Data to be entered in field x of a channel. Make sure the field is enabled in the channel settings.
For example:
fieldx=100
x must be less than or equal to 8, the number of allowed fields.
lat
Location of your channel in the form of latitude.
For example:
lat=10.45
long
Location of your channel in the form of longitude.
For example:
long=35.4
elevation
Elevation of your channel from the ground level in meters.
For example:
elevation=100
status
Status message of your channel.
For example:
status=Message
created_at
Date of feed entry in ISO 8601 format.
For example:
created_at=2014-12-31 23:59:59
Examples
Configure MQTT X to send a PUBLISH
message to update a channel feed.
In the New Connection dialog, use the following connection settings, along with client ID, username, and password derived when the MQTT device was created in ThingSpeak:
Name: MyChanName Client ID: ENTER_MQTT_DEVICE_CLIENT_ID Host: mqtt:// mqtt3.thingspeak.com Port: 1883 Username: ENTER_MQTT_DEVICE_USERNAME Password: ENTER_MQTT_DEVICE_PASSWORD Clean Session: true
In the Payload pane, use the following settings:
Topic: channels/33301/publish Payload: field1=45&field2=60&status=MQTTPUBLISH
This PUBLISH
message publishes a value of 45
to
field1
and 60
to field2
of channel
33301
, along with a status message MQTTPUBLISH
.
See Also
Publish to a Channel Field Feed | Troubleshoot MQTT Publish | Subscribe to a Channel Feed | Subscribe to a Channel Field Feed