I see its been asked at least once but no one answered,
I have an esp32 that's battery operated and i want to save as much power as possible so sleep modes etc. I want to say connect to the WIFI and IOT cloud as short as possible do my update and then turn off WiFi. I have not found At this point i have it working but its ugly, Why doesn't Update() return true when a sync occurs? and the callback sync function does not occur every time its actually updated.
void Setup_IOT() {
if (BoardSetup::GetSettingValue("USE_IOT") == "false") return;
String deviceID = BoardSetup::GetSettingValue("LOGIN_ID");
String deviceKey = BoardSetup::GetSettingValue("DEVICE_KEY");
Serial.println(deviceID);
Serial.println(deviceKey);
ArduinoCloud.setBoardId(deviceID);
ArduinoCloud.setSecretDeviceKey(deviceKey);
ArduinoCloud.addProperty(string, READ, 5 * SECONDS, NULL);
ArduinoCloud.addProperty(pct_Strength, READ, SECONDS, NULL);
ArduinoCloud.addProperty(pressure, READ, 5 * SECONDS, NULL);
ArduinoCloud.addProperty(lED_Status, READ, ON_CHANGE, NULL);
ArduinoCloud.addCallback(ArduinoIoTCloudEvent::CONNECT, doThisOnConnect);
ArduinoCloud.addCallback(ArduinoIoTCloudEvent::SYNC, doThisOnSync);
ArduinoCloud.addCallback(ArduinoIoTCloudEvent::DISCONNECT, doThisOnDisconnect);
//ArduinoCloud.addProperty(lED_Switch, READWRITE, ON_CHANGE, onLEDSwitchChange);
ArduinoCloud.begin(ArduinoIoTPreferredConnection, false); //@ Start connection to Arduino IoT Cloud false, disabled watchdog
}
// Im sure there is a better way but I cant find it atm
void Update_IOT(String value1, float value2, uint32_t value3) {
if (BoardSetup::GetSettingValue("USE_IOT") == "false") return;
// Check Timer To send data every 6 minutes
if (millis() - lastIOTSend < IOTSendPeriod) return;
WiFi.mode(WIFI_STA);
// IOT
string = value1; // This String is for WIFI Output
pct_Strength = value2; // This is for WIFI Output
pressure = value3; // This is for WIFI Output
unsigned long timer = millis();
// Wait for the connection
Serial.println("Connecting to Arduino IoT Cloud...");
unsigned int timeout = 0;
while (!ArduinoCloud.connected() && timeout < 120) {
ArduinoCloud.update();
timeout += 1;
delay(100);
}
if (ArduinoCloud.connected()) {
Serial.println("Connected and now Updating");
timeout = 0;
while (timeout < 60) {
ArduinoCloud.update();
timeout += 1;
delay(120);
}
Serial.println("Sending");
for (int i=0; i < 8; i++) {
ArduinoCloud.update();
delay(100);
}
}
else
{
Serial.println("Wifi Failed to Connect");
}
WiFi.mode(WIFI_OFF);
delay(100);
Serial.print("Updated in ");
Serial.println(millis()-timer);
lastIOTSend = millis();
}
Is there any way to just push a single time instead of the while updates() ? I assure you cutting much more time from any loop will cause IOT updates to fail, and there seems to be no solid way of getting when the correct things happen to move out of the loop, This takes ~20 seconds to get one single IOT update. from connecting to the WIFI then IOT then sending then disconnecting
Any incite would be appreciated