Commit bc6422f1 authored by Jason Williams's avatar Jason Williams

Adding software update checker from experimentation branch

parent 2a7b6d65
// WiFi & Connectivity Includes
#include <ESP8266WiFi.h>
#include <ESP8266HTTPUpdate.h>
#include <PubSubClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
......@@ -155,14 +156,19 @@ void loop() {
// Check how long it's been since the last periodic update, and send another one if required
unsigned long elapsed_since_update = millis() - periodic_update;
if (elapsed_since_update >= 120000) {
// Update the side door status
if (state_sidedoor == 0) client.publish(topic_sidedoor, "ON");
else if (state_sidedoor == 1) client.publish(topic_sidedoor, "OFF");
// Update the garage door
if (state_door == 0) client.publish(topic_doorstate, "CLOSED");
else if (state_door == 1) client.publish(topic_doorstate, "MOVING");
else if (state_door == 2) client.publish(topic_doorstate, "OPEN");
else client.publish(topic_doorstate, "ERROR");
// Check for software updates
updateCheck();
periodic_update = millis();
}
......@@ -195,3 +201,19 @@ void movedoor() {
delay(500);
digitalWrite(pin_doortoggle, HIGH);
}
void updateCheck() {
t_httpUpdate_return ret = ESPhttpUpdate.update("http://internal.jnf.me/public/pages/updater/");
switch(ret) {
case HTTP_UPDATE_FAILED:
Serial.print("[Update] Update failed: ");
Serial.println(ESPhttpUpdate.getLastErrorString().c_str());
break;
case HTTP_UPDATE_NO_UPDATES:
Serial.println("[Update] No update required");
break;
case HTTP_UPDATE_OK:
Serial.println("[Update] Update OK");
break;
}
}
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