does the emoncms api provide a mechanism for specifying the time at which data were collected?
i understand that one can upload data to emoncms like this:
https://hostname/api/post?apikey=TOKEN&json={var1:200.2,var2:200,var3:100}
i would like to buffer data at my client, then upload periodically to emoncms, so i would like to associate a timestamp with the data. for example, i imagine something like this:
https://hostname/api/post?apikey=TOKEN&json={timestamp:NNNNNNNN,var1:200.2,var2:200,var3:100}
where NNNNNNNN is the unix epoch or a formatted UTC time.
does the emoncms provide for this? or does it only associate the timestamp when it receives data?
Re: how to upload timestamped data to emoncms?
in Controllers/api_controller there is code that checks for timestamp if sent by client. so it looks like this is how to do it:
https://hostname/api/post?apikey=TOKEN&time:NNNNNNNN&json={var1:200.2,var2:100}
do not put the timestamp in the json data - it will be treated as an input.
Re: how to upload timestamped data to emoncms?
Thanks - I needed to upload data with an 'earlier' timestamp too and this was a good pointer.
Note there's a small typo above. It should read: time=NNNNNNNN
In Perl it looks something like this:
#!/usr/bin/perl -w
use strict;
use Date::Parse;
use LWP::UserAgent;
my $emon_ua = LWP::UserAgent->new;
my $timestamp = str2time("22/feb/2012 16:00");
my $r1 = 3045;
my $key = "your_key_here";
my $emon_url = "http://localhost/emoncms3/api/post?apikey=$key\&time=$timestamp\&json={meter1:$r1}";
my $emon_response = $emon_ua->get($emon_url);
if ($emon_response->is_error) {
die $emon_response->status_line;
}
And to check it worked:
mysql> select * from input;
+----+--------+-------------+-------------+---------------------+---------+--------+
| id | userid | name | processList | time | value | status |
+----+--------+-------------+-------------+---------------------+---------+--------+
| 1 | 2 | ledcount | 1:1 | 2012-02-23 15:05:32 | 975537 | 0 |
| 2 | 2 | power | 1:2,5:3 | 2012-02-23 15:05:48 | 191 | 0 |
| 3 | 2 | temperature | 1:4 | 2012-02-23 15:05:48 | 22.3 | 0 |
| 4 | 2 | apt-3-watts | 1:5,5:6 | 2012-02-23 15:05:52 | 0 | 0 |
| 5 | 2 | apt-6-watts | 1:7,5:8 | 2012-02-23 15:05:52 | 1970 | 0 |
| 6 | 2 | apt-9-watts | 1:9,5:10 | 2012-02-23 15:05:52 | 456 | 0 |
| 7 | 2 | EDS0066temp | 1:11 | 2012-02-23 15:05:01 | 24.1875 | 0 |
| 8 | 2 | meter1 | 1:12 | 2012-02-22 16:00:00 | 3045 | 0 |
+----+--------+-------------+-------------+---------------------+---------+--------+
8 rows in set (0.00 sec)
mysql>