-
Notifications
You must be signed in to change notification settings - Fork 14
/
manualUpdate.ino
71 lines (66 loc) · 1.91 KB
/
manualUpdate.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <Arduino.h>
#include <MAGELLAN_SIM7600E_MQTT.h>
MAGELLAN_SIM7600E_MQTT magel;
int checkStatusUpdate = UNKNOWN;
void setup()
{
Serial.begin(115200);
magel.OTA.autoUpdate(false); // this function ENABLED by default unless you set FALSE
setting.clientBufferSize = defaultOTABuffer; // set buffer size compatible for OTA
magel.begin(setting);
magel.getServerConfig("autoUpdate", [](String resp){
if(resp == "1")
{
magel.OTA.autoUpdate(true);
}
else{
magel.OTA.autoUpdate(false);
}
magel.clientConfig.add("autoUpdateMode", ((magel.OTA.getAutoUpdate())? "ENABLE" : "DISABLE"));
magel.clientConfig.save(); // update client config from device to thing optional
});
magel.getControl([](String key, String value){
if(key == "executeUpdate")
{
magel.control.ACK("executeUpdate", value);
if(value == "1")
{
magel.OTA.executeUpdate(); // executeUpdate OTA
}
}
else // acknowledge other control
{
magel.control.ACK(key, value);
}
});
// prepare sensor for add widget control
magel.report.send("executeUpdate", "0");
}
void loop()
{
magel.loop();
magel.subscribes([](){
magel.subscribe.serverConfig(PLAINTEXT);
magel.subscribe.control(PLAINTEXT);
checkStatusUpdate = magel.OTA.checkUpdate(); // checkUpdate once time after connect and after reconnect
// subscribe function here!
});
magel.interval(10,[](){ //time interval function inside every 10000 millis
// doing function something every 10 sec here!
switch (checkStatusUpdate)
{
case UP_TO_DATE:
Serial.print(F("checkStatusUpdate: "));
Serial.println("# UP_TO_DATE");
break;
case OUT_OF_DATE:
Serial.print(F("checkStatusUpdate: "));
Serial.println(F("# OUT_OF_DATE"));
break;
default:
Serial.print(F("checkStatusUpdate: "));
Serial.println("# UNKNOWN");
break;
}
});
}