diff --git a/boil_kettle/boil_kettle.ino b/boil_kettle/boil_kettle.ino index 3585559..a268eb7 100644 --- a/boil_kettle/boil_kettle.ino +++ b/boil_kettle/boil_kettle.ino @@ -22,35 +22,51 @@ #include "src/functions.h" void setup() { + /** + * Any state information that needs to be kept between reboots + * will be stored in EEPROM. + * + * This will allow modifying these through MQTT communication + * later without needing to recompile the code. + */ ConfigData config; EEPROM.get(ConfAddress, config); unsigned long lastRun = millis() - UpdateInterval; Serial.begin(9600); - rotary.begin(); + Ethernet.begin(config.mac, config.ip); + /** + * Setup pins and interrupts/ + */ attachInterrupt(digitalPinToInterrupt(I_CLK), doEncoder, CHANGE); attachInterrupt(digitalPinToInterrupt(I_DT), doEncoder, CHANGE); - pinMode(I_CLK, INPUT_PULLUP); - pinMode(I_DT, INPUT_PULLUP); + rotary.begin(); Enter.begin(I_BTN); boilPWM.begin(O_PWM, config.period); - mqtt_client.setServer(config.mqtt.broker, 1883); - mqtt_client.setClient(net); - mqtt_client.setCallback(MessageReceived); - + /** + * Kettle temp control + */ KettleController.begin(I_CS1); KettleController.Hysteresis(config.hysteresis); KettleController.ThreshPWR(config.threshold); - // if you get a connection, report back via serial: + /** + * No sense messing with MQTT if we're not on the network. + */ if (Ethernet.linkStatus() == LinkON) { + mqtt_client.setServer(config.mqtt.broker, 1883); + mqtt_client.setClient(net); + mqtt_client.setCallback(MessageReceived); ConnectMQTT(); } + /** + * Fire up the LCD. + */ lcd.init(); lcd.backlight();