├── BlynkInfo ├── CoopCommand ├── BlynkEdgent.h ├── BlynkState.h ├── ConfigMode.h ├── ConfigStore.h ├── Console.h ├── CoopCommandESP32Rev.ino1 ├── Indicator.h ├── OTA.h ├── ResetButton.h └── Settings.h ├── CoopCommandImages ├── Images.txt ├── PXL_20221015_171228559.jpg ├── PXL_20221015_171242919.MP.jpg ├── PXL_20221029_195134568.jpg ├── Screenshot_20221029-083106.png └── Screenshot_20221029-083134.png ├── LICENSE └── README.md /BlynkInfo: -------------------------------------------------------------------------------- 1 | # To connect to CoopCommand with your smartphone, you will need to follow these steps: 2 | 1) Go to https://blynk.io/ and make a free account. 3 | 2) Once you have signed up and are at the Blynk Dashboard, go to "Templates" on the left hand side of the screen. 4 | 3) Create a new Template and name it CoopCommand or something similar. 5 | 4) Create the following Datastreams as shown at this imgur link: https://imgur.com/a/NWCejiL . 6 | 5) Add the Template ID and Device name in the appropriate place in the CoopCommand program (IDE will throw an error if not done and will not upload) 7 | 6) Download the Blynk App (Blynk IOT for Android, unsure for Apple). 8 | 7) Top right of the app once you are logged in is 3 bars, click on that and then click "add new device" while you are near your CoopCommand board and it is powered up. 9 | 8) Follow the directions in the app to connect your phone to your CoopCommand. 10 | 9) Congratulations! You are now online with CoopCommand! 11 | -------------------------------------------------------------------------------- /CoopCommand/BlynkEdgent.h: -------------------------------------------------------------------------------- 1 | 2 | extern "C" { 3 | void app_loop(); 4 | void restartMCU(); 5 | } 6 | 7 | #include "Settings.h" 8 | #include 9 | 10 | #if defined(BLYNK_USE_LITTLEFS) 11 | #include 12 | #define BLYNK_FS LittleFS 13 | #elif defined(BLYNK_USE_SPIFFS) 14 | #if defined(ESP32) 15 | #include 16 | #elif defined(ESP8266) 17 | #include 18 | #endif 19 | #define BLYNK_FS SPIFFS 20 | #endif 21 | 22 | #ifndef BLYNK_NEW_LIBRARY 23 | #error "Old version of Blynk library is in use. Please replace it with the new one." 24 | #endif 25 | 26 | #if !defined(BLYNK_TEMPLATE_NAME) && defined(BLYNK_DEVICE_NAME) 27 | #define BLYNK_TEMPLATE_NAME BLYNK_DEVICE_NAME 28 | #endif 29 | 30 | #if !defined(BLYNK_TEMPLATE_ID) || !defined(BLYNK_TEMPLATE_NAME) 31 | #error "Please specify your BLYNK_TEMPLATE_ID and BLYNK_TEMPLATE_NAME" 32 | #endif 33 | 34 | #if defined(BLYNK_AUTH_TOKEN) 35 | #error "BLYNK_AUTH_TOKEN is assigned automatically when using Blynk.Edgent, please remove it from the configuration" 36 | #endif 37 | 38 | BlynkTimer edgentTimer; 39 | 40 | #include "BlynkState.h" 41 | #include "ConfigStore.h" 42 | #include "ResetButton.h" 43 | #include "ConfigMode.h" 44 | #include "Indicator.h" 45 | #include "OTA.h" 46 | #include "Console.h" 47 | 48 | 49 | inline 50 | void BlynkState::set(State m) { 51 | if (state != m && m < MODE_MAX_VALUE) { 52 | DEBUG_PRINT(String(StateStr[state]) + " => " + StateStr[m]); 53 | state = m; 54 | 55 | // You can put your state handling here, 56 | // i.e. implement custom indication 57 | } 58 | } 59 | 60 | void printDeviceBanner() 61 | { 62 | #ifdef BLYNK_PRINT 63 | Blynk.printBanner(); 64 | BLYNK_PRINT.println("----------------------------------------------------"); 65 | BLYNK_PRINT.print(" Device: "); BLYNK_PRINT.println(getWiFiName()); 66 | BLYNK_PRINT.print(" Firmware: "); BLYNK_PRINT.println(BLYNK_FIRMWARE_VERSION " (build " __DATE__ " " __TIME__ ")"); 67 | if (configStore.getFlag(CONFIG_FLAG_VALID)) { 68 | BLYNK_PRINT.print(" Token: "); 69 | BLYNK_PRINT.println(String(configStore.cloudToken).substring(0,4) + 70 | " - •••• - •••• - ••••"); 71 | } 72 | BLYNK_PRINT.print(" Platform: "); BLYNK_PRINT.println(String(BLYNK_INFO_DEVICE) + " @ " + ESP.getCpuFreqMHz() + "MHz"); 73 | BLYNK_PRINT.print(" Chip rev: "); BLYNK_PRINT.println(ESP.getChipRevision()); 74 | BLYNK_PRINT.print(" SDK: "); BLYNK_PRINT.println(ESP.getSdkVersion()); 75 | BLYNK_PRINT.print(" Flash: "); BLYNK_PRINT.println(String(ESP.getFlashChipSize() / 1024) + "K"); 76 | BLYNK_PRINT.print(" Free mem: "); BLYNK_PRINT.println(ESP.getFreeHeap()); 77 | BLYNK_PRINT.println("----------------------------------------------------"); 78 | #endif 79 | } 80 | 81 | void runBlynkWithChecks() { 82 | Blynk.run(); 83 | if (BlynkState::get() == MODE_RUNNING) { 84 | if (!Blynk.connected()) { 85 | if (WiFi.status() == WL_CONNECTED) { 86 | BlynkState::set(MODE_CONNECTING_CLOUD); 87 | } else { 88 | BlynkState::set(MODE_CONNECTING_NET); 89 | } 90 | } 91 | } 92 | } 93 | 94 | class Edgent { 95 | 96 | public: 97 | void begin() 98 | { 99 | WiFi.persistent(false); 100 | WiFi.enableSTA(true); // Needed to get MAC 101 | #if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)) 102 | WiFi.setMinSecurity(WIFI_AUTH_WEP); 103 | #endif 104 | 105 | #ifdef BLYNK_FS 106 | BLYNK_FS.begin(true); 107 | #endif 108 | 109 | indicator_init(); 110 | button_init(); 111 | config_init(); 112 | printDeviceBanner(); 113 | console_init(); 114 | 115 | if (configStore.getFlag(CONFIG_FLAG_VALID)) { 116 | BlynkState::set(MODE_CONNECTING_NET); 117 | } else if (config_load_blnkopt()) { 118 | DEBUG_PRINT("Firmware is preprovisioned"); 119 | BlynkState::set(MODE_CONNECTING_NET); 120 | } else { 121 | BlynkState::set(MODE_WAIT_CONFIG); 122 | } 123 | 124 | if (!String(BLYNK_TEMPLATE_ID).startsWith("TMPL") || 125 | !strlen(BLYNK_TEMPLATE_NAME) 126 | ) { 127 | DEBUG_PRINT("Invalid configuration of TEMPLATE_ID / TEMPLATE_NAME"); 128 | while (true) { delay(100); } 129 | } 130 | } 131 | 132 | void run() { 133 | app_loop(); 134 | switch (BlynkState::get()) { 135 | case MODE_WAIT_CONFIG: 136 | case MODE_CONFIGURING: enterConfigMode(); break; 137 | case MODE_CONNECTING_NET: enterConnectNet(); break; 138 | case MODE_CONNECTING_CLOUD: enterConnectCloud(); break; 139 | case MODE_RUNNING: runBlynkWithChecks(); break; 140 | case MODE_OTA_UPGRADE: enterOTA(); break; 141 | case MODE_SWITCH_TO_STA: enterSwitchToSTA(); break; 142 | case MODE_RESET_CONFIG: enterResetConfig(); break; 143 | default: enterError(); break; 144 | } 145 | } 146 | 147 | } BlynkEdgent; 148 | 149 | void app_loop() { 150 | edgentTimer.run(); 151 | edgentConsole.run(); 152 | } 153 | 154 | -------------------------------------------------------------------------------- /CoopCommand/BlynkState.h: -------------------------------------------------------------------------------- 1 | 2 | enum State { 3 | MODE_WAIT_CONFIG, 4 | MODE_CONFIGURING, 5 | MODE_CONNECTING_NET, 6 | MODE_CONNECTING_CLOUD, 7 | MODE_RUNNING, 8 | MODE_OTA_UPGRADE, 9 | MODE_SWITCH_TO_STA, 10 | MODE_RESET_CONFIG, 11 | MODE_ERROR, 12 | 13 | MODE_MAX_VALUE 14 | }; 15 | 16 | #if defined(APP_DEBUG) 17 | const char* StateStr[MODE_MAX_VALUE+1] = { 18 | "WAIT_CONFIG", 19 | "CONFIGURING", 20 | "CONNECTING_NET", 21 | "CONNECTING_CLOUD", 22 | "RUNNING", 23 | "OTA_UPGRADE", 24 | "SWITCH_TO_STA", 25 | "RESET_CONFIG", 26 | "ERROR", 27 | 28 | "INIT" 29 | }; 30 | #endif 31 | 32 | namespace BlynkState 33 | { 34 | volatile State state = MODE_MAX_VALUE; 35 | 36 | State get() { return state; } 37 | bool is (State m) { return (state == m); } 38 | void set(State m); 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /CoopCommand/ConfigMode.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #ifndef BLYNK_FS 8 | 9 | const char* config_form = R"html( 10 | 11 | 12 | 13 | WiFi setup 14 | 40 | 41 | 42 |
43 |
44 | 45 | 46 | 47 | 48 | 49 | 50 |

51 | 52 |
53 |
54 | 55 | 56 | )html"; 57 | 58 | #endif 59 | 60 | WebServer server(80); 61 | DNSServer dnsServer; 62 | const byte DNS_PORT = 53; 63 | 64 | static int connectNetRetries = WIFI_CLOUD_MAX_RETRIES; 65 | static int connectBlynkRetries = WIFI_CLOUD_MAX_RETRIES; 66 | 67 | static const char serverUpdateForm[] PROGMEM = 68 | R"( 69 |
70 | 71 | 72 |
73 | )"; 74 | 75 | void restartMCU() { 76 | ESP.restart(); 77 | while(1) {}; 78 | } 79 | 80 | static 81 | String encodeUniquePart(uint32_t n, unsigned len) 82 | { 83 | static constexpr char alphabet[] = { "0W8N4Y1HP5DF9K6JM3C2UA7R" }; 84 | static constexpr int base = sizeof(alphabet)-1; 85 | 86 | char buf[16] = { 0, }; 87 | char prev = 0; 88 | for (unsigned i = 0; i < len; n /= base) { 89 | char c = alphabet[n % base]; 90 | if (c == prev) { 91 | c = alphabet[(n+1) % base]; 92 | } 93 | prev = buf[i++] = c; 94 | } 95 | return String(buf); 96 | } 97 | 98 | static 99 | String getWiFiName(bool withPrefix = true) 100 | { 101 | const uint64_t chipId = ESP.getEfuseMac(); 102 | 103 | uint32_t unique = 0; 104 | for (int i=0; i<4; i++) { 105 | unique = BlynkCRC32(&chipId, sizeof(chipId), unique); 106 | } 107 | String devUnique = encodeUniquePart(unique, 4); 108 | 109 | String devPrefix = CONFIG_DEVICE_PREFIX; 110 | String devName = String(BLYNK_TEMPLATE_NAME).substring(0, 31-6-devPrefix.length()); 111 | 112 | if (withPrefix) { 113 | return devPrefix + " " + devName + "-" + devUnique; 114 | } else { 115 | return devName + "-" + devUnique; 116 | } 117 | } 118 | 119 | static inline 120 | String macToString(byte mac[6]) { 121 | char buff[20]; 122 | snprintf(buff, sizeof(buff), "%02x:%02x:%02x:%02x:%02x:%02x", 123 | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 124 | return String(buff); 125 | } 126 | 127 | static inline 128 | const char* wifiSecToStr(wifi_auth_mode_t t) { 129 | switch (t) { 130 | case WIFI_AUTH_OPEN: return "OPEN"; 131 | case WIFI_AUTH_WEP: return "WEP"; 132 | case WIFI_AUTH_WPA_PSK: return "WPA"; 133 | case WIFI_AUTH_WPA2_PSK: return "WPA2"; 134 | case WIFI_AUTH_WPA_WPA2_PSK: return "WPA+WPA2"; 135 | case WIFI_AUTH_WPA2_ENTERPRISE: return "WPA2-EAP"; 136 | #if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0)) 137 | case WIFI_AUTH_WPA3_PSK: return "WPA3"; 138 | case WIFI_AUTH_WPA2_WPA3_PSK: return "WPA2+WPA3"; 139 | case WIFI_AUTH_WAPI_PSK: return "WAPI"; 140 | #endif 141 | default: return "unknown"; 142 | } 143 | } 144 | 145 | static 146 | String getWiFiMacAddress() { 147 | return WiFi.macAddress(); 148 | } 149 | 150 | static 151 | String getWiFiApBSSID() { 152 | return WiFi.softAPmacAddress(); 153 | } 154 | 155 | static 156 | String getWiFiNetworkSSID() { 157 | return WiFi.SSID(); 158 | } 159 | 160 | static 161 | String getWiFiNetworkBSSID() { 162 | return WiFi.BSSIDstr(); 163 | } 164 | 165 | void enterConfigMode() 166 | { 167 | WiFi.mode(WIFI_OFF); 168 | delay(100); 169 | WiFi.mode(WIFI_AP); 170 | delay(2000); 171 | WiFi.softAPConfig(WIFI_AP_IP, WIFI_AP_IP, WIFI_AP_Subnet); 172 | WiFi.softAP(getWiFiName().c_str()); 173 | delay(500); 174 | 175 | // Set up DNS Server 176 | dnsServer.setTTL(300); // Time-to-live 300s 177 | dnsServer.setErrorReplyCode(DNSReplyCode::ServerFailure); // Return code for non-accessible domains 178 | #ifdef WIFI_CAPTIVE_PORTAL_ENABLE 179 | dnsServer.start(DNS_PORT, "*", WiFi.softAPIP()); // Point all to our IP 180 | server.onNotFound(handleRoot); 181 | #else 182 | dnsServer.start(DNS_PORT, CONFIG_AP_URL, WiFi.softAPIP()); 183 | DEBUG_PRINT(String("AP URL: ") + CONFIG_AP_URL); 184 | #endif 185 | 186 | server.on("/update", HTTP_GET, []() { 187 | server.sendHeader("Connection", "close"); 188 | server.send(200, "text/html", serverUpdateForm); 189 | }); 190 | server.on("/update", HTTP_POST, []() { 191 | server.sendHeader("Connection", "close"); 192 | if (!Update.hasError()) { 193 | server.send(200, "text/plain", "OK"); 194 | } else { 195 | server.send(500, "text/plain", "FAIL"); 196 | } 197 | delay(1000); 198 | restartMCU(); 199 | }, []() { 200 | HTTPUpload& upload = server.upload(); 201 | if (upload.status == UPLOAD_FILE_START) { 202 | DEBUG_PRINT(String("Update: ") + upload.filename); 203 | //WiFiUDP::stop(); 204 | 205 | if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size 206 | DEBUG_PRINT(Update.errorString()); 207 | } 208 | } else if (upload.status == UPLOAD_FILE_WRITE) { 209 | /* flashing firmware to ESP*/ 210 | if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) { 211 | DEBUG_PRINT(Update.errorString()); 212 | } 213 | #ifdef BLYNK_PRINT 214 | BLYNK_PRINT.print("."); 215 | #endif 216 | } else if (upload.status == UPLOAD_FILE_END) { 217 | #ifdef BLYNK_PRINT 218 | BLYNK_PRINT.println(); 219 | #endif 220 | DEBUG_PRINT("Finishing..."); 221 | if (Update.end(true)) { //true to set the size to the current progress 222 | DEBUG_PRINT("Update Success. Rebooting"); 223 | } else { 224 | DEBUG_PRINT(Update.errorString()); 225 | } 226 | } 227 | }); 228 | #ifndef BLYNK_FS 229 | server.on("/", []() { 230 | server.send(200, "text/html", config_form); 231 | }); 232 | #endif 233 | server.on("/config", []() { 234 | DEBUG_PRINT("Applying configuration..."); 235 | String ssid = server.arg("ssid"); 236 | String ssidManual = server.arg("ssidManual"); 237 | String pass = server.arg("pass"); 238 | if (ssidManual != "") { 239 | ssid = ssidManual; 240 | } 241 | String token = server.arg("blynk"); 242 | String host = server.arg("host"); 243 | String port = server.arg("port_ssl"); 244 | 245 | String ip = server.arg("ip"); 246 | String mask = server.arg("mask"); 247 | String gw = server.arg("gw"); 248 | String dns = server.arg("dns"); 249 | String dns2 = server.arg("dns2"); 250 | 251 | bool forceSave = server.arg("save").toInt(); 252 | 253 | String content; 254 | 255 | DEBUG_PRINT(String("WiFi SSID: ") + ssid + " Pass: " + pass); 256 | DEBUG_PRINT(String("Blynk cloud: ") + token + " @ " + host + ":" + port); 257 | 258 | if (token.length() == 32 && ssid.length() > 0) { 259 | configStore = configDefault; 260 | CopyString(ssid, configStore.wifiSSID); 261 | CopyString(pass, configStore.wifiPass); 262 | CopyString(token, configStore.cloudToken); 263 | if (host.length()) { 264 | CopyString(host, configStore.cloudHost); 265 | } 266 | if (port.length()) { 267 | configStore.cloudPort = port.toInt(); 268 | } 269 | 270 | IPAddress addr; 271 | 272 | if (ip.length() && addr.fromString(ip)) { 273 | configStore.staticIP = addr; 274 | configStore.setFlag(CONFIG_FLAG_STATIC_IP, true); 275 | } else { 276 | configStore.setFlag(CONFIG_FLAG_STATIC_IP, false); 277 | } 278 | if (mask.length() && addr.fromString(mask)) { 279 | configStore.staticMask = addr; 280 | } 281 | if (gw.length() && addr.fromString(gw)) { 282 | configStore.staticGW = addr; 283 | } 284 | if (dns.length() && addr.fromString(dns)) { 285 | configStore.staticDNS = addr; 286 | } 287 | if (dns2.length() && addr.fromString(dns2)) { 288 | configStore.staticDNS2 = addr; 289 | } 290 | 291 | if (forceSave) { 292 | configStore.setFlag(CONFIG_FLAG_VALID, true); 293 | config_save(); 294 | 295 | content = R"json({"status":"ok","msg":"Configuration saved"})json"; 296 | } else { 297 | content = R"json({"status":"ok","msg":"Trying to connect..."})json"; 298 | } 299 | server.send(200, "application/json", content); 300 | 301 | connectNetRetries = connectBlynkRetries = 1; 302 | BlynkState::set(MODE_SWITCH_TO_STA); 303 | } else { 304 | DEBUG_PRINT("Configuration invalid"); 305 | content = R"json({"status":"error","msg":"Configuration invalid"})json"; 306 | server.send(500, "application/json", content); 307 | } 308 | }); 309 | server.on("/board_info.json", []() { 310 | // Configuring starts with board info request (may impact indication) 311 | BlynkState::set(MODE_CONFIGURING); 312 | 313 | DEBUG_PRINT("Sending board info..."); 314 | const char* tmpl = BLYNK_TEMPLATE_ID; 315 | 316 | char buff[512]; 317 | snprintf(buff, sizeof(buff), 318 | R"json({"board":"%s","tmpl_id":"%s","fw_type":"%s","fw_ver":"%s","ssid":"%s","bssid":"%s","mac":"%s","last_error":%d,"wifi_scan":true,"static_ip":true})json", 319 | BLYNK_TEMPLATE_NAME, 320 | tmpl ? tmpl : "Unknown", 321 | BLYNK_FIRMWARE_TYPE, 322 | BLYNK_FIRMWARE_VERSION, 323 | getWiFiName().c_str(), 324 | getWiFiApBSSID().c_str(), 325 | getWiFiMacAddress().c_str(), 326 | configStore.last_error 327 | ); 328 | server.send(200, "application/json", buff); 329 | }); 330 | server.on("/wifi_scan.json", []() { 331 | DEBUG_PRINT("Scanning networks..."); 332 | int wifi_nets = WiFi.scanNetworks(true, true); 333 | const uint32_t t = millis(); 334 | while (wifi_nets < 0 && 335 | millis() - t < 20000) 336 | { 337 | delay(20); 338 | wifi_nets = WiFi.scanComplete(); 339 | } 340 | DEBUG_PRINT(String("Found networks: ") + wifi_nets); 341 | 342 | if (wifi_nets > 0) { 343 | // Sort networks 344 | int indices[wifi_nets]; 345 | for (int i = 0; i < wifi_nets; i++) { 346 | indices[i] = i; 347 | } 348 | for (int i = 0; i < wifi_nets; i++) { 349 | for (int j = i + 1; j < wifi_nets; j++) { 350 | if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) { 351 | std::swap(indices[i], indices[j]); 352 | } 353 | } 354 | } 355 | 356 | wifi_nets = BlynkMin(15, wifi_nets); // Show top 15 networks 357 | 358 | // TODO: skip empty names 359 | String result = "[\n"; 360 | 361 | char buff[256]; 362 | for (int i = 0; i < wifi_nets; i++){ 363 | int id = indices[i]; 364 | 365 | snprintf(buff, sizeof(buff), 366 | R"json( {"ssid":"%s","bssid":"%s","rssi":%i,"sec":"%s","ch":%i})json", 367 | WiFi.SSID(id).c_str(), 368 | WiFi.BSSIDstr(id).c_str(), 369 | WiFi.RSSI(id), 370 | wifiSecToStr(WiFi.encryptionType(id)), 371 | WiFi.channel(id) 372 | ); 373 | 374 | result += buff; 375 | if (i != wifi_nets-1) result += ",\n"; 376 | } 377 | WiFi.scanDelete(); 378 | server.send(200, "application/json", result + "\n]"); 379 | } else { 380 | server.send(200, "application/json", "[]"); 381 | } 382 | }); 383 | server.on("/reset", []() { 384 | BlynkState::set(MODE_RESET_CONFIG); 385 | server.send(200, "application/json", R"json({"status":"ok","msg":"Configuration reset"})json"); 386 | }); 387 | server.on("/reboot", []() { 388 | restartMCU(); 389 | }); 390 | 391 | #ifdef BLYNK_FS 392 | server.serveStatic("/img/favicon.png", BLYNK_FS, "/img/favicon.png"); 393 | server.serveStatic("/img/logo.png", BLYNK_FS, "/img/logo.png"); 394 | server.serveStatic("/", BLYNK_FS, "/index.html"); 395 | #endif 396 | 397 | server.begin(); 398 | 399 | while (BlynkState::is(MODE_WAIT_CONFIG) || BlynkState::is(MODE_CONFIGURING)) { 400 | delay(10); 401 | dnsServer.processNextRequest(); 402 | server.handleClient(); 403 | app_loop(); 404 | if (BlynkState::is(MODE_CONFIGURING) && WiFi.softAPgetStationNum() == 0) { 405 | BlynkState::set(MODE_WAIT_CONFIG); 406 | } 407 | } 408 | 409 | server.stop(); 410 | } 411 | 412 | void enterConnectNet() { 413 | BlynkState::set(MODE_CONNECTING_NET); 414 | DEBUG_PRINT(String("Connecting to WiFi: ") + configStore.wifiSSID); 415 | 416 | // Needed for setHostname to work 417 | WiFi.enableSTA(false); 418 | 419 | String hostname = getWiFiName(); 420 | hostname.replace(" ", "-"); 421 | WiFi.setHostname(hostname.c_str()); 422 | 423 | if (configStore.getFlag(CONFIG_FLAG_STATIC_IP)) { 424 | if (!WiFi.config(configStore.staticIP, 425 | configStore.staticGW, 426 | configStore.staticMask, 427 | configStore.staticDNS, 428 | configStore.staticDNS2) 429 | ) { 430 | DEBUG_PRINT("Failed to configure Static IP"); 431 | config_set_last_error(BLYNK_PROV_ERR_CONFIG); 432 | BlynkState::set(MODE_ERROR); 433 | return; 434 | } 435 | } 436 | 437 | WiFi.begin(configStore.wifiSSID, configStore.wifiPass); 438 | 439 | unsigned long timeoutMs = millis() + WIFI_NET_CONNECT_TIMEOUT; 440 | while ((timeoutMs > millis()) && (WiFi.status() != WL_CONNECTED)) 441 | { 442 | delay(10); 443 | app_loop(); 444 | 445 | if (!BlynkState::is(MODE_CONNECTING_NET)) { 446 | WiFi.disconnect(); 447 | return; 448 | } 449 | } 450 | 451 | if (WiFi.status() == WL_CONNECTED) { 452 | IPAddress localip = WiFi.localIP(); 453 | if (configStore.getFlag(CONFIG_FLAG_STATIC_IP)) { 454 | BLYNK_LOG_IP("Using Static IP: ", localip); 455 | } else { 456 | BLYNK_LOG_IP("Using Dynamic IP: ", localip); 457 | } 458 | 459 | connectNetRetries = WIFI_CLOUD_MAX_RETRIES; 460 | BlynkState::set(MODE_CONNECTING_CLOUD); 461 | } else if (--connectNetRetries <= 0) { 462 | config_set_last_error(BLYNK_PROV_ERR_NETWORK); 463 | BlynkState::set(MODE_ERROR); 464 | } 465 | } 466 | 467 | void enterConnectCloud() { 468 | BlynkState::set(MODE_CONNECTING_CLOUD); 469 | 470 | Blynk.config(configStore.cloudToken, configStore.cloudHost, configStore.cloudPort); 471 | Blynk.connect(0); 472 | 473 | unsigned long timeoutMs = millis() + WIFI_CLOUD_CONNECT_TIMEOUT; 474 | while ((timeoutMs > millis()) && 475 | (WiFi.status() == WL_CONNECTED) && 476 | (!Blynk.isTokenInvalid()) && 477 | (Blynk.connected() == false)) 478 | { 479 | delay(10); 480 | Blynk.run(); 481 | app_loop(); 482 | if (!BlynkState::is(MODE_CONNECTING_CLOUD)) { 483 | Blynk.disconnect(); 484 | return; 485 | } 486 | } 487 | 488 | if (millis() > timeoutMs) { 489 | DEBUG_PRINT("Timeout"); 490 | } 491 | 492 | if (Blynk.isTokenInvalid()) { 493 | config_set_last_error(BLYNK_PROV_ERR_TOKEN); 494 | BlynkState::set(MODE_WAIT_CONFIG); // TODO: retry after timeout 495 | } else if (WiFi.status() != WL_CONNECTED) { 496 | BlynkState::set(MODE_CONNECTING_NET); 497 | } else if (Blynk.connected()) { 498 | BlynkState::set(MODE_RUNNING); 499 | connectBlynkRetries = WIFI_CLOUD_MAX_RETRIES; 500 | 501 | if (!configStore.getFlag(CONFIG_FLAG_VALID)) { 502 | configStore.last_error = BLYNK_PROV_ERR_NONE; 503 | configStore.setFlag(CONFIG_FLAG_VALID, true); 504 | config_save(); 505 | 506 | Blynk.sendInternal("meta", "set", "Hotspot Name", getWiFiName()); 507 | } 508 | } else if (--connectBlynkRetries <= 0) { 509 | config_set_last_error(BLYNK_PROV_ERR_CLOUD); 510 | BlynkState::set(MODE_ERROR); 511 | } 512 | } 513 | 514 | void enterSwitchToSTA() { 515 | BlynkState::set(MODE_SWITCH_TO_STA); 516 | 517 | DEBUG_PRINT("Switching to STA..."); 518 | 519 | delay(1000); 520 | WiFi.mode(WIFI_OFF); 521 | delay(100); 522 | WiFi.mode(WIFI_STA); 523 | 524 | BlynkState::set(MODE_CONNECTING_NET); 525 | } 526 | 527 | void enterError() { 528 | BlynkState::set(MODE_ERROR); 529 | 530 | unsigned long timeoutMs = millis() + 10000; 531 | while (timeoutMs > millis() || g_buttonPressed) 532 | { 533 | delay(10); 534 | app_loop(); 535 | if (!BlynkState::is(MODE_ERROR)) { 536 | return; 537 | } 538 | } 539 | DEBUG_PRINT("Restarting after error."); 540 | delay(10); 541 | 542 | restartMCU(); 543 | } 544 | 545 | -------------------------------------------------------------------------------- /CoopCommand/ConfigStore.h: -------------------------------------------------------------------------------- 1 | 2 | #define CONFIG_FLAG_VALID 0x01 3 | #define CONFIG_FLAG_STATIC_IP 0x02 4 | 5 | #define BLYNK_PROV_ERR_NONE 0 // All good 6 | #define BLYNK_PROV_ERR_CONFIG 700 // Invalid config from app (malformed token,etc) 7 | #define BLYNK_PROV_ERR_NETWORK 701 // Could not connect to the router 8 | #define BLYNK_PROV_ERR_CLOUD 702 // Could not connect to the cloud 9 | #define BLYNK_PROV_ERR_TOKEN 703 // Invalid token error (after connection) 10 | #define BLYNK_PROV_ERR_INTERNAL 704 // Other issues (i.e. hardware failure) 11 | 12 | struct ConfigStore { 13 | uint32_t magic; 14 | char version[15]; 15 | uint8_t flags; 16 | 17 | char wifiSSID[34]; 18 | char wifiPass[64]; 19 | 20 | char cloudToken[34]; 21 | char cloudHost[34]; 22 | uint16_t cloudPort; 23 | 24 | uint32_t staticIP; 25 | uint32_t staticMask; 26 | uint32_t staticGW; 27 | uint32_t staticDNS; 28 | uint32_t staticDNS2; 29 | 30 | int last_error; 31 | 32 | void setFlag(uint8_t mask, bool value) { 33 | if (value) { 34 | flags |= mask; 35 | } else { 36 | flags &= ~mask; 37 | } 38 | } 39 | 40 | bool getFlag(uint8_t mask) { 41 | return (flags & mask) == mask; 42 | } 43 | } __attribute__((packed)); 44 | 45 | ConfigStore configStore; 46 | 47 | const ConfigStore configDefault = { 48 | 0x626C6E6B, 49 | BLYNK_FIRMWARE_VERSION, 50 | 0x00, 51 | 52 | "", 53 | "", 54 | 55 | "invalid token", 56 | CONFIG_DEFAULT_SERVER, 57 | CONFIG_DEFAULT_PORT, 58 | 0, 59 | BLYNK_PROV_ERR_NONE 60 | }; 61 | 62 | template 63 | void CopyString(const String& s, T(&arr)[size]) { 64 | s.toCharArray(arr, size); 65 | } 66 | 67 | static bool config_load_blnkopt() 68 | { 69 | static const char blnkopt[] = "blnkopt\0" 70 | BLYNK_PARAM_KV("ssid" , BLYNK_PARAM_PLACEHOLDER_64 71 | BLYNK_PARAM_PLACEHOLDER_64 72 | BLYNK_PARAM_PLACEHOLDER_64 73 | BLYNK_PARAM_PLACEHOLDER_64) 74 | BLYNK_PARAM_KV("host" , CONFIG_DEFAULT_SERVER) 75 | BLYNK_PARAM_KV("port" , BLYNK_TOSTRING(CONFIG_DEFAULT_PORT)) 76 | "\0"; 77 | 78 | BlynkParam prov(blnkopt+8, sizeof(blnkopt)-8-2); 79 | BlynkParam::iterator ssid = prov["ssid"]; 80 | BlynkParam::iterator pass = prov["pass"]; 81 | BlynkParam::iterator auth = prov["auth"]; 82 | BlynkParam::iterator host = prov["host"]; 83 | BlynkParam::iterator port = prov["port"]; 84 | 85 | if (!(ssid.isValid() && auth.isValid())) { 86 | return false; 87 | } 88 | 89 | // reset to defaut before loading values from blnkopt 90 | configStore = configDefault; 91 | 92 | if (ssid.isValid()) { CopyString(ssid.asStr(), configStore.wifiSSID); } 93 | if (pass.isValid()) { CopyString(pass.asStr(), configStore.wifiPass); } 94 | if (auth.isValid()) { CopyString(auth.asStr(), configStore.cloudToken); } 95 | if (host.isValid()) { CopyString(host.asStr(), configStore.cloudHost); } 96 | if (port.isValid()) { configStore.cloudPort = port.asInt(); } 97 | 98 | return true; 99 | } 100 | 101 | #include 102 | 103 | void config_load() 104 | { 105 | Preferences prefs; 106 | if (prefs.begin("blynk", true)) { // read-only 107 | memset(&configStore, 0, sizeof(configStore)); 108 | prefs.getBytes("config", &configStore, sizeof(configStore)); 109 | if (configStore.magic != configDefault.magic) { 110 | DEBUG_PRINT("Using default config."); 111 | configStore = configDefault; 112 | } 113 | } else { 114 | DEBUG_PRINT("Config read failed"); 115 | } 116 | } 117 | 118 | bool config_save() 119 | { 120 | Preferences prefs; 121 | if (prefs.begin("blynk", false)) { // writeable 122 | prefs.putBytes("config", &configStore, sizeof(configStore)); 123 | DEBUG_PRINT("Configuration stored to flash"); 124 | return true; 125 | } else { 126 | DEBUG_PRINT("Config write failed"); 127 | return false; 128 | } 129 | } 130 | 131 | bool config_init() 132 | { 133 | config_load(); 134 | return true; 135 | } 136 | 137 | void enterResetConfig() 138 | { 139 | DEBUG_PRINT("Resetting configuration!"); 140 | configStore = configDefault; 141 | config_save(); 142 | BlynkState::set(MODE_WAIT_CONFIG); 143 | } 144 | 145 | void config_set_last_error(int error) { 146 | // Only set error if not provisioned 147 | if (!configStore.getFlag(CONFIG_FLAG_VALID)) { 148 | configStore = configDefault; 149 | configStore.last_error = error; 150 | BLYNK_LOG2("Last error code: ", error); 151 | config_save(); 152 | } 153 | } 154 | 155 | -------------------------------------------------------------------------------- /CoopCommand/Console.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | extern "C" { 5 | #include "esp_partition.h" 6 | #include "esp_ota_ops.h" 7 | } 8 | 9 | BlynkConsole edgentConsole; 10 | 11 | void console_init() 12 | { 13 | #ifdef BLYNK_PRINT 14 | edgentConsole.begin(BLYNK_PRINT); 15 | #endif 16 | 17 | edgentConsole.print("\n>"); 18 | 19 | edgentConsole.addCommand("reboot", []() { 20 | edgentConsole.print(R"json({"status":"OK","msg":"rebooting wifi module"})json" "\n"); 21 | delay(100); 22 | restartMCU(); 23 | }); 24 | 25 | edgentConsole.addCommand("config", [](int argc, const char** argv) { 26 | if (argc < 1 || 0 == strcmp(argv[0], "start")) { 27 | BlynkState::set(MODE_WAIT_CONFIG); 28 | } else if (0 == strcmp(argv[0], "erase")) { 29 | BlynkState::set(MODE_RESET_CONFIG); 30 | } 31 | }); 32 | 33 | edgentConsole.addCommand("devinfo", []() { 34 | edgentConsole.printf( 35 | R"json({"name":"%s","board":"%s","tmpl_id":"%s","fw_type":"%s","fw_ver":"%s"})json" "\n", 36 | getWiFiName().c_str(), 37 | BLYNK_TEMPLATE_NAME, 38 | BLYNK_TEMPLATE_ID, 39 | BLYNK_FIRMWARE_TYPE, 40 | BLYNK_FIRMWARE_VERSION 41 | ); 42 | }); 43 | 44 | edgentConsole.addCommand("connect", [](int argc, const char** argv) { 45 | if (argc < 2) { 46 | edgentConsole.print(R"json({"status":"error","msg":"invalid arguments. expected: "})json" "\n"); 47 | return; 48 | } 49 | String auth = argv[0]; 50 | String ssid = argv[1]; 51 | String pass = (argc >= 3) ? argv[2] : ""; 52 | 53 | if (auth.length() != 32) { 54 | edgentConsole.print(R"json({"status":"error","msg":"invalid token size"})json" "\n"); 55 | return; 56 | } 57 | 58 | edgentConsole.print(R"json({"status":"OK","msg":"trying to connect..."})json" "\n"); 59 | 60 | configStore = configDefault; 61 | CopyString(ssid, configStore.wifiSSID); 62 | CopyString(pass, configStore.wifiPass); 63 | CopyString(auth, configStore.cloudToken); 64 | 65 | BlynkState::set(MODE_SWITCH_TO_STA); 66 | }); 67 | 68 | edgentConsole.addCommand("wifi", [](int argc, const char* argv[]) { 69 | if (argc < 1 || 0 == strcmp(argv[0], "show")) { 70 | edgentConsole.printf( 71 | "mac:%s ip:%s (%s [%s] %ddBm)\n", 72 | getWiFiMacAddress().c_str(), 73 | WiFi.localIP().toString().c_str(), 74 | getWiFiNetworkSSID().c_str(), 75 | getWiFiNetworkBSSID().c_str(), 76 | WiFi.RSSI() 77 | ); 78 | } else if (0 == strcmp(argv[0], "scan")) { 79 | int found = WiFi.scanNetworks(); 80 | for (int i = 0; i < found; i++) { 81 | bool current = (WiFi.SSID(i) == WiFi.SSID()); 82 | edgentConsole.printf( 83 | "%s %s [%s] %s ch:%d rssi:%d\n", 84 | (current ? "*" : " "), WiFi.SSID(i).c_str(), 85 | macToString(WiFi.BSSID(i)).c_str(), 86 | wifiSecToStr(WiFi.encryptionType(i)), 87 | WiFi.channel(i), WiFi.RSSI(i) 88 | ); 89 | } 90 | WiFi.scanDelete(); 91 | } 92 | }); 93 | 94 | edgentConsole.addCommand("firmware", [](int argc, const char** argv) { 95 | if (argc < 1 || 0 == strcmp(argv[0], "info")) { 96 | unsigned sketchSize = ESP.getSketchSize(); 97 | 98 | edgentConsole.printf(" Version: %s (build %s)\n", BLYNK_FIRMWARE_VERSION, __DATE__ " " __TIME__); 99 | edgentConsole.printf(" Type: %s\n", BLYNK_FIRMWARE_TYPE); 100 | edgentConsole.printf(" Platform: %s\n", BLYNK_INFO_DEVICE); 101 | edgentConsole.printf(" SDK: %s\n", ESP.getSdkVersion()); 102 | 103 | if (const esp_partition_t* running = esp_ota_get_running_partition()) { 104 | edgentConsole.printf(" Partition: %s (%dK)\n", running->label, running->size / 1024); 105 | edgentConsole.printf(" App size: %dK (%d%%)\n", sketchSize/1024, (sketchSize*100)/(running->size)); 106 | edgentConsole.printf(" App MD5: %s\n", ESP.getSketchMD5().c_str()); 107 | } 108 | 109 | } else if (0 == strcmp(argv[0], "rollback")) { 110 | if (Update.rollBack()) { 111 | edgentConsole.print(R"json({"status":"ok"})json" "\n"); 112 | edgentTimer.setTimeout(50, restartMCU); 113 | } else { 114 | edgentConsole.print(R"json({"status":"error"})json" "\n"); 115 | } 116 | } 117 | }); 118 | 119 | edgentConsole.addCommand("status", [](int argc, const char** argv) { 120 | const int64_t t = esp_timer_get_time() / 1000000; 121 | unsigned secs = t % BLYNK_SECS_PER_MIN; 122 | unsigned mins = (t / BLYNK_SECS_PER_MIN) % BLYNK_SECS_PER_MIN; 123 | unsigned hrs = (t % BLYNK_SECS_PER_DAY) / BLYNK_SECS_PER_HOUR; 124 | unsigned days = t / BLYNK_SECS_PER_DAY; 125 | 126 | edgentConsole.printf(" Uptime: %dd %dh %dm %ds\n", days, hrs, mins, secs); 127 | edgentConsole.printf(" Chip: %s rev %d\n", ESP.getChipModel(), ESP.getChipRevision()); 128 | edgentConsole.printf(" Flash: %dK\n", ESP.getFlashChipSize() / 1024); 129 | edgentConsole.printf(" Stack unused: %d\n", uxTaskGetStackHighWaterMark(NULL)); 130 | edgentConsole.printf(" Heap free: %d / %d\n", ESP.getFreeHeap(), ESP.getHeapSize()); 131 | edgentConsole.printf(" max alloc: %d\n", ESP.getMaxAllocHeap()); 132 | edgentConsole.printf(" min free: %d\n", ESP.getMinFreeHeap()); 133 | if (ESP.getPsramSize()) { 134 | edgentConsole.printf(" PSRAM free: %d / %d\n", ESP.getFreePsram(), ESP.getPsramSize()); 135 | } 136 | #ifdef BLYNK_FS 137 | uint32_t fs_total = BLYNK_FS.totalBytes(); 138 | edgentConsole.printf(" FS free: %d / %d\n", (fs_total-BLYNK_FS.usedBytes()), fs_total); 139 | #endif 140 | }); 141 | 142 | #ifdef BLYNK_FS 143 | 144 | edgentConsole.addCommand("ls", [](int argc, const char** argv) { 145 | const char* path = (argc < 1) ? "/" : argv[0]; 146 | File rootDir = BLYNK_FS.open(path); 147 | while (File f = rootDir.openNextFile()) { 148 | #if defined(BLYNK_USE_SPIFFS) && (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 0, 0)) 149 | String fn = f.name(); 150 | #else 151 | String fn = f.path(); 152 | #endif 153 | 154 | MD5Builder md5; 155 | md5.begin(); 156 | md5.addStream(f, f.size()); 157 | md5.calculate(); 158 | String md5str = md5.toString(); 159 | 160 | edgentConsole.printf("%8d %-24s %s\n", 161 | f.size(), fn.c_str(), 162 | md5str.substring(0,8).c_str()); 163 | } 164 | }); 165 | 166 | edgentConsole.addCommand("rm", [](int argc, const char** argv) { 167 | if (argc < 1) return; 168 | 169 | for (int i=0; i 32 | #include 33 | #include 34 | 35 | // Blynk Widget Setups 36 | 37 | WidgetLED led1(V1); 38 | WidgetLED led2(V2); 39 | WidgetLED led3(V3); 40 | WidgetLED led4(V4); 41 | WidgetLED led5(V14); 42 | 43 | // Blynk Timer 44 | 45 | BlynkTimer timer; 46 | 47 | // DS18B20 Sensor Setup 48 | 49 | #define ONE_WIRE_BUS 25 // Pin for One-Wire Bus 50 | OneWire oneWire(ONE_WIRE_BUS); // Initialize One-Wire Bus 51 | DallasTemperature sensors(&oneWire); // Initialize DS18B20 52 | 53 | //DHT Setup 54 | 55 | #define DHTPIN 32 // Pin for DHT sensor 56 | #define DHTTYPE DHT22 // DHT 22 (AM2302) 57 | DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor 58 | 59 | // Photocell Pin 60 | 61 | const int photocellPin = 34; // analog pin for photocell 62 | 63 | // Battery Voltage Monitor Pin 64 | 65 | const int batteryPin = 36; // analog pin for battery voltage monitor 66 | 67 | // Door Limit Switches 68 | 69 | const int bottomSwitchPin = 26; // bottom switch is connected to pin 26 70 | const int topSwitchPin = 27; // top switch is connected to pin 27 71 | 72 | //Door Motor Driver Pins 73 | 74 | const int directionCloseCoopDoorMotorB = 22; // direction close motor b - pin 22 75 | const int directionOpenCoopDoorMotorB = 23; // direction open motor b - pin 23 76 | 77 | // OutPuts 78 | const int layLightRelay = 4; // output pin controlling lay light MOSFET 79 | const int fanRelay = 16; // output pin controlling ventilation fan MOSFET 80 | const int heatRelay = 17; // output pin controlling water heater MOSFET 81 | const int output4 = 18; // Spare Output MOSFET 82 | 83 | 84 | // Sensor Variables 85 | bool doorOpen = false; // is the coop door open 86 | bool doorClosed = false; // is the door closed 87 | bool doorOpenMove = false; // is the door opening? 88 | bool doorCloseMove = false; // is the door closing? 89 | int topSwitchState; // Current state (open/closed) of the top limit switch 90 | int bottomSwitchState; // Current state (open/closed) of the bottom limit switch 91 | bool doorSensor = true; // is the door in automatic or manual mode 92 | bool heaterOn = true; // is the water heater function running 93 | bool nightTimer = false; // is it night time 94 | bool layLightOn = true; // is the Lay Light time monitoring system on 95 | bool nightLightOn = false; // is the Night Light on 96 | int coopTemp = 0; // Interior Coop Temperature Reading 97 | int closeDoor = 5; // Light level to close coop door (user editable) 98 | int openDoor = closeDoor + 20; // Light level to open coop door 99 | int hotTemp = 30; // Temperature to turn on Ventilation Fan Relay (user editable) 100 | int coldTemp = 3; // Temperature to turn on Water Heat MOSFET (user editable) 101 | float waterTemp = 0; // Water Tempterature Reading 102 | float hum; // Stores humidity value from DHT22 103 | float temp; // Stores temperature value from DHT22 104 | int photocellReading; // analog reading of the photocell 105 | int photocellReadingLevel = '2'; // photocell reading levels (night, light, twilight) 106 | float batteryVoltage; // battery voltage reading mapped 0-100% 107 | int batteryVoltageRaw; // raw battery voltage reading 108 | int batteryPercent; 109 | 110 | // Timer Variables 111 | unsigned long layLightTimer = 36000000; // Timer to make sure at least 14 hours of "daylight" 112 | unsigned long lastDayLightReadingTime = 0; // timer to keep track of how long it has been night 113 | unsigned long nightLightDelay = 300000; // 5 minute timer to turn on the coop light if light switch button is pushed and it is night. 114 | unsigned long lastNightLightTime = 0; // the last time the night light button was pushed 115 | unsigned long photocellReadingDelay = 600000; // 600000 = 10 minute 116 | unsigned long lastPhotocellReadingTime = 0; // the last time the photocell was read 117 | 118 | void setup() 119 | { 120 | Serial.begin(115200); // Start Serial Comms 121 | delay(100); 122 | dht.begin(); // Start DHT sensor 123 | sensors.begin(); // Start DS18B20 Sensor 124 | BlynkEdgent.begin(); // Start Edgent 125 | 126 | // Set Pin Modes 127 | pinMode(photocellPin, INPUT); // Set Pinmode for photocell sensor 128 | pinMode(batteryPin, INPUT); // Set Pinmode for battery voltage divider sensor 129 | pinMode(topSwitchPin, INPUT); // Set Pinmode for top door limit switch 130 | pinMode(bottomSwitchPin, INPUT); // Set Pinmode for bottom door limit switch 131 | pinMode(layLightRelay, OUTPUT); // Set Pinmode for LayLight Output 132 | pinMode(fanRelay, OUTPUT); // Set Pinmode for Ventilation Fan Output 133 | pinMode(heatRelay, OUTPUT); // Set Pinmode for Water Heater Output 134 | pinMode(directionCloseCoopDoorMotorB, OUTPUT); // Set Pinmode for Motor Driver Output1 135 | pinMode(directionOpenCoopDoorMotorB, OUTPUT); // Set Pinmode for Motor Driver Output2 136 | 137 | // Initial Photocell reading 138 | photocellReading = analogRead(photocellPin); 139 | photocellReading = map(photocellReading, 0, 4000, 0, 100); // Map reading to 0-100 140 | 141 | // Ensure Mosfets are pulled low 142 | digitalWrite(layLightRelay, LOW); 143 | digitalWrite(fanRelay, LOW); 144 | digitalWrite(heatRelay, LOW); 145 | digitalWrite(output4, LOW); 146 | readSwitches(); // Check Door Switchs 147 | 148 | // Set Timers 149 | timer.setInterval(1000,blynkData); 150 | } 151 | 152 | // Function to Control Coop Light 153 | void layLight() { 154 | if (layLightOn) { 155 | if (!nightTimer) { // if it is not dark 156 | lastDayLightReadingTime = millis(); 157 | digitalWrite(layLightRelay, LOW); // turn off the lay light 158 | Blynk.virtualWrite(V14, LOW); // Turn off Blynk Widge LED 159 | } 160 | else { // if it is dark 161 | if ((unsigned long)(millis() - lastDayLightReadingTime) >= layLightTimer) { //if it has been dark more than 14 hours (or whatever the timer is 162 | digitalWrite(layLightRelay, HIGH); // turn on the lay light 163 | Blynk.virtualWrite(V14, HIGH); // turn on Blynk Widget LED 164 | } 165 | } 166 | } 167 | 168 | if (nightLightOn) { // if someone wants the light on 169 | digitalWrite(layLightRelay, HIGH); // Turn on the light 170 | Blynk.virtualWrite(V14, HIGH); // Turn on Blynk Widge LED 171 | // Set Timeout to shut light off after 5 minutes 172 | timer.setTimeout(300000, []() 173 | { 174 | digitalWrite(layLightRelay, LOW); // Turn off the light 175 | Blynk.virtualWrite(V14, LOW); // Turn on Blynk Widge LED 176 | nightLightOn = false; // Reset the flag 177 | }); 178 | } 179 | } 180 | 181 | // Function to send data to Blynk 182 | void blynkData() 183 | { 184 | 185 | // Send Light Value to Blynk 186 | Blynk.virtualWrite(V8, photocellReading); 187 | 188 | // Send Battery Voltages to Blynk 189 | Blynk.virtualWrite(V23, batteryVoltageRaw); 190 | Blynk.virtualWrite(V9, batteryVoltage); 191 | Blynk.virtualWrite(V24, batteryPercent); 192 | 193 | // Send Water Temp to Blynk 194 | Blynk.virtualWrite(V5, waterTemp); 195 | 196 | // Send DHT22 Values to Blynk 197 | Blynk.virtualWrite(V13, hum); 198 | Blynk.virtualWrite(V0, temp); 199 | 200 | // Send control settings to Blynk 201 | Blynk.virtualWrite(V20, hotTemp); 202 | Blynk.virtualWrite(V21, coldTemp); 203 | Blynk.virtualWrite(V22, closeDoor); 204 | 205 | // Blynk Widget LED control based on Coop Door Status 206 | if (doorOpen) { 207 | Blynk.virtualWrite(V1, HIGH); 208 | } 209 | else { 210 | Blynk.virtualWrite(V1, LOW); 211 | } 212 | if (doorClosed) { 213 | Blynk.virtualWrite(V2, HIGH); 214 | } 215 | else { 216 | Blynk.virtualWrite(V2, LOW); 217 | } 218 | if (doorOpenMove) { 219 | Blynk.virtualWrite(V3, HIGH); 220 | } 221 | else { 222 | Blynk.virtualWrite(V3, LOW); 223 | } 224 | if (doorCloseMove) { 225 | Blynk.virtualWrite(V4, HIGH); 226 | } 227 | else { 228 | Blynk.virtualWrite(V4, LOW); 229 | } 230 | 231 | } 232 | 233 | // Function to read sensors as well as send data to Blynk 234 | void readSensor() 235 | { 236 | // Read the battery voltage 237 | 238 | batteryVoltageRaw = analogRead(batteryPin); 239 | batteryVoltage = (batteryVoltageRaw * 0.003241); // Map reading to 12v reference 240 | batteryPercent = map(batteryVoltageRaw, 3708, 3920, 0, 100); // Map reading to 0-100 241 | 242 | // Read DS18B20 Water Temp Sensor 243 | sensors.requestTemperatures(); 244 | waterTemp = sensors.getTempCByIndex(0); 245 | // If Reading is -127 sensor is faulty or not connected, default to 0 value and turn off water heat ability 246 | if (waterTemp == -127) { 247 | waterTemp = 0; 248 | heaterOn = false; 249 | } 250 | // If the sensor reads literally any other value, sensor is working, heater is enabled 251 | else { 252 | heaterOn = true; 253 | } 254 | //Read DHT22 255 | hum = dht.readHumidity(); 256 | temp = dht.readTemperature(); 257 | } 258 | 259 | // Function to read photocell and send commands to door function at proper intervals 260 | void doorControl() 261 | { 262 | photocellReading = analogRead(photocellPin); // Read the photocell 263 | photocellReading = map(photocellReading, 0, 4000, 0, 100); // Map photocell readings to 0-100 value 264 | if ((unsigned long)(millis() - lastPhotocellReadingTime) >= photocellReadingDelay) { 265 | if (photocellReading >= 0 && photocellReading <= closeDoor) { // Night Setting based on user or default selected low light trigger 266 | // If it is "night" set 20 minute timer before door closes to make sure chickens are all inside 267 | if (doorSensor) { 268 | timer.setTimeout(1200000, []() 269 | { 270 | photocellReadingLevel = '1'; 271 | }); 272 | } 273 | nightTimer = true; // Tell system to enable LayLight timer monitoring 274 | } 275 | else if (photocellReading >= closeDoor && photocellReading <= openDoor) { // Twighlight setting 276 | if (doorSensor) { 277 | photocellReadingLevel = '2'; 278 | nightTimer = false; 279 | } 280 | } 281 | else if (photocellReading >= openDoor) { //Daylight Setting 282 | // If "daytime", set coop door control to open 283 | if (doorSensor) { 284 | photocellReadingLevel = '3'; 285 | nightTimer = false; 286 | } 287 | } 288 | } 289 | } 290 | 291 | // Function to control water heater 292 | void waterHeat() 293 | { 294 | if (heaterOn) { 295 | //If sensor fails or becomes disconnected, turn off the heater and zero the sensor 296 | if (waterTemp == -127) { 297 | digitalWrite(heatRelay, LOW); // Turn off the water heater 298 | Blynk.virtualWrite(V15, LOW); 299 | waterTemp = 0; 300 | heaterOn = false; 301 | } 302 | else if (waterTemp >= (coldTemp + 3)) { // If the temperature is 3 degrees above the trigger temp 303 | digitalWrite(heatRelay, LOW); // Turn off the water heater 304 | Blynk.virtualWrite(V15, LOW); // Turn off the Blynk LED 305 | } 306 | else if (waterTemp < coldTemp) { // If the temperature is below the cold temperature 307 | digitalWrite(heatRelay, HIGH); // Turn on the water heater 308 | Blynk.virtualWrite(V15, HIGH); // Turn on the Blynk LED 309 | } 310 | } 311 | else { 312 | digitalWrite(heatRelay, LOW); // Turn off the water heater 313 | Blynk.virtualWrite(V15, LOW); // Turn off the Blynk LED 314 | } 315 | 316 | } 317 | 318 | // Function to control ventilation fan 319 | void ventFan() 320 | { 321 | if (coopTemp >= hotTemp) { // If the temperature is above the Hot temperature 322 | digitalWrite(fanRelay, HIGH); // Turn on the ventilation fan 323 | Blynk.virtualWrite(V16, HIGH); // Turn on the Blynk LED 324 | } 325 | else if (coopTemp < (hotTemp - 2)) { // If the temperature has been lowered two degrees 326 | digitalWrite(fanRelay, LOW); // Turn off the ventilation fan 327 | Blynk.virtualWrite(V16, LOW); // Turn off the Blynk LED 328 | } 329 | } 330 | 331 | // Function to check limit switches 332 | void readSwitches() { 333 | topSwitchState = (digitalRead(topSwitchPin)); // Check the state of the top limit switch 334 | if (topSwitchState == 0) { 335 | doorOpen = true; 336 | } 337 | bottomSwitchState = (digitalRead(bottomSwitchPin)); // Check the state of the bottom limit switch 338 | if (bottomSwitchState == 0) { 339 | doorClosed = true; 340 | } 341 | } 342 | 343 | // stop the coop door motor and put the motor driver IC to sleep (power saving) 344 | void stopCoopDoorMotorB() { 345 | digitalWrite (directionCloseCoopDoorMotorB, LOW); // turn off motor close direction 346 | digitalWrite (directionOpenCoopDoorMotorB, LOW); // turn off motor open direction 347 | } 348 | 349 | // close the coop door motor 350 | void closeCoopDoorMotorB() { 351 | if (bottomSwitchState == 1) { //if the bottom reed switch is open 352 | digitalWrite (directionCloseCoopDoorMotorB, HIGH); // turn on motor close direction 353 | digitalWrite (directionOpenCoopDoorMotorB, LOW); // turn off motor open direction 354 | doorOpen = false; 355 | doorClosed = false; 356 | doorCloseMove = true; 357 | doorOpenMove = false; 358 | } 359 | else { // if bottom reed switch circuit is closed 360 | stopCoopDoorMotorB(); 361 | doorClosed = true; 362 | doorCloseMove = false; 363 | doorOpenMove = false; 364 | } 365 | } 366 | 367 | // open the coop door 368 | void openCoopDoorMotorB() { 369 | if (topSwitchState == 1) { //if the top reed switch is open 370 | digitalWrite(directionCloseCoopDoorMotorB, LOW); // turn off motor close direction 371 | digitalWrite(directionOpenCoopDoorMotorB, HIGH); // turn on motor open direction 372 | doorOpen = false; 373 | doorClosed = false; 374 | doorOpenMove = true; 375 | doorCloseMove = false; 376 | } 377 | else { // if top reed switch circuit is closed 378 | stopCoopDoorMotorB(); 379 | doorOpen = true; 380 | doorOpenMove = false; 381 | doorCloseMove = false; 382 | } 383 | } 384 | 385 | // Function to run the coop door 386 | void doCoopDoor() { 387 | if (photocellReadingLevel == '1') { // if it's dark 388 | readSwitches(); 389 | closeCoopDoorMotorB(); // close the door 390 | } 391 | else if (photocellReadingLevel == '3') { // if it's light 392 | readSwitches(); 393 | openCoopDoorMotorB(); // Open the door 394 | } 395 | else if (photocellReadingLevel == '2') { // if it's twilight 396 | readSwitches(); 397 | stopCoopDoorMotorB(); 398 | } 399 | } 400 | 401 | void coopOperation() { 402 | doCoopDoor(); 403 | readSensor(); 404 | doorControl(); 405 | ventFan(); 406 | waterHeat(); 407 | layLight(); 408 | } 409 | 410 | // Door Override Open 411 | BLYNK_WRITE (V7) 412 | { 413 | photocellReadingLevel = '3'; 414 | } 415 | 416 | // Door Override Closed 417 | BLYNK_WRITE (V6) 418 | { 419 | photocellReadingLevel = '1'; 420 | } 421 | 422 | // Door in Auto or Manual Mode 423 | BLYNK_WRITE (V10) 424 | { 425 | if (param.asInt() == 0) { 426 | doorSensor = false; 427 | } 428 | else { 429 | doorSensor = true; 430 | } 431 | } 432 | 433 | // LayLight On or Off 434 | BLYNK_WRITE (V11) 435 | { 436 | if (param.asInt() == 0) { 437 | layLightOn = false; 438 | nightTimer = false; 439 | digitalWrite(layLightRelay, LOW); // turn off the lay light 440 | } 441 | else { 442 | layLightOn = true; 443 | } 444 | } 445 | 446 | // Turn on the Night Light 447 | BLYNK_WRITE (V12) 448 | { 449 | nightLightOn = true; 450 | } 451 | 452 | // Adjust Ventilation Fan Temperature 453 | BLYNK_WRITE (V17) 454 | { 455 | hotTemp = param.asInt(); 456 | } 457 | 458 | // Adjust Water Heater Temp 459 | BLYNK_WRITE (V18) 460 | { 461 | coldTemp = param.asInt(); 462 | } 463 | 464 | // Adjust Door Close Light Level 465 | BLYNK_WRITE (V19) 466 | { 467 | closeDoor = param.asInt(); 468 | openDoor = closeDoor + 20; 469 | } 470 | 471 | 472 | // Run the code 473 | void loop() { 474 | BlynkEdgent.run(); 475 | timer.run(); 476 | coopOperation(); 477 | } -------------------------------------------------------------------------------- /CoopCommand/Indicator.h: -------------------------------------------------------------------------------- 1 | 2 | #if defined(BOARD_LED_PIN_WS2812) 3 | #include // Library: https://github.com/adafruit/Adafruit_NeoPixel 4 | 5 | Adafruit_NeoPixel rgb = Adafruit_NeoPixel(1, BOARD_LED_PIN_WS2812, NEO_GRB + NEO_KHZ800); 6 | #endif 7 | 8 | void indicator_run(); 9 | 10 | #if !defined(BOARD_LED_BRIGHTNESS) 11 | #define BOARD_LED_BRIGHTNESS 255 12 | #endif 13 | 14 | #if defined(BOARD_LED_PIN_WS2812) || defined(BOARD_LED_PIN_R) 15 | #define BOARD_LED_IS_RGB 16 | #endif 17 | 18 | #define DIMM(x) ((uint32_t)(x)*(BOARD_LED_BRIGHTNESS)/255) 19 | #define RGB(r,g,b) (DIMM(r) << 16 | DIMM(g) << 8 | DIMM(b) << 0) 20 | #define TO_PWM(x) ((uint32_t)(x)*(BOARD_PWM_MAX)/255) 21 | 22 | class Indicator { 23 | public: 24 | 25 | enum Colors { 26 | COLOR_BLACK = RGB(0x00, 0x00, 0x00), 27 | COLOR_WHITE = RGB(0xFF, 0xFF, 0xE7), 28 | COLOR_BLUE = RGB(0x0D, 0x36, 0xFF), 29 | COLOR_BLYNK = RGB(0x2E, 0xFF, 0xB9), 30 | COLOR_RED = RGB(0xFF, 0x10, 0x08), 31 | COLOR_MAGENTA = RGB(0xA7, 0x00, 0xFF), 32 | }; 33 | 34 | Indicator() { 35 | } 36 | 37 | void init() { 38 | m_Counter = 0; 39 | initLED(); 40 | } 41 | 42 | uint32_t run() { 43 | State currState = BlynkState::get(); 44 | 45 | // Reset counter if indicator state changes 46 | if (m_PrevState != currState) { 47 | m_PrevState = currState; 48 | m_Counter = 0; 49 | } 50 | 51 | const long t = millis(); 52 | if (g_buttonPressed) { 53 | if (t - g_buttonPressTime > BUTTON_HOLD_TIME_ACTION) { return beatLED(COLOR_WHITE, (int[]){ 100, 100 }); } 54 | if (t - g_buttonPressTime > BUTTON_HOLD_TIME_INDICATION) { return waveLED(COLOR_WHITE, 1000); } 55 | } 56 | switch (currState) { 57 | case MODE_RESET_CONFIG: 58 | case MODE_WAIT_CONFIG: return beatLED(COLOR_BLUE, (int[]){ 50, 500 }); 59 | case MODE_CONFIGURING: return beatLED(COLOR_BLUE, (int[]){ 200, 200 }); 60 | case MODE_CONNECTING_NET: return beatLED(COLOR_BLYNK, (int[]){ 50, 500 }); 61 | case MODE_CONNECTING_CLOUD: return beatLED(COLOR_BLYNK, (int[]){ 100, 100 }); 62 | case MODE_RUNNING: return waveLED(COLOR_BLYNK, 5000); 63 | case MODE_OTA_UPGRADE: return beatLED(COLOR_MAGENTA, (int[]){ 50, 50 }); 64 | default: return beatLED(COLOR_RED, (int[]){ 80, 100, 80, 1000 } ); 65 | } 66 | } 67 | 68 | protected: 69 | 70 | /* 71 | * LED drivers 72 | */ 73 | 74 | #if defined(BOARD_LED_PIN_WS2812) // Addressable, NeoPixel RGB LED 75 | 76 | void initLED() { 77 | rgb.begin(); 78 | setRGB(COLOR_BLACK); 79 | } 80 | 81 | void setRGB(uint32_t color) { 82 | rgb.setPixelColor(0, color); 83 | rgb.show(); 84 | } 85 | 86 | #elif defined(BOARD_LED_PIN_R) // Normal RGB LED (common anode or common cathode) 87 | 88 | void initLED() { 89 | ledcAttachPin(BOARD_LED_PIN_R, BOARD_LEDC_CHANNEL_1); 90 | ledcAttachPin(BOARD_LED_PIN_G, BOARD_LEDC_CHANNEL_2); 91 | ledcAttachPin(BOARD_LED_PIN_B, BOARD_LEDC_CHANNEL_3); 92 | 93 | ledcSetup(BOARD_LEDC_CHANNEL_1, BOARD_LEDC_BASE_FREQ, BOARD_LEDC_TIMER_BITS); 94 | ledcSetup(BOARD_LEDC_CHANNEL_2, BOARD_LEDC_BASE_FREQ, BOARD_LEDC_TIMER_BITS); 95 | ledcSetup(BOARD_LEDC_CHANNEL_3, BOARD_LEDC_BASE_FREQ, BOARD_LEDC_TIMER_BITS); 96 | } 97 | 98 | void setRGB(uint32_t color) { 99 | uint8_t r = (color & 0xFF0000) >> 16; 100 | uint8_t g = (color & 0x00FF00) >> 8; 101 | uint8_t b = (color & 0x0000FF); 102 | #if BOARD_LED_INVERSE 103 | ledcWrite(BOARD_LEDC_CHANNEL_1, TO_PWM(255 - r)); 104 | ledcWrite(BOARD_LEDC_CHANNEL_2, TO_PWM(255 - g)); 105 | ledcWrite(BOARD_LEDC_CHANNEL_3, TO_PWM(255 - b)); 106 | #else 107 | ledcWrite(BOARD_LEDC_CHANNEL_1, TO_PWM(r)); 108 | ledcWrite(BOARD_LEDC_CHANNEL_2, TO_PWM(g)); 109 | ledcWrite(BOARD_LEDC_CHANNEL_3, TO_PWM(b)); 110 | #endif 111 | } 112 | 113 | #elif defined(BOARD_LED_PIN) // Single color LED 114 | 115 | void initLED() { 116 | ledcSetup(BOARD_LEDC_CHANNEL_1, BOARD_LEDC_BASE_FREQ, BOARD_LEDC_TIMER_BITS); 117 | ledcAttachPin(BOARD_LED_PIN, BOARD_LEDC_CHANNEL_1); 118 | } 119 | 120 | void setLED(uint32_t color) { 121 | #if BOARD_LED_INVERSE 122 | ledcWrite(BOARD_LEDC_CHANNEL_1, TO_PWM(255 - color)); 123 | #else 124 | ledcWrite(BOARD_LEDC_CHANNEL_1, TO_PWM(color)); 125 | #endif 126 | } 127 | 128 | #else 129 | 130 | #warning Invalid LED configuration. 131 | 132 | void initLED() { 133 | } 134 | 135 | void setLED(uint32_t color) { 136 | } 137 | 138 | #endif 139 | 140 | /* 141 | * Animations 142 | */ 143 | 144 | uint32_t skipLED() { 145 | return 20; 146 | } 147 | 148 | #if defined(BOARD_LED_IS_RGB) 149 | 150 | template 151 | uint32_t beatLED(uint32_t onColor, const T& beat) { 152 | const uint8_t cnt = sizeof(beat)/sizeof(beat[0]); 153 | setRGB((m_Counter % 2 == 0) ? onColor : (uint32_t)COLOR_BLACK); 154 | uint32_t next = beat[m_Counter % cnt]; 155 | m_Counter = (m_Counter+1) % cnt; 156 | return next; 157 | } 158 | 159 | uint32_t waveLED(uint32_t colorMax, unsigned breathePeriod) { 160 | uint8_t redMax = (colorMax & 0xFF0000) >> 16; 161 | uint8_t greenMax = (colorMax & 0x00FF00) >> 8; 162 | uint8_t blueMax = (colorMax & 0x0000FF); 163 | 164 | // Brightness will rise from 0 to 128, then fall back to 0 165 | uint8_t brightness = (m_Counter < 128) ? m_Counter : 255 - m_Counter; 166 | 167 | // Multiply our three colors by the brightness: 168 | redMax *= ((float)brightness / 128.0); 169 | greenMax *= ((float)brightness / 128.0); 170 | blueMax *= ((float)brightness / 128.0); 171 | // And turn the LED to that color: 172 | setRGB((redMax << 16) | (greenMax << 8) | blueMax); 173 | 174 | // This function relies on the 8-bit, unsigned m_Counter rolling over. 175 | m_Counter = (m_Counter+1) % 256; 176 | return breathePeriod / 256; 177 | } 178 | 179 | #else 180 | 181 | template 182 | uint32_t beatLED(uint32_t, const T& beat) { 183 | const uint8_t cnt = sizeof(beat)/sizeof(beat[0]); 184 | setLED((m_Counter % 2 == 0) ? BOARD_LED_BRIGHTNESS : 0); 185 | uint32_t next = beat[m_Counter % cnt]; 186 | m_Counter = (m_Counter+1) % cnt; 187 | return next; 188 | } 189 | 190 | uint32_t waveLED(uint32_t, unsigned breathePeriod) { 191 | uint32_t brightness = (m_Counter < 128) ? m_Counter : 255 - m_Counter; 192 | 193 | setLED(DIMM(brightness*2)); 194 | 195 | // This function relies on the 8-bit, unsigned m_Counter rolling over. 196 | m_Counter = (m_Counter+1) % 256; 197 | return breathePeriod / 256; 198 | } 199 | 200 | #endif 201 | 202 | private: 203 | uint8_t m_Counter; 204 | State m_PrevState; 205 | }; 206 | 207 | Indicator indicator; 208 | 209 | /* 210 | * Animation timers 211 | */ 212 | 213 | #if defined(USE_TICKER) 214 | 215 | #include 216 | 217 | Ticker blinker; 218 | 219 | void indicator_run() { 220 | uint32_t returnTime = indicator.run(); 221 | if (returnTime) { 222 | blinker.attach_ms(returnTime, indicator_run); 223 | } 224 | } 225 | 226 | void indicator_init() { 227 | indicator.init(); 228 | blinker.attach_ms(100, indicator_run); 229 | } 230 | 231 | #elif defined(USE_PTHREAD) 232 | 233 | #include 234 | 235 | pthread_t blinker; 236 | 237 | void* indicator_thread(void*) { 238 | while (true) { 239 | uint32_t returnTime = indicator.run(); 240 | returnTime = BlynkMathClamp(returnTime, 1, 10000); 241 | vTaskDelay(returnTime); 242 | } 243 | } 244 | 245 | void indicator_init() { 246 | indicator.init(); 247 | pthread_create(&blinker, NULL, indicator_thread, NULL); 248 | } 249 | 250 | #elif defined(USE_TIMER_ONE) 251 | 252 | #include 253 | 254 | void indicator_run() { 255 | uint32_t returnTime = indicator.run(); 256 | if (returnTime) { 257 | Timer1.initialize(returnTime*1000); 258 | } 259 | } 260 | 261 | void indicator_init() { 262 | indicator.init(); 263 | Timer1.initialize(100*1000); 264 | Timer1.attachInterrupt(indicator_run); 265 | } 266 | 267 | #elif defined(USE_TIMER_THREE) 268 | 269 | #include 270 | 271 | void indicator_run() { 272 | uint32_t returnTime = indicator.run(); 273 | if (returnTime) { 274 | Timer3.initialize(returnTime*1000); 275 | } 276 | } 277 | 278 | void indicator_init() { 279 | indicator.init(); 280 | Timer3.initialize(100*1000); 281 | Timer3.attachInterrupt(indicator_run); 282 | } 283 | 284 | #elif defined(USE_TIMER_FIVE) 285 | 286 | #include // Library: https://github.com/michael71/Timer5 287 | 288 | int indicator_counter = -1; 289 | void indicator_run() { 290 | indicator_counter -= 10; 291 | if (indicator_counter < 0) { 292 | indicator_counter = indicator.run(); 293 | } 294 | } 295 | 296 | void indicator_init() { 297 | indicator.init(); 298 | MyTimer5.begin(1000/10); 299 | MyTimer5.attachInterrupt(indicator_run); 300 | MyTimer5.start(); 301 | } 302 | 303 | #else 304 | 305 | #warning LED indicator needs a functional timer! 306 | 307 | void indicator_run() {} 308 | void indicator_init() {} 309 | 310 | #endif 311 | 312 | -------------------------------------------------------------------------------- /CoopCommand/OTA.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | String overTheAirURL; 7 | 8 | extern BlynkTimer edgentTimer; 9 | 10 | BLYNK_WRITE(InternalPinOTA) { 11 | overTheAirURL = param.asString(); 12 | 13 | edgentTimer.setTimeout(2000L, [](){ 14 | // Start OTA 15 | Blynk.logEvent("sys_ota", "OTA started"); 16 | 17 | // Disconnect, not to interfere with OTA process 18 | Blynk.disconnect(); 19 | 20 | BlynkState::set(MODE_OTA_UPGRADE); 21 | }); 22 | } 23 | 24 | void enterOTA() { 25 | BlynkState::set(MODE_OTA_UPGRADE); 26 | 27 | DEBUG_PRINT(String("Firmware update URL: ") + overTheAirURL); 28 | 29 | HTTPClient http; 30 | http.begin(overTheAirURL); 31 | 32 | const char* headerkeys[] = { "x-MD5" }; 33 | http.collectHeaders(headerkeys, sizeof(headerkeys)/sizeof(char*)); 34 | 35 | int httpCode = http.GET(); 36 | if (httpCode != HTTP_CODE_OK) { 37 | DEBUG_PRINT("HTTP response should be 200"); 38 | BlynkState::set(MODE_ERROR); 39 | return; 40 | } 41 | int contentLength = http.getSize(); 42 | if (contentLength <= 0) { 43 | DEBUG_PRINT("Content-Length not defined"); 44 | BlynkState::set(MODE_ERROR); 45 | return; 46 | } 47 | 48 | bool canBegin = Update.begin(contentLength); 49 | if (!canBegin) { 50 | DEBUG_PRINT("Not enough space to begin OTA"); 51 | BlynkState::set(MODE_ERROR); 52 | return; 53 | } 54 | 55 | if (http.hasHeader("x-MD5")) { 56 | String md5 = http.header("x-MD5"); 57 | if (md5.length() == 32) { 58 | md5.toLowerCase(); 59 | DEBUG_PRINT("Expected MD5: " + md5); 60 | Update.setMD5(md5.c_str()); 61 | } 62 | } 63 | 64 | #ifdef BLYNK_FS 65 | BLYNK_FS.end(); 66 | #endif 67 | 68 | Client& client = http.getStream(); 69 | int written = Update.writeStream(client); 70 | if (written != contentLength) { 71 | DEBUG_PRINT(String("OTA written ") + written + " / " + contentLength + " bytes"); 72 | BlynkState::set(MODE_ERROR); 73 | return; 74 | } 75 | 76 | if (!Update.end()) { 77 | DEBUG_PRINT("Error #" + String(Update.getError())); 78 | BlynkState::set(MODE_ERROR); 79 | return; 80 | } 81 | 82 | if (!Update.isFinished()) { 83 | DEBUG_PRINT("Update failed."); 84 | BlynkState::set(MODE_ERROR); 85 | return; 86 | } 87 | 88 | DEBUG_PRINT("=== Update successfully completed. Rebooting."); 89 | restartMCU(); 90 | } 91 | 92 | -------------------------------------------------------------------------------- /CoopCommand/ResetButton.h: -------------------------------------------------------------------------------- 1 | 2 | #ifdef BOARD_BUTTON_PIN 3 | 4 | volatile bool g_buttonPressed = false; 5 | volatile uint32_t g_buttonPressTime = -1; 6 | 7 | void button_action(void) 8 | { 9 | BlynkState::set(MODE_RESET_CONFIG); 10 | } 11 | 12 | void button_change(void) 13 | { 14 | #if BOARD_BUTTON_ACTIVE_LOW 15 | bool buttonState = !digitalRead(BOARD_BUTTON_PIN); 16 | #else 17 | bool buttonState = digitalRead(BOARD_BUTTON_PIN); 18 | #endif 19 | 20 | if (buttonState && !g_buttonPressed) { 21 | g_buttonPressTime = millis(); 22 | g_buttonPressed = true; 23 | DEBUG_PRINT("Hold the button for 10 seconds to reset configuration..."); 24 | } else if (!buttonState && g_buttonPressed) { 25 | g_buttonPressed = false; 26 | uint32_t buttonHoldTime = millis() - g_buttonPressTime; 27 | if (buttonHoldTime >= BUTTON_HOLD_TIME_ACTION) { 28 | button_action(); 29 | } else if (buttonHoldTime >= BUTTON_PRESS_TIME_ACTION) { 30 | // User action 31 | } 32 | g_buttonPressTime = -1; 33 | } 34 | } 35 | 36 | void button_init() 37 | { 38 | #if BOARD_BUTTON_ACTIVE_LOW 39 | pinMode(BOARD_BUTTON_PIN, INPUT_PULLUP); 40 | #else 41 | pinMode(BOARD_BUTTON_PIN, INPUT_PULLDOWN); 42 | #endif 43 | attachInterrupt(BOARD_BUTTON_PIN, button_change, CHANGE); 44 | } 45 | 46 | #else 47 | 48 | #define g_buttonPressed false 49 | #define g_buttonPressTime 0 50 | 51 | void button_init() {} 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /CoopCommand/Settings.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Board configuration (see examples below). 4 | */ 5 | 6 | #if defined(USE_WROVER_BOARD) 7 | 8 | #define BOARD_BUTTON_PIN 15 9 | #define BOARD_BUTTON_ACTIVE_LOW true 10 | 11 | #define BOARD_LED_PIN_R 0 12 | #define BOARD_LED_PIN_G 2 13 | #define BOARD_LED_PIN_B 4 14 | #define BOARD_LED_INVERSE false 15 | #define BOARD_LED_BRIGHTNESS 128 16 | 17 | #elif defined(USE_TTGO_T7) 18 | 19 | #warning "This board does not have a button. Connect a button to gpio0 <> GND" 20 | 21 | #define BOARD_BUTTON_PIN 0 22 | #define BOARD_BUTTON_ACTIVE_LOW true 23 | 24 | #define BOARD_LED_PIN 19 25 | #define BOARD_LED_INVERSE false 26 | #define BOARD_LED_BRIGHTNESS 64 27 | 28 | #elif defined(USE_TTGO_T_OI) 29 | 30 | #warning "This board does not have a button. Connect a button to gpio0 <> GND" 31 | 32 | #define BOARD_BUTTON_PIN 0 33 | #define BOARD_BUTTON_ACTIVE_LOW true 34 | 35 | #define BOARD_LED_PIN 3 36 | #define BOARD_LED_INVERSE false 37 | #define BOARD_LED_BRIGHTNESS 64 38 | 39 | #elif defined(USE_ESP32_DEV_MODULE) 40 | 41 | #warning "The LED of this board is not configured" 42 | 43 | #define BOARD_BUTTON_PIN 0 44 | #define BOARD_BUTTON_ACTIVE_LOW true 45 | 46 | #elif defined(USE_ESP32C3_DEV_MODULE) 47 | 48 | #define BOARD_BUTTON_PIN 9 49 | #define BOARD_BUTTON_ACTIVE_LOW true 50 | 51 | #define BOARD_LED_PIN_WS2812 8 52 | #define BOARD_LED_INVERSE false 53 | #define BOARD_LED_BRIGHTNESS 32 54 | 55 | #elif defined(USE_ESP32S2_DEV_KIT) 56 | 57 | #define BOARD_BUTTON_PIN 0 58 | #define BOARD_BUTTON_ACTIVE_LOW true 59 | 60 | #define BOARD_LED_PIN 19 61 | #define BOARD_LED_INVERSE false 62 | #define BOARD_LED_BRIGHTNESS 128 63 | 64 | #else 65 | 66 | #warning "Custom board configuration is used" 67 | 68 | #define BOARD_BUTTON_PIN 0 // Pin where user button is attached 69 | #define BOARD_BUTTON_ACTIVE_LOW true // true if button is "active-low" 70 | 71 | //#define BOARD_LED_PIN 4 // Set LED pin - if you have a single-color LED attached 72 | //#define BOARD_LED_PIN_R 15 // Set R,G,B pins - if your LED is PWM RGB 73 | //#define BOARD_LED_PIN_G 12 74 | //#define BOARD_LED_PIN_B 13 75 | //#define BOARD_LED_PIN_WS2812 4 // Set if your LED is WS2812 RGB 76 | #define BOARD_LED_INVERSE false // true if LED is common anode, false if common cathode 77 | #define BOARD_LED_BRIGHTNESS 64 // 0..255 brightness control 78 | 79 | #endif 80 | 81 | 82 | /* 83 | * Advanced options 84 | */ 85 | 86 | #define BUTTON_HOLD_TIME_INDICATION 3000 87 | #define BUTTON_HOLD_TIME_ACTION 10000 88 | #define BUTTON_PRESS_TIME_ACTION 50 89 | 90 | #define BOARD_PWM_MAX 1023 91 | 92 | #define BOARD_LEDC_CHANNEL_1 1 93 | #define BOARD_LEDC_CHANNEL_2 2 94 | #define BOARD_LEDC_CHANNEL_3 3 95 | #define BOARD_LEDC_TIMER_BITS 10 96 | #define BOARD_LEDC_BASE_FREQ 12000 97 | 98 | #if !defined(CONFIG_DEVICE_PREFIX) 99 | #define CONFIG_DEVICE_PREFIX "Blynk" 100 | #endif 101 | #if !defined(CONFIG_AP_URL) 102 | #define CONFIG_AP_URL "blynk.setup" 103 | #endif 104 | #if !defined(CONFIG_DEFAULT_SERVER) 105 | #define CONFIG_DEFAULT_SERVER "blynk.cloud" 106 | #endif 107 | #if !defined(CONFIG_DEFAULT_PORT) 108 | #define CONFIG_DEFAULT_PORT 443 109 | #endif 110 | 111 | #define WIFI_CLOUD_MAX_RETRIES 500 112 | #define WIFI_NET_CONNECT_TIMEOUT 50000 113 | #define WIFI_CLOUD_CONNECT_TIMEOUT 50000 114 | #define WIFI_AP_IP IPAddress(192, 168, 4, 1) 115 | #define WIFI_AP_Subnet IPAddress(255, 255, 255, 0) 116 | //#define WIFI_CAPTIVE_PORTAL_ENABLE 117 | 118 | //#define USE_TICKER 119 | //#define USE_TIMER_ONE 120 | //#define USE_TIMER_THREE 121 | //#define USE_TIMER_FIVE 122 | #define USE_PTHREAD 123 | 124 | #define BLYNK_NO_DEFAULT_BANNER 125 | 126 | #if defined(APP_DEBUG) 127 | #define DEBUG_PRINT(...) BLYNK_LOG1(__VA_ARGS__) 128 | #define DEBUG_PRINTF(...) BLYNK_LOG(__VA_ARGS__) 129 | #else 130 | #define DEBUG_PRINT(...) 131 | #define DEBUG_PRINTF(...) 132 | #endif 133 | 134 | -------------------------------------------------------------------------------- /CoopCommandImages/Images.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /CoopCommandImages/PXL_20221015_171228559.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hms-11/CoopCommandESP32/29f5dd7f9d317558d72906f91789024fe18bea54/CoopCommandImages/PXL_20221015_171228559.jpg -------------------------------------------------------------------------------- /CoopCommandImages/PXL_20221015_171242919.MP.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hms-11/CoopCommandESP32/29f5dd7f9d317558d72906f91789024fe18bea54/CoopCommandImages/PXL_20221015_171242919.MP.jpg -------------------------------------------------------------------------------- /CoopCommandImages/PXL_20221029_195134568.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hms-11/CoopCommandESP32/29f5dd7f9d317558d72906f91789024fe18bea54/CoopCommandImages/PXL_20221029_195134568.jpg -------------------------------------------------------------------------------- /CoopCommandImages/Screenshot_20221029-083106.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hms-11/CoopCommandESP32/29f5dd7f9d317558d72906f91789024fe18bea54/CoopCommandImages/Screenshot_20221029-083106.png -------------------------------------------------------------------------------- /CoopCommandImages/Screenshot_20221029-083134.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hms-11/CoopCommandESP32/29f5dd7f9d317558d72906f91789024fe18bea54/CoopCommandImages/Screenshot_20221029-083134.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CoopCommandESP32 2 | 3 | Next generation Coop Command using an ESP32 as the MCU 4 | 5 | #### This is the next generation of the original, ATMEGA328P based CoopCommand found [HERE](https://github.com/hms-11/CoopCommand). 6 | 7 | # Overview 8 | 9 | Chickens are simple animals with lots of benefits. The downside? Humans are not the only creatures that find chickens tasty and chickens themselves require some basic maintenance and care to keep happy and healthy. 10 | 11 | CoopCommand aims to reduce the daily labour of looking after chickens, improve their well-being as well as allow hobby-farmers the ability to go out for the night without worrying if their chickens are in danger from wandering predators. 12 | 13 | [![CoopCommand Picture](https://github.com/hms-11/CoopCommandESP32/blob/main/CoopCommandImages/PXL_20221015_171228559.jpg)](https://github.com) 14 | 15 | Contributors always welcome, I could use people smarter than myself to keep improving this project. 16 | 17 | You can also support this project @ 18 | Buy Me A Coffee 19 | 20 | 21 | # GOALS: 22 | 23 | - Allow Backyard Chicken owners the ability to increase the security and productivity of their flock while reducing the daily labour costs of chicken ownership. 24 | 25 | - Automatic Coop Door controlled by daylight in order to more closely track chicken behaviour. 26 | 27 | - Monitor and control coop and water temperatures to prevent overheating of the coop and freezing of the water. 28 | 29 | - "LayLight" which monitors daylight light levels and ensures chickens receive at least 14 hours of daylight to maintain laying throughout winter months. 30 | 31 | - Ease of installation and configuration for non-technical individuals. 32 | 33 | - Designed for Off Grid Operation (12-24v DC), can also be powered by a suitably sized 12-24V DC Power Supply from an AC source. 34 | 35 | 36 | 37 | # FEATURES: 38 | 39 | ## TACO CHICKEN COOP COMMAND MAIN BOARD: 40 | 41 | - Hardware debouncing on door limit switches. [Example Limit Switches](https://www.amazon.ca/SpeedDa-Magnetic-Switch-Normally-Security/dp/B076GZDYD2/ref=sr_1_11?crid=1FTS5IZLOU1AM&keywords=magnetic+door+switch&qid=1667011161&qu=eyJxc2MiOiI0LjYxIiwicXNhIjoiNC4xMSIsInFzcCI6IjMuODAifQ%3D%3D&sprefix=magnetic+door+swi%2Caps%2C431&sr=8-11) 42 | 43 | - Pluggable Terminal Block connectors for all user-installed inputs/outputs. 44 | 45 | - DHT22 Input (requires 10k pullup on DHT22) for interior coop temperature. [Example DHT22](https://universal-solder.ca/product/dht22-temperature-humidity-sensor-16bit-digital-interface/) 46 | 47 | - DS18B20 Input (Pullup resistor already on board TACO CHICKEN board) for water temperature. [Example DS18B20](https://universal-solder.ca/product/digital-temperature-sensor-ds18b20-watertight-1-wire-interface-3-meter-wire/) 48 | 49 | - GL5539 Photoresistor Input (requires GL5539 with 10K resistor as voltage divider) for daylight sensor. [Example GL5539](https://universal-solder.ca/product/50-pcs-photo-resistor-5-different-types-10-each-gl55xx-series/) 50 | 51 | - Efficient SMPS for off-grid operation @ 12-24V DC. 52 | 53 | - TI DRV8870 Motor Driver IC w/3.6A current cabilitity & voltages up to maximimum working voltage of CoopCommand. 54 | 55 | - LayLight MOSFET for controlling LED lights for supplementing daylight hours to keep chickens laying even with less than 14 hours of Daylight. 56 | 57 | - Ventilation Fan MOSFET for controlling a fan for cooling the coop in the summer. [Example Ventilation Fan](https://www.amazon.ca/MACHSWON-Cooling-Exhaust-Ventilation-Motorhome/dp/B08FMNZH5T/ref=sr_1_8?keywords=12v+ventilation+fan&qid=1667011330&qu=eyJxc2MiOiIzLjM1IiwicXNhIjoiMi4wMCIsInFzcCI6IjAuMDAifQ%3D%3D&sprefix=12v+ventilat%2Caps%2C151&sr=8-8) 58 | 59 | - Water Heat MOSFET for controlling a heater for heating the water in the winter. [Example Water Heater](https://www.amazon.ca/Dernord-Immersion-Submersible-Element-Stainless/dp/B0761L2Q8M/ref=sr_1_25?crid=V2QPTYX224KK&keywords=12v+water+heater&qid=1667011500&qu=eyJxc2MiOiI1LjIwIiwicXNhIjoiNC42NiIsInFzcCI6IjIuNTIifQ%3D%3D&sprefix=12v+water+heate%2Caps%2C149&sr=8-25) 60 | 61 | - USB-UART CH340 chip wirth auto-reset for ease of programming (just plug in a [USB A - USB A cable](https://www.amazon.ca/DTECH-Type-Cable-Speed-Black/dp/B079GV2F5W/ref=sr_1_12?crid=FD392ACYKISH&keywords=usb+a+usb+a&qid=1667011638&qu=eyJxc2MiOiIyLjI1IiwicXNhIjoiMi4wMCIsInFzcCI6IjEuNTgifQ%3D%3D&refinements=p_n_availability%3A12035748011&sprefix=usb+a+usb+a%2Caps%2C162&sr=8-12) and go!) 62 | 63 | [![CoopCommand Picture](https://github.com/hms-11/CoopCommandESP32/blob/main/CoopCommandImages/PXL_20221029_195134568.jpg)](https://github.com) 64 | 65 | 66 | ## BLYNK: 67 | 68 | - Override door open or closed. 69 | 70 | - Monitor coop overall status (coop temperature, water temperature, fan and heat and light status). 71 | 72 | - Monitor door status (Open, Closed, Opening/Closing). 73 | 74 | - Adjust settings for all coop operations. 75 | 76 | [![CoopCommand Picture](https://github.com/hms-11/CoopCommandESP32/blob/main/CoopCommandImages/Screenshot_20221029-083134.png)](https://github.com) 77 | [![CoopCommand Picture](https://github.com/hms-11/CoopCommandESP32/blob/main/CoopCommandImages/Screenshot_20221029-083106.png)](https://github.com) 78 | 79 | # THE BOARD: 80 | 81 | CoopCommand uses the TacoChicken control board. Currently the board is on Rev1. The board is 100% Open Source and all files can be found [HERE](https://oshwlab.com/coreyearl1985/tacochickenrev1-dc_copy) 82 | 83 | If you want to purchase the pre-assembled board, I have them for sale [HERE](https://www.tindie.com/products/hms-11/taco-chicken-esp32-based-control-board/) 84 | 85 | 86 | # Getting Started: 87 | 88 | All files are included in this git-repository to get CoopCommand up and running. To get started, either create/modify your own based on this [OPEN SOURCE](https://oshwlab.com/coreyearl1985/tacochickenrev1-dc_copy) board or buy the board [HERE](https://www.tindie.com/products/hms-11/taco-chicken-esp32-based-control-board/). 89 | 90 | Once you have the board in hand and assembled, program can be easily loaded in using the Arduino IDE (or your preffered IDE) and a USB A - USB A cable. 91 | 92 | First, follow the instructions in the [BlynkInfo](https://github.com/hms-11/CoopCommandESP32/blob/main/BlynkInfo) file. This will setup the needed steps to get the app going and generate a required Template ID and Device Name to be added to your program to be uploaded to the board. 93 | 94 | Secondly, download all code files [HERE](https://github.com/hms-11/CoopCommandESP32/archive/refs/heads/main.zip). Extract all files in the CoopCommand folder into a folder all together. If you open the .ino file using Arduino IDE all other files will be loaded at same time. Insert the Template ID and Device Name into the appropriate location at the top of the sketch. Select your board (ESP32 Dev Module), select your Com Port and click upload! 95 | 96 | 97 | 98 | # CURRENT KNOWN ISSUES: 99 | 100 | - Loss of wifi can result in the system getting stuck in a blocked loop, resulting in no Coop control operations happening until wifi is restored. 101 | - Auto/Manual door function does not appear to switch correctly. System is stuck in auto mode. 102 | 103 | # THANKS 104 | 105 | There is an incredible reddit community dedicated to reviewing PCB schematics and layouts. This project, and many others of mine would not be possible without the amazing individuals present in this community. The subreddit is https://www.reddit.com/r/PrintedCircuitBoard/ . 106 | 107 | --------------------------------------------------------------------------------