Webwrite to metadata Thingspeak Channel

3 次查看(过去 30 天)
Helllo,
I would like to write to the Metadat of my channel but I cna't get it to work. as a test , I tried wiriting to the Status which works.
if fieldName = "status"; is changed to fieldName = "metadata"; it doesn't work! does anyone know the trick for getting this to work?
code here:
%keys & ID here ...
thingSpeakURL = "http://api.thingspeak.com/";
thingSpeakWriteURL = thingSpeakURL + "update";
fieldName = "status";
fieldValue = '[100 100 100 92 93 93 94 ; 55 55 56 57 58 63 64 ; 333 444 555 666 777 888 999]';
response = webwrite(thingSpeakWriteURL,"api_key",writeApiKey,fieldName,fieldValue);
  1 个评论
Marc Hanssens
Marc Hanssens 2024-7-9
Hello all, I finally worked this out and here is my solution showing how to writethe word "meta" to the metadata setting:
where CHANNELID is your channel ID and USERKey is you user key -not the channel read or write key.
url = 'https://api.thingspeak.com/channels/CHANNELID.json?api_key=USERKey';
options = weboptions('MediaType','application/x-www-form-urlencoded','RequestMethod','put');
response = webwrite(url,"metadata","meta",options);
display(response);

请先登录,再进行评论。

回答(1 个)

Piyush Kumar
Piyush Kumar 2024-6-26
"Metadata" is one of the channel properties. You can change your channel properties on the My Channels page in the Channel Settings tab. You can also use the REST API to Write Settings.
If you are using REST API to write settings, the URL format should be like this - https://api.thingspeak.com/channels/<channel_id>.<format>
You can go through these links for more details -
If you want to update channel data using REST API, the URL format should be like this - https://api.thingspeak.com/update.<format>
  1 个评论
Marc Hanssens
Marc Hanssens 2024-6-27
Hello PK,
Thanks for your response. The above code that I have supplied shows the actual working code for updating a Channel's Status. We can almost consider Status of a channel as a 9th field as you can update the fields and status all in one call and it inserts a channel entry in doing so. The question is, given the current code that I have, I wish to update the Metadata of a channel via WebWrite(or similar mechanism).This would not create a new entry to our channel but update the Metadata. Why would I want to do so you might ask? I would like to put some channel related information in the Metadata a bit like a status but I wish to have it at a channel level not at a feeds level.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 REST API 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by