Skip to content

Commit

Permalink
Final tweaks to get it working on a Photon
Browse files Browse the repository at this point in the history
  • Loading branch information
meisteg committed Dec 28, 2019
1 parent 8ad26b1 commit 7f11d20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion project.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name=TempAlarmFirmware
dependencies.Adafruit_DHT=0.0.4
dependencies.Adafruit_DHT=0.0.2
dependencies.Adafruit_IO_Particle=1.0.1
20 changes: 18 additions & 2 deletions src/TempAlarmFirmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -155,36 +155,49 @@ static void doAlarmIfNecessary(void)

if ((now - lastAIOThresMillis) >= AIO_CHECK_MS)
{
SERIAL.println("Getting thresholds from Adafruit IO");

// Get latest values from Adafruit IO
Adafruit_IO_Feed lowThresFeed = AIOClient->getFeed("temp-alarm.low-threshold");
FeedData lowThresLatest = lowThresFeed.receive();
if (lowThresLatest.isValid())
{
int newLowThres;
lowThresLatest.intValue(&newLowThres);
if (newLowThres != sensorSettings.lowThres)
if ((newLowThres != 0) && (newLowThres != sensorSettings.lowThres))
{
sensorSettings.lowThres = newLowThres;
EEPROM.put(SETTINGS_ADDR, sensorSettings);

SERIAL.printlnf("New Low Threshold: %d", sensorSettings.lowThres);
}
}
else
{
SERIAL.println("Adafruit IO low threshold is not valid!");
}

// Yield to Particle before retrieving the high threshold
Particle.process();

Adafruit_IO_Feed highThresFeed = AIOClient->getFeed("temp-alarm.high-threshold");
FeedData highThresLatest = highThresFeed.receive();
if (highThresLatest.isValid())
{
int newHighThres;
highThresLatest.intValue(&newHighThres);
if (newHighThres != sensorSettings.highThres)
if ((newHighThres != 0) && (newHighThres != sensorSettings.highThres))
{
sensorSettings.highThres = newHighThres;
EEPROM.put(SETTINGS_ADDR, sensorSettings);

SERIAL.printlnf("New High Threshold: %d", sensorSettings.highThres);
}
}
else
{
SERIAL.println("Adafruit IO high threshold is not valid!");
}

lastAIOThresMillis = now;
}
Expand Down Expand Up @@ -274,6 +287,9 @@ static void doReportIfTime(void)
SERIAL.println("Failed to publish temperature to Adafruit IO!");
}

// Yield to Particle before sending the humidity
Particle.process();

Adafruit_IO_Feed humidityFeed = AIOClient->getFeed("temp-alarm.humidity");
snprintf(publishString, sizeof(publishString), "%.1f", currentHumid);
if (!humidityFeed.send(publishString))
Expand Down

0 comments on commit 7f11d20

Please sign in to comment.