Example #1
0
void loop() {
  unsigned long currentTime = Time.now();
  //TODO: if targets -1, don't do any control

  //Request time synchronization from the Particle Cloud every 24 hours
  if (millis() - lastTimeSync > ONE_DAY_MILLIS) {
    Particle.syncTime();
    lastTimeSync = millis();
  }

  //Update time zone at DSTJumpHour incase DST is now in effect
  if(Time.hour(currentTime) == DSTJumpHour && Time.minute(currentTime) == 0) {
    Time.zone(isDST(Time.day(currentTime), Time.month(currentTime), Time.weekday(currentTime), preferences.DSTRule) ? preferences.timeZone + 1 : preferences.timeZone);
  }

  //Record data from sensors every minute
  if(millis() - lastDataSync > dataSyncFrequency) {
    temperature = tempHumidSensor.readTemperature();
    humidity = tempHumidSensor.readHumidity();
    light = lightSensor.getFullLuminosity();
    fullLight = light & 0xFFFF;
    irLight = light >> 16;
    visibleLight = fullLight - irLight;
    lux = lightSensor.calculateLux(fullLight, irLight);
    //TODO: soil moisture sensor
    if(postToPhant() == 0) {
      //Success
    } else {
      //failed
      //TODO: Handle failure
    }
  }
Example #2
0
termomether temp_read() {
  _t.temperature = htu.readTemperature();
  _t.humidity    = htu.readHumidity();
  return _t;
}