Event log to file on web server

I have tried different variants to log imp registered events on web server located text file. For example, register on file passing cars or people.
“onrequest” response cannot be applied - passing are not determined.
Looping (via wakeup) generate to much information on textile.
I have success pervious with Plenner but cannot get result through Agent.
Help!

I have a hard time to understand what you mean.
Can you share your planner solution?

@DolfTraanberg , yes, a bit mess.
It is simple: photosensor or PIR sensor trigger event. I’m interested to register this event trigger on the file on web server - sensor number and timestamp.

ah, ok
look here: http://devwiki.electricimp.com/doku.php?id=electricimpapi:server:setpermanentvalues
you have to clean up that table regularly, because you don’t have indefinite storage space
If you want to do this in the agent (which is not yet possible), then you first send that table to the device and then use server.setpermanentvalues()

@DolfTraanberg
Hmmm…it is for server. I want to store on the file un my web server.
Here is my Agent code:
device.on(“set_is”, function(coord) {
server.log(“C:”+ coord)
http.post(“http://xxxxxxxxx/impweb.php”,
{ “Content-Type”:“application/x-www-form-urlencoded”},
http.urlencode(coord)).sendsync();
server.log(“C1:”+ coord)
});

Here is a server log:
Sat Jun 15 2013 17:24:43 GMT+0300 (EEST): C:0.4
Sat Jun 15 2013 17:24:43 GMT+0300 (EEST): bad parameters to http.urlencode(table)
Sat Jun 15 2013 17:24:43 GMT+0300 (EEST): at unknown:22

This “0.4” (or other value) I need to store on .txt file on web server via very common php script:

<?php if(isset($_POST['value'])) { $fd = fopen('impdata.txt', 'a'); if(flock($fd, LOCK_EX)) { fwrite($fd, $_POST['target'] . ' ' . $_POST['channel'] . ' ' . gmdate('Y-m-d H:i:s') . ' ' . number_format($_POST['value'], 2) . "C\ "); fflush($fd); flock($fd, LOCK_UN); } fclose($fd); } ?>

What mean “bad parameters to http.urlencode(table)”?

i’m not a web programmer, but “bad parameters to http.urlencode(table)” means you have one or more mistakes on line 22. for instance, http.urlencode(coord)).sendsync();` is not correct

Mistake here:http://devwiki.electricimp.com/doku.php?id=electricimpapi:http:urlencode?

device.on(“data”, function(s) {
http.post(“http://my.web.service/imp.cgi”,
{ “Content-Type”: “application/x-www-form-urlencoded” },
http.urlencode(s)).sendsync();
});

As @DolfTraanberg pointed out, urlencode expects a table, not a single variable.

@PeterAp: the example you pulled from the devwiki says “here’s some agent code that takes a table of data from an imp, and encodes it for sending as if POSTed by an HTML form”

You can declare the table inline so it’s not a big change:

device.on("data", function(s) { http.post("http://my.web.service/imp.cgi", { "Content-Type": "application/x-www-form-urlencoded" }, http.urlencode({ coord = s })).sendsync(); });

@beardedinventor , @DolfTraanberg,
Works! Thanks a lot!
Good lesson.

Final Agent code:
device.on(“set_is”, function(s) {
local resp = http.post(“http://xxxxxxxxxx/impweb.php”,
{“Content-Type”:“application/x-www-form-urlencoded”},
http.urlencode({coord = s})).sendsync();
server.log(resp.statuscode);
server.log(resp.body);
});