// Will be called when WiFi station was connected to AP void connectOk() { Serial.println("I'm CONNECTED"); // Configure cloud update airUpdater.addItem(0x0000, "http://simple.anakod.ru/fw/eagle.flash.bin"); airUpdater.addItem(0x9000, "http://simple.anakod.ru/fw/eagle.irom0text.bin"); attachInterrupt(UPDATE_PIN, interruptHandler, CHANGE); Serial.println("\r\nPress GPIO0 to start cloud update!\r\n"); }
void onRequestSent(HttpClient& client, bool successful) { if (successful) { debugf("Update check successful."); StaticJsonBuffer<200> jsonBuffer; String response = client.getResponseString(); char json[response.length() + 1];// Add 1 char space for null strcpy(json, response.c_str()); JsonObject& root = jsonBuffer.parseObject(json); if (root != root.invalid()) { const char* version = root["version"]; if (strcmp(version, AppSettings.version.c_str()) == 0) { debugf("No new version available."); } else { debugf("New version available. Staging files..."); JsonArray& files = root["files"]; for (int i = 0; i < 10; i++) { JsonObject& file = files[i]; if (file == file.invalid()) break; // We're at the end of the file list int address = file["address"]; const char* url = file["url"]; // Configure cloud update airUpdater.addItem(address, url); debugf("Staging file %i from %s.", address, url); } debugf("Update files staged. Starting update..."); airUpdater.start(); } } } else { debugf("Update check failed."); } }
void IRAM_ATTR interruptHandler() { detachInterrupt(UPDATE_PIN); Serial.println("Let's do cloud magic!"); // Start cloud update airUpdater.start(); }