Parsing data from the URL in MATLAB Analysis and Visualizations | ThingSpeak Apps | 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
Parsing data from the URL in MATLAB Analysis and Visualizations
No permission to create posts
October 5, 2015
11:52 pm
Avatar
Matthew Driver

Silver
Members
Forum Posts: 6
Member Since:
October 5, 2015
sp_UserOfflineSmall Offline

Hello All,

I am collecting a small amount of data (50 records) from many (>100) moisture sensors and storing it all in one channel. This is working well.

I then use one MATLAB Visualization to create a customised visualization about each sensor.

As an example the first line of the MATLAB code is:
SensorID = 'ID1234'; % change this Sensor ID value only

The problem is I need to manually change the SensorID in code to view the visualization for that sensor.

QUESTION:
Is there any way to include in the URL the sensor ID and then grab this in the MATLAB code?

Example URL:
https://thingspeak.com/apps/matlab_visualizations/26703?SensorID=ID7654 (or some other format)

Code becomes:
SensorID = GetURLdata('SensorID');

This would make the MATLAB Analysis and Visualizations code far more flexible as it would allow inputs from the user via the URL.

An external website could then embed multiple visualizations on page that all based on the same visualization code.

I'm guessing this feature doesn't yet exist (I'd love to be proved wrong).

Does anyone know of another way to provide inputs to the MATLAB code via the URL?

I could modify data in another channel (eg. set the Sensor ID to be viewed) then check for it in the visualization code but this is not a very scalable solution when multiple people view the visualization at the same time.

Any ideas?

Cheers,

Matthew Driver

October 6, 2015
10:45 am
Avatar
hans

MathWorks
Members
Forum Posts: 4
Member Since:
January 19, 2011
sp_UserOfflineSmall Offline

Matthew Driver,

Thank you for posting your question on the ThingSpeak forum.

The functionality requested in your post is not currently available in the form described.

To better understand your request, can you describe your setup in a little more detail? For example, what convention are you using to differentiate data points from various sensors in a single Channel?

MATLAB provides a function 'subplot' to create multiple axes in a figure. The 'subplot' function works with static MATLAB plots and does not work with dynamic plotting functions (thingSpeakPlot ect..). More information on the 'subplot' function is available on the following Documentation center page:
http://www.mathworks.com/help/matlab/ref/subplot.html?searchHighlight=subplot

It is also possible to plot multiple series in a single MATLAB plot. The syntax and examples for how to do so are available in the following Documentation center page:
http://www.mathworks.com/help/matlab/ref/plot.html?searchHighlight=plot

October 13, 2015
4:20 am
Avatar
Matthew Driver

Silver
Members
Forum Posts: 6
Member Since:
October 5, 2015
sp_UserOfflineSmall Offline

Hello,

Thank you for responding. I should have checked back sooner:-).

My channel has fields at:
datetime
SensorID (alphanumeric) Examples: Oats1, Oats2, Onions
Layer1, value options: 'R', 'G', 'B'
Layer2 as above
Layer3 as above
Layer4 as above

My visualisation code filters out all but one SensorID and does some coloured rectangle drawing to get the output I need.

At the moment I'm making one visualisation app per SensorID but this is not scalable.

Please see the examples:
https://thingspeak.com/apps/matlab_visualizations/27998
https://thingspeak.com/apps/matlab_visualizations/27999
https://thingspeak.com/apps/matlab_visualizations/28000

So my problem is not how to plot. I've got that sorted.

My problem is how to make one visualisation app reusable based on the SensorID as an input?

This same concept could be used for any kind of data.

Example - IoT temperature sensors:
I plan to build a large number of temperature data logging devices (using 1-wire temperature sensor and an ESP8266 wifi module.
Each temperature sensor has an 64bit ID.

Proposed ThingSpeak solution:
Code all the micro-controllers identically with the same thingspeak write key.
Store the data for all sensors in a single channel.
Fields: datetime, SensorID, temperature

Create a single visualisation that has the SensorID as an input.
Embed on a web page multiple lines like this:
[iframe src="https://thingspeak.com/apps/matlab_visualizations/27986?SesnorID=A5D4c4EE62" width="100%" height="220"]
[iframe src="https://thingspeak.com/apps/matlab_visualizations/27986?SesnorID=EE62A5D4c4" width="100%" height="220"]
etc.

End result you have a data storage and visualisation system for any number of temperature sensors without requiring the micro controller to have customised writekeys. You only need to configure one thingspeak channel and one visualisation app.

All the above solution is missing is the ability to provide an input to visualisation apps via the URL.

I hope I have explained myself well enough for other to see the power of a feature like this.

Cheers,

Matthew.

Cheers,

Matthew Driver

October 14, 2015
12:10 am
Avatar
rw950431

Top
Members
Forum Posts: 271
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

Matthew/
I wonder if the URL query string is available in the thingspeak MATLAB via getenv() ?

This stack overflow question lists how to enumerate the environment variables https://stackoverflow.com/questions/20004955/list-all-environment-variables-in-matlab

But I'm too much of a MATLAB newbie to know how to return any such list..

October 14, 2015
7:44 pm
Avatar
Matthew Driver

Silver
Members
Forum Posts: 6
Member Since:
October 5, 2015
sp_UserOfflineSmall Offline

Thanks rw950431,

Interesting idea to use getenv().
I have tried getenv() inside of a visualisation and this the available content:

code used:
map = java.lang.System.getenv();
disp(map);

The output is below but unfortunately it doesn't appear to contain the URL query string.

The query string was: https://thingspeak.com/apps/matlab_visualizations/28323/edit

Cheers,

Matthew.

Output:
{MATLAB_CONNECTOR_AUTOSTART_ENABLED=false, AUTOMOUNT_MAP=, SHLVL=2, MATLAB_PREFDIR=/tmp/matlabpref, OSG_LD_LIBRARY_PATH=/opt/mlsedu/matlab/R2015b/sys/openscenegraph/lib/glnxa64, XFILESEARCHPATH=/opt/mlsedu/matlab/R2015b/sys/java/jre/glnxa64/jre/lib/locale/%L/%T/%N%S::/usr/dt/app-defaults/%L/Dt, PROXY_SERVER_PORT=3128, MATLABPATH=/opt/mlsedu/matlab/R2015b/toolbox/local, DEBIAN_FRONTEND=noninteractive, LC_NUMERIC=C, GFORTRAN_STDOUT_UNIT=-1, MAIL=/var/mail/mlsedu, HOSTNAME=6c3e2f72fd93, MLSEDU_ROOT=/opt/mlsedu/mdcsserver/latest, PWD=/opt/mlsedu/mdcsserver/latest/m, MKL_DOMAIN_NUM_THREADS=, LOGNAME=mlsedu, KMP_HANDLE_SIGNALS=0, TOOLBOX=/opt/mlsedu/matlab/R2015b/toolbox, NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat, LD_LIBRARY_PATH=/opt/mlsedu/matlab/R2015b/sys/opengl/lib/glnxa64:/opt/mlsedu/matlab/R2015b/sys/os/glnxa64:/opt/mlsedu/matlab/R2015b/bin/glnxa64/mvm:/opt/mlsedu/matlab/R2015b/bin/glnxa64:/opt/mlsedu/matlab/R2015b/extern/lib/glnxa64:/opt/mlsedu/matlab/R2015b/runtime/glnxa64:/opt/mlsedu/matlab/R2015b/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/opt/mlsedu/matlab/R2015b/sys/java/jre/glnxa64/jre/lib/amd64/server, KMP_STACKSIZE=512k, OLDPWD=/opt/mlsedu/matlab/R2015b, SHELL=/bin/bash, MATLAB=/opt/mlsedu/matlab/R2015b, MW_CRASH_MODE=exit, LANGUAGE=en_US:en, BASEMATLABPATH=, PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games, GFORTRAN_STDIN_UNIT=-1, PROXY_SERVER=ec2-50-17-204-167.compute-1.amazonaws.com, HOST_IP_ADDRESS=10.203.202.175, WORKER_GATEWAY_WEB_SERVER_PUBLIC_PORT=10000, LM_LICENSE_FILE=13501@motw-flexlm-15b-a.wsroute.mathworks.com:13501@motw-flexlm-15b-d.wsroute.mathworks.com, DISPLAY=:1.0, USER=mlsedu, HOME=/tmp/matlabpref, ARCH=glnxa64, DOCKER_CONTAINER_NAME=trusting_wilson_0, KMP_BLOCKTIME=1, WORKER_CONFIG=/tmp/worker.properties, GFORTRAN_STDERR_UNIT=-1, MKL_NUM_THREADS=, INITRD=no, HTTP_MATLAB_CLIENT_GATEWAY_PUBLIC_PORT=8000, LANG=en_US.UTF-8}

October 15, 2015
12:14 am
Avatar
rw950431

Top
Members
Forum Posts: 271
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

Shame about that... Did you try to append some parameters just to be sure? I notice you are using the edit URL rather than the straight viewer- wonder if that makes any difference?

Were you were able to see the result of "disp(map)" on the thingspeak console when you called the URL? (Maybe thats why you used the edit URL) Useful to know for debugging.

October 15, 2015
2:58 am
Avatar
Matthew Driver

Silver
Members
Forum Posts: 6
Member Since:
October 5, 2015
sp_UserOfflineSmall Offline

Hi
Hi rw950431,

I have rewritten the code so I can include the text in an actual visualisation.

Please visit this URL to see the output:
https://thingspeak.com/apps/matlab_visualizations/28323?xxx=AAAAAAAAAAAAAAAAAAAAAAAAAAAAA

Result:
Unfortunately the extra parameters are not present.

Here is my visualisation code (if your interested). It's not very elegant but does the job for this test.

map = java.lang.System.getenv();
figure('position', [0, 0, 1000, 500])
drawtext = char(map);
num = 100;
textlength = length(drawtext);
numlines = ceil(textlength/num);
for k=1:numlines
frompos = 1+(k-1)*num;
topos = num+(k-1)*num;
if (topos>textlength)
topos=textlength;
end
drawtext_part = drawtext(frompos:topos);
text('units','pixels','position',[10 400-k*12],'fontsize',10,'string',drawtext_part);
end

Cheers,

Matthew.

October 15, 2015
7:30 pm
Avatar
rw950431

Top
Members
Forum Posts: 271
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

Awesome! Thanks for the code.

Wonder if theres any way to use a 3rd-party webservice as a wrapper.. then your visualisation would call an external URL which does the filtering, supplies the filtered data via webread() and returns the image .. not sure if its possible, just thinking out loud..

October 15, 2015
11:23 pm
Avatar
Matthew Driver

Silver
Members
Forum Posts: 6
Member Since:
October 5, 2015
sp_UserOfflineSmall Offline

Hi rw950431,

The trouble with any kind of solution like:
We first store the input parameter (for example into another matlab channel) and then the visualisation code goes off to find that value

If multiple hits to the visualisation happen at the same time the results returned may not be what are expected.

It all gets rather messy.

I'm starting to the think I need to drop using the matlab visualisation solution and rewrite the visualisation as a javascript plugin. This will be a pain but at least I'll have access to the URL parameters.

This is a real shame as the matlab visualisation code is very powerful (and I've already written it (except for URL input parameters).

Thanks for your thoughts.

Cheers,

Matthew

October 18, 2015
7:32 pm
Avatar
rw950431

Top
Members
Forum Posts: 271
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

After thinking about it some more I came to much the same conclusion.. Simpler to use one of the javascript graphing libs to do it all in-browser.

Perhaps the thingspeak guys will take it as a feature request?

October 20, 2015
4:56 am
Avatar
Matthew Driver

Silver
Members
Forum Posts: 6
Member Since:
October 5, 2015
sp_UserOfflineSmall Offline

Hi rw950431,

I've just finished porting my MatLab visualisation to a javascript plugin. It still hosted with ThingSpeak as a plugin.

As it's not a tradition chart, I just coded it using javascript canvas drawing functions.

I used jsbin.com as my development editor. The best feature is it redraws in real time as you code and displays syntax errors in a useful way.
http://jsbin.com/lelode/edit?html,css,js,output

Examples:
The URL for the new plugin is in the format:
https://thingspeak.com/apps/plugins/29169?SensorID=oats1
https://thingspeak.com/apps/plugins/29169?SensorID=Oats2
https://thingspeak.com/apps/plugins/29169?SensorID=mustard

You can see I have my SensorID input parameter in the URL.

Let's hope URL input parameters are added to thingspeak in the future.

Cheers,

Matthew.

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
31 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:

JudestAboth, concettazx4, lyndarf60, caseybo16, iodiree, emiliacz4

Administrators: Hans: 387, lee: 457