in arduino/plant_reference.ino [198:249]
void ota() {
switch (state) {
case NO_OTA: {
expresslinkExecuteCommand("AT+OTA?\n");
if (startsWith(expresslinkResponse, "OK 0", 4)) {
awaitingOTAResponse = false;
otaInProgress = false;
} else if (startsWith(expresslinkResponse, "OK 1", 4)) {
awaitingOTAResponse = true;
state = DOWNLOAD_OTA;
}
break;
}
case DOWNLOADING: {
delay(timeout_ms);
expresslinkExecuteCommand("AT+OTA?\n");
if (startsWith(expresslinkResponse, "OK 4", 4)) {
state = OTA_UPDATE;
}
break;
}
case DOWNLOAD_OTA: {
Serial.printf("Would you like to download and flash the new ExpressLink firmware (y/n)?\n");
Serial.setTimeout(10000);
String userResponse = Serial.readStringUntil('\n');
if (userResponse.equals("y\r")) {
expresslinkExecuteCommand("AT+OTA ACCEPT\n");
state = DOWNLOADING;
otaInProgress = true;
awaitingOTAResponse = false;
} else if (userResponse.equals("n\r")) {
expresslinkExecuteCommand("AT+OTA FLUSH\n");
awaitingOTAResponse = false;
state = NO_OTA;
}
break;
}
case OTA_UPDATE: {
expresslinkExecuteCommand("AT+OTA APPLY\n");
state = NO_OTA;
otaInProgress = false;
expresslink_serial.setTimeout(20000);
String response = expresslink_serial.readStringUntil('\n');
int responseLen = response.length() + 1;
response.toCharArray(expresslinkResponse, responseLen);
Serial.printf(expresslinkResponse);
expresslinkExecuteCommand("AT+CONNECT\n");
expresslinkSetParams();
break;
}
}
}