Clear Filters
Clear Filters

Webwrite to metadata Thingspeak Channel

36 views (last 30 days)
Marc Hanssens
Marc Hanssens on 26 Jun 2024 at 4:25
Commented: Marc Hanssens on 9 Jul 2024 at 4:53
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 Comment
Marc Hanssens
Marc Hanssens on 9 Jul 2024 at 4:53
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);

Sign in to comment.

Answers (1)

Piyush Kumar
Piyush Kumar on 26 Jun 2024 at 5:47
"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 Comment
Marc Hanssens
Marc Hanssens on 27 Jun 2024 at 0:26
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.

Sign in to comment.

Categories

Find more on Configure Accounts and Channels in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!