Emergency_mesh_communication — ESP32-C3 simulation

An interactive ESP32-C3 circuit simulation you can run free in your browser on Velxio, by usaamaamf4925.

Components

Sketch code

#include <HardwareSerial.h>

HardwareSerial primary(1);
HardwareSerial backup(2);

#define EMERGENCY_BTN 4

bool emergencyActive = false;
bool node2Failed = false;
bool lastButton = HIGH;

void setup() {
  Serial.begin(115200);

  pinMode(EMERGENCY_BTN, INPUT_PULLUP);

  primary.begin(9600, SERIAL_8N1, 16, 17);
  backup.begin(9600, SERIAL_8N1, 26, 25);
}

void sendEmergency() {
  if (node2Failed) {
    backup.println("EMERG:N1:N3:N4");
    Serial.println("Emergency via Backup Route");
  } else {
    primary.println("EMERG:N1:N2:N4");
    Serial.println("Emergency via Primary Route");
  }
}

void loop() {

  bool current = digitalRead(EMERGENCY_BTN);

  if (lastButton == HIGH && current == LOW) {
    emergencyActive = true;
    sendEmergency();
  }

  lastButton = current;

  if (primary.available()) {
    String msg = primary.readStringUntil('\n');
    msg.trim();

    if (msg == "FAIL:N2") {
      node2Failed = true;

      if (emergencyActive) {
        delay(1000);
        backup.println("EMERG:N1:N3:N4");
      }
    }

    if (msg == "REPAIR:N2") {
      node2Failed = false;
    }
  }
}

More projects by usaamaamf4925