Sending all fields data with Mqtt

2 visualizaciones (últimos 30 días)
Marc Hanssens
Marc Hanssens el 6 de Feb. de 2024
Comentada: Christopher Stapels el 5 de Mzo. de 2024
When using Rest api there is a neat feature whereby you can send data to fields of a channel by doing this in the thingspeakwrite ....[11,12,13,14,15,16,17,18] //where the field1 = 1, field2= 2 etc.
It appears that in Mqtt , the syntaxt must be field1= 1, filed2 etc which seems verbose. Can the data be sent using Mqtt in a syntax like PublishString= ...... ChannelID,[11,12,13,14,15,16,17,18], API_Key=mychannelkey;

Respuestas (1)

Christopher Stapels
Christopher Stapels el 13 de Feb. de 2024
Yes, there is a multiple field syntax. See the publish to channel field doc.
In the Payload pane, use the following settings:
Topic: channels/33301/publish
Payload: field1=45&field2=60&status=MQTTPUBLISH
  2 comentarios
Marc Hanssens
Marc Hanssens el 4 de Mzo. de 2024
Hi Christopher,
Thanks for the reply. I think that I didn't phase my question correctly.
In your example :Payload: field1=45&field2=60&status=MQTTPUBLISH you are passing the values 45 and 60 to fields 1 & 2 respectively.
I would like to pass the values in less verbose way and do something similar to thingspeakwrite, like: Payload: [45,60]&status=MQTTPUBLISH
is this possible with MQTT?
Christopher Stapels
Christopher Stapels el 5 de Mzo. de 2024
thingSpeakWrite is a function in MATLAB, though it does use the REST API in the background.. You can definitely write MATLAB functions to simplify your code, but you will need to keep them in your MATLAB analysis or visualizations code (you cant yet call custom functions in your ThingSpeak code, though you can in MATLAB online). You can use MATLAB to communicate with ThingSpeak via MQTT. The syntax you use inside your functions will still need to be what is shown above.

Iniciar sesión para comentar.

Categorías

Más información sobre Write Data to Channel en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by