Changeset - ec770b41aaac
[Not reviewed]
tip default
0 1 0
Dennis Fink - 5 years ago 2020-01-15 20:54:18
dennis.fink@c3l.lu
Let the LED flash, when there is an error and the button restarts
1 file changed with 21 insertions and 5 deletions:
0 comments (0 inline, 0 general)
SpaceApiButton.ino
Show inline comments
 
@@ -25,10 +25,25 @@ unsigned long debounceDelay = 50;    // 
 
const size_t bufferSize = JSON_OBJECT_SIZE(4) + 70;
 

	
 
void connect() {
 
  digitalWrite(LED_BUILTIN, HIGH);
 
  Serial.print("\nChecking WiFi...");
 
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
 
    Serial.println("Connection Failed! Reboot...");
 
    delay(5000);
 
    digitalWrite(D2, LOW);
 
    digitalWrite(LED_BUILTIN, LOW);
 
    delay(250);
 
    digitalWrite(D2, HIGH);
 
    digitalWrite(LED_BUILTIN, HIGH);
 
    delay(250);
 
    digitalWrite(D2, LOW);
 
    digitalWrite(LED_BUILTIN, LOW);
 
    delay(250);
 
    digitalWrite(D2, HIGH);
 
    digitalWrite(LED_BUILTIN, HIGH);
 
    delay(250);
 
    digitalWrite(D2, LOW);
 
    digitalWrite(LED_BUILTIN, LOW);
 
    delay(4000);
 
    ESP.restart();
 
  }
 
  Serial.println("Connected to WiFi!");
 
@@ -39,11 +54,14 @@ void connect() {
 
  Serial.print("Connecting to MQTT Server...");
 
  while (!client.connect(MQTT_CLIENT_ID, MQTT_USERNAME, MQTT_PASSWORD)) {
 
    Serial.print(".");
 
    digitalWrite(LED_BUILTIN, LOW);
 
    delay(1000);
 
    digitalWrite(LED_BUILTIN, HIGH);
 
  }
 
  Serial.println("\nConnected to MQTT!");
 
  client.publish(MQTT_AVAILABILITY_TOPIC, "online", true, 2);
 
  client.subscribe(MQTT_STATE_TOPIC);
 
  digitalWrite(LED_BUILTIN, LOW);
 
}
 

	
 
void on_state_received(String &topic, String &payload) {
 
@@ -72,6 +90,8 @@ void setup() {
 
  Serial.println("Booting...");
 

	
 
  pinMode(LED_BUILTIN, OUTPUT);
 
  pinMode(D2, OUTPUT);
 
  pinMode(D1, INPUT);
 

	
 
  WiFi.hostname(HOSTNAME);
 
  WiFi.mode(WIFI_STA);
 
@@ -93,10 +113,6 @@ void setup() {
 
  Serial.println("Adding HTTP server to MDNS...");
 
  MDNS.addService("http", "tcp", 80);
 
  Serial.printf("HTTPUpdateServer ready! Open http://%s.local/update in your browser\n", HOSTNAME);
 

	
 
  pinMode(D2, OUTPUT);
 
  pinMode(D1, INPUT);
 

	
 
}
 

	
 
void loop() {
0 comments (0 inline, 0 general)