Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified java/JavaSmap_0.1.jar
100644 → 100755
Binary file not shown.
4 changes: 4 additions & 0 deletions matlab/PSTtoUTC.m
Original file line number Diff line number Diff line change
@@ -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;
31 changes: 31 additions & 0 deletions matlab/README.md
Original file line number Diff line number Diff line change
@@ -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


54 changes: 54 additions & 0 deletions matlab/RunMatlabSmap.m
Original file line number Diff line number Diff line change
@@ -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')
4 changes: 4 additions & 0 deletions matlab/UTCtoPST.m
Original file line number Diff line number Diff line change
@@ -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;