Commit 1b5d9729 authored by Jason Williams's avatar Jason Williams

Added code for second temperature sensor.

parent bc6422f1
......@@ -11,6 +11,8 @@ const int pin_doorclosed = D1;
const int pin_sidedoor = D2;
const int pin_doortoggle = D6;
const int pin_temperature = D7;
DeviceAddress ambient = { 0x28, 0x6F, 0x08, 0x0A, 0x31, 0x14, 0x01, 0x20 };
DeviceAddress freezer = { 0x28, 0x6C, 0x96, 0x00, 0x31, 0x14, 0x01, 0x77 };
// WiFi & Connectivity Settings
#include "secrets.h"
......@@ -27,6 +29,7 @@ const char* topic_doorcommand = "garage/door/command";
const char* topic_doorstate = "garage/door/state";
const char* topic_sidedoor = "garage/sidedoor";
const char* topic_ambienttemp = "garage/temperature";
const char* topic_freezertemp = "garage/freezer";
// Currently reported states and/or times
bool state_sidedoor = 1;
......@@ -136,13 +139,15 @@ void loop() {
delay(500);
}
// Check the temperature every 30 seconds and send an update
// Check the temperatures every 30 seconds and send an update
unsigned long elapsed_temperature = millis() - sent_temperature;
if(elapsed_temperature >= 30000) {
DallasTemp.requestTemperatures();
char tempstr[6];
sprintf(tempstr, "%.1f", DallasTemp.getTempCByIndex(0));
client.publish(topic_ambienttemp, tempstr);
char ambtempstr[6], frztempstr[6];
sprintf(ambtempstr, "%.1f", DallasTemp.getTempC(ambient));
sprintf(frztempstr, "%.1f", DallasTemp.getTempC(freezer));
client.publish(topic_ambienttemp, ambtempstr);
client.publish(topic_freezertemp, frztempstr);
Serial.print("The temperature is ");
Serial.print(tempstr);
......@@ -150,7 +155,6 @@ void loop() {
sent_temperature = millis();
}
// TODO: TEMPERATURE SENSOR 2
// TODO: ULTRASONIC DISTANCE SENSORS
// Check how long it's been since the last periodic update, and send another one if required
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment