Skip to content

Commit b3c1188

Browse files
cpqcesantabot
authored andcommitted
Introduce MGOS_EVENT_CLOUD_[DIS]CONNECTED
CL: Introduce MGOS_EVENT_CLOUD_[DIS]CONNECTED PUBLISHED_FROM=b1e60dabad0ed9a58318ab7a73eb5c65b16744ed
1 parent 9a39cbc commit b3c1188

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

fs/api_events.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ let Event = {
2929
addGroupHandler: ffi(
3030
'bool mgos_event_add_group_handler(int, void(*)(int, void *, userdata), userdata)'),
3131

32+
// ## **`Event.on(event_num, callback, userdata)`**
33+
// Alias for Event.addHandler
34+
on: function(ev, cb, cbdata) {
35+
this.addHandler(ev, cb, cbdata);
36+
return this;
37+
},
38+
3239
// ## **`Event.regBase(base_event_number, name)`**
3340
// Register a base event number in order to prevent event number conflicts.
3441
// Use `Event.baseNumber(id)` to get `base_event_number`; `name` is an
@@ -56,7 +63,7 @@ let Event = {
5663
// it and prevent event number conflicts. (see example there)
5764
baseNumber: function(id) {
5865
if (id.length !== 3) {
59-
die("Base event id should have exactly 3 chars");
66+
die('Base event id should have exactly 3 chars');
6067
return -1;
6168
}
6269

@@ -78,7 +85,7 @@ let Event = {
7885
_gdl: ffi('int mgos_debug_event_get_len(void *)'),
7986
};
8087

81-
Event.SYS = Event.baseNumber("MOS");
88+
Event.SYS = Event.baseNumber('MOS');
8289

8390
// NOTE: INIT_DONE is unavailable here because init.js is executed in
8491
// INIT_DONE hook
@@ -99,4 +106,12 @@ Event.REBOOT = Event.SYS + 2;
99106
//
100107
// In the callback, use `OTA.evdataOtaStatusMsg(evdata)` from `api_ota.js` to
101108
// get the OTA status message.
102-
Event.OTA_STATUS = Event.SYS + 3;
109+
Event.OTA_TIME_CHANGED = Event.SYS + 3;
110+
111+
// ## **`Event.CLOUD_CONNECTED`**
112+
// Triggered when device is connected to the cloud (mqtt, dash)
113+
Event.CLOUD_CONNECTED = Event.SYS + 4;
114+
115+
// ## **`Event.CLOUD_DISCONNECTED`**
116+
// Triggered when device is disconnected from the cloud
117+
Event.CLOUD_DISCONNECTED = Event.SYS + 5;

0 commit comments

Comments
 (0)