|
|
@ -16,6 +16,11 @@ EspMQTTClient client( |
|
|
|
); |
|
|
|
|
|
|
|
const int heating_pin = 14; |
|
|
|
const int led_pin = 2; |
|
|
|
|
|
|
|
#define led_on(state) do {\
|
|
|
|
digitalWrite(led_pin, (state) ? LOW : HIGH); \ |
|
|
|
} while (0) |
|
|
|
|
|
|
|
#define heater_on(pin) do {\
|
|
|
|
digitalWrite(pin, LOW); \ |
|
|
@ -58,6 +63,7 @@ void shutdown_heater(void *dummy) |
|
|
|
void setup() |
|
|
|
{ |
|
|
|
pinMode(heating_pin, OUTPUT); |
|
|
|
pinMode(led_pin, OUTPUT); |
|
|
|
heater_off(heating_pin); |
|
|
|
|
|
|
|
Serial.begin(115200); |
|
|
@ -80,9 +86,19 @@ void onConnectionEstablished() |
|
|
|
|
|
|
|
void loop() |
|
|
|
{ |
|
|
|
static unsigned int counter; |
|
|
|
static bool led_state = false; |
|
|
|
|
|
|
|
client.loop(); |
|
|
|
if (!client.isConnected()) { |
|
|
|
// if something wrong happens, switch off the heater
|
|
|
|
heater_off(heating_pin); |
|
|
|
} |
|
|
|
|
|
|
|
// blink ESP blue led to show that we are alive
|
|
|
|
if (((led_state) && (counter % 1000 == 0)) || (!led_state && (counter % 30000 == 0))) { |
|
|
|
led_state = !led_state; |
|
|
|
led_on(led_state); |
|
|
|
} |
|
|
|
counter++; |
|
|
|
} |