Send more than one value in Field 1. Buffer of values.

조회 수: 4 (최근 30일)
Paula
Paula 2024년 4월 28일
댓글: Christopher Stapels 2024년 10월 7일
Hello! I would like to know if any of you know how I could send a list of values all as field1.
From postman it would look something like this:
The data is sent because I can see it by downloading the excel but not graphed. Do you know if it is possible to send them all together and graph them?
Thanks
  댓글 수: 4
Christopher Stapels
Christopher Stapels 2024년 4월 30일
Can you show the data? I dont want you to share your API key if possible.
Paula
Paula 2024년 5월 1일
Hi, this are the values that I send to thigspeak
And these are the values that arrive at the platform (I can see from the downloadable excel):
Field1 represents the abscissa axis and field2 the ordinate axis, something like this.
with the matlab code I provide only the first value of each field is represented and not all the characters.
Thanks

댓글을 달려면 로그인하십시오.

답변 (2개)

Christopher Stapels
Christopher Stapels 2024년 4월 30일
편집: Christopher Stapels 2024년 4월 30일
ThingSpeak cannot parse the data you have in your field since it has string characters in it. MATLAB can though.
First you need to tell ThingSpeak you want to read string data. The easiest way to do this is with a timetable.
data = thingSpeakRead(readChannelID, 'Fields', [1,2], 'NumPoints', 70, 'ReadKey', readAPIKey,'outputformat','timetable');
Now you will need to split you data. The format in your channel changes wildly for the most recent points. I would probably reconsider the current format you are writing in.
But, lets say you want to plot the most recent point.
splitData=split(data.FieldLabel1(end),newline);
myNums=str2double(splitData);
plot(myNums);

Christopher Stapels
Christopher Stapels 2024년 5월 1일
편집: Christopher Stapels 2024년 5월 1일
We definitely need to change he way you are sending data to ThingSpeak. (I would clear the data and start over)
Do you intend to have a large number of plots, such as one per feed entry?
Otherwise you should send the data as 70 individual points. Then you will have one live graph.
i.e.
https://api.thingspeak.com/update?api_key=xxxxxxxxxxxxxxxx&field1=<X1>&field2=<y1>
wait
https://api.thingspeak.com/update?api_key=xxxxxxxxxxxxxxxx&field1=<X2>&field2=<y2>
...
or using thingSpeakWrite and a table. (see the doc) thingSpeakWrite
If you need to have a different x axis, I would reccomend you use a custom MATLAB visualization.
In the case where you want each feed point to be a seperate plot:
If field1 is the x data and field2 is the y data, you will need to compress the data further.
In one point you have 484.00 by 0.,73 (im not sure why you are using comma and decimal as a seperator.)
The x data has 6 characters, so if you write them with a seperator, they will take up (6+1)*70 characters, which is more than the 255 you can fit in one field. In this case you could reduce the accuracy of the data(to reduce the number of characters), or reduce the number of data points from 70 , or use multiple feeds to hold the whole dataset. If you take this route, I would reccoend a different data seperator, perhaps a '\' character.
  댓글 수: 4
Paula
Paula 2024년 5월 4일
편집: Paula 2024년 5월 4일
Hello,
After several unsuccessful attempts to send data with different separators. I finally seem to be getting closer to my goal thanks to your help.
I only have one problem.
The graph should be plotted with the values of field2 on the ordinate axis and field1 on the abscissa axis.
Using the last one you provided and entering the field2, I only get the field2 on the ordinate axis:
readChannelID = 2515826;
% TODO - Replace the [] with the Read API Key:
readAPIKey = 'XXXXXXXXXXXXXXXXXXXX';
%% Read Data %%
data = thingSpeakRead(readChannelID, 'Fields', [1,2], 'NumPoints', 70, 'ReadKey', readAPIKey,'outputformat','timetable');
%% Visualize Data %%
% Ordenar los datos en función de la coordenada en el eje X
splitData=split(data.FieldLabel2(end),newline);
myNums=str2double(splitData);
plot(myNums);
Do you know what change I have to make to represent field1 on the ordinate axis?
Thank you very much
Christopher Stapels
Christopher Stapels 2024년 10월 7일
plot(data.(1),myNums);
or
plot(data.<field1label>,myNums);

댓글을 달려면 로그인하십시오.

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

Help CenterFile Exchange에서 ThingSpeak에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by