#include "esp32_ethernet.hpp" #include "mpod.hpp" #include "pins.hpp" #include "rest.hpp" unsigned long start; extern bool eth_connected; extern SNMP::Manager snmp; TaskHandle_t restServerTask; TaskHandle_t powerProcedureTask; void setup() { Serial.begin(115200); initializeMCP(); initializeNetwork(); initializeRoutes(); initializeSNMP(); // Poll port expander to initialize the PINS struct. poll_port_expander(); PINS.last_triggered = millis(); PINS.stage = ""; PINS.ramping = false; start = millis(); xTaskCreatePinnedToCore(webInterfaceLoop, "Web Interface", 10000, NULL, 1, &restServerTask, 0); xTaskCreatePinnedToCore(mainLoop, "PowerProcedure Task", 10000, NULL, 1, &powerProcedureTask, 1); } enum { NONE, ON, OFF, }; void serialLoop() { if (millis() - start >= 1000) { start = millis(); Serial.print(eth_connected ? "." : "-"); } } void webInterfaceLoop(void* pvParameters) { Serial.print("Web loop running on core "); Serial.println(xPortGetCoreID()); while (true) { restServer.handleClient(); } } void mainLoop(void* pvParameters) { Serial.print("main loop running on core "); Serial.println(xPortGetCoreID()); while (true) { isr_check_loop(); snmp.loop(); toggle_status_led(); serialLoop(); if (eth_connected) { // We may be triggered, but disconnected from the network. powerOffCheckLoop(); } } } void loop() {}