looks fine to me except for the “<-” inside the if statement. I would change it to…
`button <- hardware.pin1;
job1 <- “”;
function buttonPress() {
local state = button.read();
imp.sleep(0.05);
if (state == 1) {
// when the button is released
job1 =“working”;
} else {
job1 = “off the clock”;
}
agent.send(“job1”, job1);
}
button.configure(DIGITAL_IN_PULLUP, buttonPress);`
Your agent code looks correct to my eye - assuming you would put your proper and correct path in ‘url’
I don’t know very much about PHP. From some other example I put this together and it has been working.
`<?php
/* sript to recieve the JSON data from the agent
agent sends…
{ “meterdata”: { “I”: 2.72236, “unixtime”: 1385870780, “GMT”: “2013-12-01T04:06:21”, “V”: 122.664, “PF”: 0.917173, “W”: 306.4, “Ipeak”: 2.37886 } }
php input receives
{ “meterdata”: { “I”: 2.72236, “unixtime”: 1385870780, “GMT”: “2013-12-01T04:06:21”, “V”: 122.664, “PF”: 0.917173, “W”: 306.4, “Ipeak”: 2.37886 } }
in the electric imp Agent the table is created like this; the values of this table are modified before sending each point
//{ “meterdata”: { “I”: 2.72236, “unixtime”: 1385870780, “GMT”: “2013-12-01T04:06:21”, “V”: 122.664, “PF”: 0.917173, “W”: 306.4, “Ipeak”: 2.37886 } }
*/
$logfilename = “Sensorlogs/” . “logfilename.csv”; //. $dArray[‘meterdata’][‘flname’]; //The filename to log to
$dArray = json_decode(file_get_contents(‘php://input’),true);//php function json to php array
$HZ = $dArray[‘meterdata’][‘HZ’];//RMS Voltage
$V = $dArray[‘meterdata’][‘V’];//RMS Voltage
$I = $dArray[‘meterdata’][‘I’];//RMS Current
$Ipeak = $dArray[‘meterdata’][‘Ipeak’];//peak DC level at really high (?.? khz) sample speed
$time = $dArray[‘meterdata’][‘GMT’]; //Time and date Agent
$timestamp = $dArray[‘meterdata’][‘unixtime’]; //Linux timestamp from Device
$W = $dArray[‘meterdata’][‘W’]; //The active power in Watts
$VA = $dArray[‘meterdata’][‘VA’]; //The apparant power
$PF = $dArray[‘meterdata’][‘PF’]; //Power Factor
// see http://php.net/manual/en/timezones.php for supported timezones
date_default_timezone_set(“America/Chicago”); //php handles timezones and daylight savings time
$dateTime = date(‘Y-m-d H:i:s’); //‘Y-m-d H:i:s’
$fa = fopen($logfilename, ‘a’); //other is ‘w’ for write
if(flock($fa, LOCK_EX)) {
//fwrite($fa, file_get_contents(‘php://input’) . “
”); //to see the raw message
fwrite($fa, $dateTime . “,” . $timestamp. “,” . ($time) ."," . ($V) ."," . ($I) . “,” . $W . “,” . $Ipeak."," . $PF ."
");
fflush($fa);
flock($fa, LOCK_UN);
}
?>`
In your question you state that you are trying to post some data onto a web page. From what i know, this is not possible. The web page (browser) must initiate a request for information. The web page would do a request to the agent. The agent can respond right away with information on hand or it could send something to the device and wait for a response but of course this causes added lag. You should only need php for logging - and I see that is what you are doing.