pack more information into a single field

2 views (last 30 days)
Ismail Bera
Ismail Bera on 25 Feb 2024
Commented: Ismail Bera on 26 Feb 2024
Dear Christopher Stapels, @Christopher Stapels
In my experiment, in total I need to visualize 12 parameters out of 6 different sensors. The outputs of the sensors are as follows.
Sensor 1: one parameter
Sensor 2: one parameter
Sensor 3: one parameter
Sensor 4: three parameters
Sensor 5: four parameters
Sensor 6: two parameters
Is it possible to dedicate each sensor to a field? For example:
Field 1 - Sensor 1: so field 1 will only demonstrate that one parameter
Field 2 - Sensor 2: so field 2 will only demonstrate that one parameter
Field 3 - Sensor 3: so field 2 will only demonstrate that one parameter
Field 4 - Sensor 4: so field 2 will demonstrate that three parameters in one graph
Field 5 - Sensor 5: so field 2 will only demonstrate that four parameters in one graph
Field 6 - Sensor 6: so field 2 will only demonstrate that two parameters in one graph
How can I achieve this?
If possible is there any downside to this?
Additionally, as I saw from your previous response to someone else's question, you said a single field holds up to 255 characters. What does it mean? What does custom visualizations to unpack the field values mean?
Thank your for your interest.
  2 Comments
Walter Roberson
Walter Roberson on 25 Feb 2024
Is this a question about Simulink ?
How much data is required to store each of the parameters?
Ismail Bera
Ismail Bera on 25 Feb 2024
No, I want to do this in ThingSpeak.
I do not know how much data is required to store each of the parameters.

Sign in to comment.

Answers (1)

Christopher Stapels
Christopher Stapels on 26 Feb 2024
Fo the concepts, I really reccomend some time with the documentation.
I would suggest you use multiple channels, this will make your ThingSpeak workflow the most simple.
However, you can succeed using a single channel, but packing values as stated.
The downsides of packing values into fields are that the automatic field plots that come with the channel wont work, and that your process will probably be more britte or prone to breaking - since a change in one sensor may affect others that are packed with it.
A single field update can have up to 255 characters. That means that when you write to a field, you could write something like
https://api.thingspeak.com/update?api_key=xxxxxxxxxxxxxxxx&field1=123456789......(you can write up to 244 more characters here)...
So you can put multiple values with a seperator value like this
https://api.thingspeak.com/update?api_key=xxxxxxxxxxxxxxxx&field1=1234,43.2,245.321
Where the three values are 1234, 43.2, and 245.321
Now thingspeak field plots wont understand that as a number, so you will have to create custom MATLAB visualization to unpack.
If your visualization code, you need to start by getting the date. You would read string data, so use outputformat timetable.
myValues=thingSpeakRead(channel,...,'outputformat','timetable);
% MyValues.field1label = "1234, 43.2, and 245.321"
Now you need to split the data and turn it into numbers
theNumbersAsStrings=split(myValues,',');
theNumbers=str2double(theNumbersAsStrings);
...
% plot(theNumbers) ...and so on
Your actual code will vary depending on how you pack things in.
  1 Comment
Ismail Bera
Ismail Bera on 26 Feb 2024
Dear Christopher Stapels,
Thank you so much for your answer. I tried the first option, opening multiple channels for the same device. It works fine. I will also try the second option too.
Best regards...

Sign in to comment.

Categories

Find more on ThingSpeak in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!