Hi,
I am attempting to read the LPO from the Shinyei Dust Sensor on PIN01 of the APRIL board and then post it to our server - using the code below. However I’m not sure I am using the pulse counter correctly should I be also multiplying it by the milliseconds? Many thanks
const FIELD_COUNT = 1; // Number of fields in the stream
local fieldNames = [“Particles”]; // Exact names of each field
//-----------------------------------------------------------------------------------------
//-------------------
function get_date_string() {
local d = date(); // the time() function would return seconds since 1970.
return ( d["year"] + "/" + d["month"] + "/" + d["day"] + " " +
d["hour"] + ":" + d["min"] + ":" + d["sec"] + " UTC+1" );
}
//---------------------------------------------------------------
local counter = 0;
count <- hardware.pin1;
local time = 60 // time to log pulses for, double the time seems to be needed…
count.configure(PULSE_COUNTER, time);
local numPulses = 0;
function bigLoop() {
counter = counter +1;
local numPulses = count.read();
//local temp2 = mysensorBMP.read_temp_Celsius();
//local pressure = mysensorBMP.read_pressure_atm();
// Populate fieldData array with respective data values
local fieldData = [numPulses];
// Create a data string to send to the agent. Should be of the form:
//"fieldName0=fieldData0&fieldName1=fieldData1&fieldName2=fieldData2"
local data = "";
for (local i=0; i<FIELD_COUNT; i++)
{
data += fieldNames[i] + "=" + fieldData[i];
if (i < FIELD_COUNT - 1)
data += "&";
}
server.log("Sending Data!");
agent.send("postData", data);
server.log( "Particles: " + numPulses);
imp.wakeup(1, bigLoop); // sleep for xx seconds
}
bigLoop();