Clear channels using matlab commands | ThingSpeak API | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Clear channels using matlab commands
No permission to create posts
September 19, 2018
9:38 am
Avatar
teratoulis

Silver
Members
Forum Posts: 18
Member Since:
July 20, 2018
sp_UserOfflineSmall Offline

Hi again,

is there any way to clear the channels from matlab script? or a t least overwriting the previous ones

I would like to delete/ovewrite data after running the matlab script!

thanks again,

Nikolas

September 19, 2018
2:27 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 442
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Yes, definitely possible.
There is a REST API call for clear channel.
https://www.mathworks.com/help/thingspeak/clearchannel.html.
Be careful to use your USR API key with this call
You can use Webwrite(url, myOptions)
https://www.mathworks.com/help/matlab/ref/webwrite.html
but you will need to set weboptions to use the delete method.
myOptions=weboptions('RequestMethod,'delete')
https://www.mathworks.com/help/matlab/ref/weboptions.html
I don't have tested code for that method, because I didn't know there was an option for delete until I tired to answer your question. (thanks!)

Here is the probably more complex code I used last time I needed to do that:

rMessage=matlab.net.http.RequestMessage;
rMessage.Method= matlab.net.http.RequestMethod.DELETE;
uri='https://api.thingspeak.com/channels/CHID/feeds.json?api_key=XXXXXXXXXXXXXXXX';
%[response,completedrequest,history] = send(request,uri)
send(rMessage,uri)

September 24, 2018
6:37 am
Avatar
teratoulis

Silver
Members
Forum Posts: 18
Member Since:
July 20, 2018
sp_UserOfflineSmall Offline

thanks for the reply, I managed to clear one channel through POSTMAN as it described in:

https://www.mathworks.com/help/thingspeak/clearchannel.html.

However, I don't know how to do the same for mutiple channels!

for example if I have 50 channels how can I clear them all at once?

thanks again

Nikolas

September 24, 2018
8:20 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 442
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Though I have not done it myself, I know you can set up a suite of tests or commands to run in POSTMAN.

You could also write a MATLAB analysis script to do this programatically.
You could pre-program the array of channel specific commands, and them loop through them. You could put a bit of delay in the loop to give each one time to process, but not so much that your code times out.
something like ...
loop over i
url(i)=https://api.thingspeak.com/channels//feeds.
webwrite('url',options)
pause(0.05);
end
etc.
You could also store the channel list in another channel, and use a thingSpeakRead function to get the list and then loop over them.

We are definitely interested in improving the process for handling many channels. Can you tell us more about your use case and your workflow?
How often are you writing / creating and or deleting channels?
Are you clearing the channels yourself or do you want other users to be able to clear them?
Does a device need to be able to crate and clear multiple channels?
If you are using devices, what devices are you using?
And anything else you think is relevant.

September 25, 2018
11:07 am
Avatar
teratoulis

Silver
Members
Forum Posts: 18
Member Since:
July 20, 2018
sp_UserOfflineSmall Offline

hi again,

thanks for the detailed reply.

For my case, I am going to use around 50 channels with a couple of values in each of them (using tstamps).

I need to clear all of them at once every couple of min or hours in order to update the values uploaded to them.

It's like what I am doing in POSTMAN for one channel, to be able to do it for all of them at once.

I am going to clear the channels myself: Ideally I would like to integrate a piece of code in matlab that does this instead of using POSTMAN manually.

I hope that helps

thanks again for your reply,

looking forward to your suggestions

Nikolas

October 5, 2018
10:06 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 442
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

'I need to clear all of them at once every couple of min or hours in order to update the values uploaded to them."
Can you clarify why you need to do this? If you have less than 10 million points in a channel, you can continue to write, unless the timestamps are the same.
if you are only interested in the most recent data, you can just read the last value or set the days parameter to be 1 (assuming you only wanted one day of data, for example.)
Clearing is totally possible using the methods described above, but I'm not sure you need it.

October 8, 2018
11:53 am
Avatar
teratoulis

Silver
Members
Forum Posts: 18
Member Since:
July 20, 2018
sp_UserOfflineSmall Offline

thanks again for the reply,

my values are obviously much less , it's around 900 per iteration.

However, my problem is that if I don't clear the channel I get wrong values in the next iteration.

Probably it's because of the timestamps. Could you let me know which values should I put ? I don't really care about the time, I just want to get the 900 values after each iteration.

I use the timestamps because I don't know any other way to upload a whole vector through thing Speak.

thanks a lot

nikolas

here is the code, in case you wanna have a look:

data = xlsread('draft');

%user 35-required energy example
channelID_re35 = 578168;
writeKey_re35='AI51CJB121JIJX77';

data_35=data;
tStamps = [datetime('now')-minutes(899):minutes(1):datetime('now')]';

thingSpeakWrite(channelID_re35,data_35,'TimeStamp',tStamps,'WriteKey',writeKey_re35)

channelID_35 = 578168;
rk_re35='CRKOVW81DXRV6WOB';

Required_Energy_35= thingSpeakRead(channelID_re35,'Fields',[1],'ReadKey',rk_re35,'NumPoints',900,'OutputFormat','table');

October 10, 2018
11:11 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 442
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

900 minutes is about 15 hours so things might be overlapping.
Given your method, I think you will need timestamps.

Here is one suggestion - use 'yesterday':

tStamps = [datetime('yesterday')-minutes(899):minutes(1):datetime('yesterday')]';

or the distant past:
tStamps = [datetime('now')-minutes(899)-days(100):minutes(1):datetime('now')-days(100)]';

But you might still have overlapping points if you publish again within 15 hours..

ThingSpeak does 1s resolution. How about:

tStamps = [datetime('yesterday')-seconds(899):seconds(1):datetime('yesterday')]';

Then you only have to wait 900s, or 15 minutes to post again.

Be careful if you use the distant past, because then your last command (thingSpeakRead) wont read the new data that you just posted to a long time ago 🙂

October 12, 2018
10:04 am
Avatar
teratoulis

Silver
Members
Forum Posts: 18
Member Since:
July 20, 2018
sp_UserOfflineSmall Offline

thanks you very much for the detailed reply,

I found out that since Thing Speak does 1 second resolution, If I need to send 900 values I need to wait 900 sec and so on..

I think for what I need it's alright but I wonder if you wanna send 900 values every 10 seconds ? probably it's not working as you have overlapping

I guess it would be possible if the resolution could be smaller (like 1ms for example).

Anyway, thanks again for the reply for what I need is fine!

Nikolas

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
37 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

Williampes, esmeraldagx11, lilacs16, loriexo60, ThomasHut, WernerDernnida

Administrators: Hans: 387, lee: 457