diff --git a/java/JavaSmap_0.1.jar b/java/JavaSmap_0.1.jar old mode 100644 new mode 100755 index 4dba904..a714a5a Binary files a/java/JavaSmap_0.1.jar and b/java/JavaSmap_0.1.jar differ diff --git a/matlab/PSTtoUTC.m b/matlab/PSTtoUTC.m new file mode 100644 index 0000000..33def72 --- /dev/null +++ b/matlab/PSTtoUTC.m @@ -0,0 +1,4 @@ +function timearray = PSTtoUTC(timearray) +% Take PST time in Matlab to UTC time in Java. + +timearray = (timearray +1/24*8 - datenum(1970,1,1))*86400*1000; diff --git a/matlab/README.md b/matlab/README.md new file mode 100644 index 0000000..886abb7 --- /dev/null +++ b/matlab/README.md @@ -0,0 +1,31 @@ +How to set up MatlabSmap. + +(1) Unzip MatlabSmap.zip folder and extract from the java folder: +JavaSmap_0.1.jar + +and from the java/lib folder: +javax.json-1.0-b06.jar + +(2) Add jar paths to Matlab java path. + +(Option 1) Add dynamically. For example, include in your m-file the following code: +javaaddpath('/Users/skoehler/Documents/SDB_MPC/smap/Matlab/JavaSmap_0.1.jar') +javaaddpath('/Users/skoehler/Documents/SDB_MPC/smap/java/JavaSmap/lib/javax.json-1.0-b06.jar') +javaaddpath('/Users/skoehler/Documents/SDB_MPC/smap/java/JavaSmap/lib/json-simple-1.1.1.jar') + +(Option 2) To add statically, find and edit the following file to include those three jar paths. +$MATLAB\toolbox\local\classpath.txt + +For more information, see: http://www.mathworks.com/matlabcentral/answers/96993-how-can-i-use-a-java-class-from-a-jar-file-in-matlab + +Check java path by typing: + + >> javaclasspath + +(3) Download JSONLab. Add to Matlab path (e.g. use Set Path button or addpath()) +http://www.mathworks.com/matlabcentral/fileexchange/33381-jsonlab--a-toolbox-to-encode-decode-json-files-in-matlab-octave + +For a good review of using JSON in Matlab, see: +http://undocumentedmatlab.com/blog/json-matlab-integration + + diff --git a/matlab/RunMatlabSmap.m b/matlab/RunMatlabSmap.m new file mode 100644 index 0000000..9c06740 --- /dev/null +++ b/matlab/RunMatlabSmap.m @@ -0,0 +1,54 @@ +%% RunMatlabSmap.m +% Use JavaSmap to collect data from sMap. + +close all +clear all +clear java + +disp('Please verify that you set the correct paths in MatlabSmap.m at line 11, 15, 16 and 17') + +% jsonlab dynamic link if not set statically: +% addpath('C:\Users\Robin\Documents\MATLAB\DownloadedFun\JsonLab\jsonlab') +% If commented, check the following paths are statically added to +% classpath.txt. Otherwise, uncomment and dynamically add jars to Java +% path. Check path with javaclasspath. +% javaaddpath('C:\Users\Robin\Desktop\java\JavaSmap_0.1.jar') +% javaaddpath('C:\Users\Robin\Desktop\java\lib\javax.json-1.0-b06.jar') +% javaaddpath('C:\Users\Robin\Desktop\java\lib\json-simple-1.1.1.jar') +%javaclasspath + +%% Query Set Up +archiverUrl = 'http://new.openbms.org/backend/api/query'; +js = JavaSmap(archiverUrl); +uuid_list = java.util.ArrayList; + +%% Query Time +% % Option 1: choose a time frame that ends at the current time +% Helpful units in Java time +one_minute = 1000*60; +one_hour = one_minute*60; +one_day = 24*one_hour; +one_week = 7*one_day; +% endtime = java.lang.System.currentTimeMillis(); +% start = endtime - one_day; + +% Option 2: Choose specific dates +start = PSTtoUTC(datenum(2014,12,3,0,0,0)); +endtime = PSTtoUTC(datenum(2014,12,4,0,0,0)); + +%% Specify your uuid here (you can find the uuid at http://new.openbms.org/plot/) +my_uuid = '395005af-a42c-587f-9c46-860f3061ef0d'; +uuid_list.add(my_uuid); +result = js.data_uuid(uuid_list, start, endtime, int64(100000), int64(size(uuid_list))); + +%% Postprocess +java.lang.System.out.println(result) +data = loadjson(char(result.toString())); +timestamp = data{1,1}.Readings(:,1); +% Convert from Java (UNIX) time to Matlab time, and from UTC to PST +timestamp = timestamp/86400/1000 + datenum(1970,1,1) - 1/24*8; +datastamp = data{1}.Readings(:,2); + +%% Plot +plot(timestamp,(datastamp-32)*5/9) +datetick('x') \ No newline at end of file diff --git a/matlab/UTCtoPST.m b/matlab/UTCtoPST.m new file mode 100644 index 0000000..79f0c07 --- /dev/null +++ b/matlab/UTCtoPST.m @@ -0,0 +1,4 @@ +function timearray = UTCtoPST(timearray) +% Take UTC time from Java and turns into PST time in Matlab. + +timearray = timearray/86400/1000 + datenum(1970,1,1) - 1/24*8; \ No newline at end of file