Skip to content

Instantly share code, notes, and snippets.

@cat-haines
Last active August 29, 2015 14:16
Show Gist options
  • Save cat-haines/65316671dbc7f0e8f0ad to your computer and use it in GitHub Desktop.
Save cat-haines/65316671dbc7f0e8f0ad to your computer and use it in GitHub Desktop.
device.on("data", function(data) {
server.log(http.jsonencode(data));
});
// https://github.com/electricimp/APDS9007
#require "APDS9007.class.nut:1.0"
// https://github.com/electricimp/LPS25H
#require "LPS25H.class.nut:1.0"
// https://github.com/electricimp/Si702x
#require "SI702x.class.nut:0.1"
// Ambient Light Sensor
als_en <- hardware.pin7; // (active high)
als_en.configure(DIGITAL_OUT, 0);
als_out <- hardware.pin5;
als_out.configure(ANALOG_IN);
lightSensor <- APDS9007(als_out, 47000.0, als_en);
// Air Pressure and Temp + Humid Sensor
i2c <- hardware.i2c89;
i2c.configure(CLOCK_SPEED_400_KHZ);
pressureSensor <- LPS25H(i2c); // air pressure
tempHumidSensor <- Si702x(i2c); // temp and humid
function poll() {
local temp = tempHumidSensor.readTemp(); // celsius
local humid = tempHumidSensor.readHumidity(); // relative humidity (%)
local light = lightSensor.read(); // lux
// reading pressure takes a few seconds, so it's an
// asynchronous call and we send the data upon completion
pressureSensor.read(function(pressure) {
agent.send("data", {
temp = temp,
humid = humid,
light = light,
pressure = pressure
});
imp.wakeup(10, poll);
});
}
/* RUNTIME START ------------------------------------------------------------ */
server.log("SW: "+imp.getsoftwareversion());
server.log("Memory Free: "+imp.getmemoryfree());
imp.enableblinkup(true);
poll();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment