* sensor node: now have two alert priorities, LO, HI
This commit is contained in:
@@ -332,13 +332,14 @@ void SensorMesh::applyContactPermissions(const uint8_t* pubkey, uint16_t perms)
|
|||||||
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY); // trigger saveContacts()
|
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY); // trigger saveContacts()
|
||||||
}
|
}
|
||||||
|
|
||||||
void SensorMesh::sendAlert(const char* text) {
|
void SensorMesh::sendAlert(AlertPriority pri, const char* text) {
|
||||||
int text_len = strlen(text);
|
int text_len = strlen(text);
|
||||||
|
uint16_t pri_mask = (pri == HIGH_PRI_ALERT) ? PERM_RECV_ALERTS_HI : PERM_RECV_ALERTS_LO;
|
||||||
|
|
||||||
// send text message to all contacts with RECV_ALERT permission
|
// send text message to all contacts with RECV_ALERT permission
|
||||||
for (int i = 0; i < num_contacts; i++) {
|
for (int i = 0; i < num_contacts; i++) {
|
||||||
auto c = &contacts[i];
|
auto c = &contacts[i];
|
||||||
if ((c->permissions & PERM_RECV_ALERTS) == 0) continue; // contact does NOT want alerts
|
if ((c->permissions & pri_mask) == 0) continue; // contact does NOT want alert
|
||||||
|
|
||||||
uint8_t data[MAX_PACKET_PAYLOAD];
|
uint8_t data[MAX_PACKET_PAYLOAD];
|
||||||
uint32_t now = getRTCClock()->getCurrentTimeUnique(); // need different timestamp per packet
|
uint32_t now = getRTCClock()->getCurrentTimeUnique(); // need different timestamp per packet
|
||||||
@@ -360,12 +361,12 @@ void SensorMesh::sendAlert(const char* text) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SensorMesh::alertIf(bool condition, Trigger& t, const char* text) {
|
void SensorMesh::alertIf(bool condition, Trigger& t, AlertPriority pri, const char* text) {
|
||||||
if (condition) {
|
if (condition) {
|
||||||
if (!t.triggered) {
|
if (!t.triggered) {
|
||||||
t.triggered = true;
|
t.triggered = true;
|
||||||
t.time = getRTCClock()->getCurrentTime();
|
t.time = getRTCClock()->getCurrentTime();
|
||||||
sendAlert(text);
|
sendAlert(pri, text);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (t.triggered) {
|
if (t.triggered) {
|
||||||
@@ -422,7 +423,7 @@ uint8_t SensorMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t*
|
|||||||
MESH_DEBUG_PRINTLN("Login success!");
|
MESH_DEBUG_PRINTLN("Login success!");
|
||||||
client->last_timestamp = sender_timestamp;
|
client->last_timestamp = sender_timestamp;
|
||||||
client->last_activity = getRTCClock()->getCurrentTime();
|
client->last_activity = getRTCClock()->getCurrentTime();
|
||||||
client->permissions = PERM_IS_ADMIN | PERM_RECV_ALERTS;
|
client->permissions = PERM_IS_ADMIN | PERM_RECV_ALERTS_HI | PERM_RECV_ALERTS_LO; // initially opt-in to receive alerts (can opt out)
|
||||||
memcpy(client->shared_secret, secret, PUB_KEY_SIZE);
|
memcpy(client->shared_secret, secret, PUB_KEY_SIZE);
|
||||||
|
|
||||||
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
|
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
|
||||||
|
|||||||
@@ -26,7 +26,8 @@
|
|||||||
#define PERM_IS_ADMIN 0x8000
|
#define PERM_IS_ADMIN 0x8000
|
||||||
#define PERM_GET_TELEMETRY 0x0001
|
#define PERM_GET_TELEMETRY 0x0001
|
||||||
#define PERM_GET_MIN_MAX_AVG 0x0002
|
#define PERM_GET_MIN_MAX_AVG 0x0002
|
||||||
#define PERM_RECV_ALERTS 0x0100
|
#define PERM_RECV_ALERTS_LO 0x0100 // low priority alerts
|
||||||
|
#define PERM_RECV_ALERTS_HI 0x0200 // high priority alerts
|
||||||
|
|
||||||
struct ContactInfo {
|
struct ContactInfo {
|
||||||
mesh::Identity id;
|
mesh::Identity id;
|
||||||
@@ -104,8 +105,8 @@ protected:
|
|||||||
|
|
||||||
Trigger() { triggered = false; time = 0; }
|
Trigger() { triggered = false; time = 0; }
|
||||||
};
|
};
|
||||||
|
enum AlertPriority { LOW_PRI_ALERT, HIGH_PRI_ALERT };
|
||||||
void alertIf(bool condition, Trigger& t, const char* text);
|
void alertIf(bool condition, Trigger& t, AlertPriority pri, const char* text);
|
||||||
|
|
||||||
virtual void onSensorDataRead() = 0; // for app to implement
|
virtual void onSensorDataRead() = 0; // for app to implement
|
||||||
virtual int querySeriesData(uint32_t start_secs_ago, uint32_t end_secs_ago, MinMaxAvg dest[], int max_num) = 0; // for app to implement
|
virtual int querySeriesData(uint32_t start_secs_ago, uint32_t end_secs_ago, MinMaxAvg dest[], int max_num) = 0; // for app to implement
|
||||||
@@ -145,6 +146,6 @@ private:
|
|||||||
ContactInfo* putContact(const mesh::Identity& id);
|
ContactInfo* putContact(const mesh::Identity& id);
|
||||||
void applyContactPermissions(const uint8_t* pubkey, uint16_t perms);
|
void applyContactPermissions(const uint8_t* pubkey, uint16_t perms);
|
||||||
|
|
||||||
void sendAlert(const char* text);
|
void sendAlert(AlertPriority pri, const char* text);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ protected:
|
|||||||
float batt_voltage = getVoltage(TELEM_CHANNEL_SELF);
|
float batt_voltage = getVoltage(TELEM_CHANNEL_SELF);
|
||||||
|
|
||||||
battery_data.recordData(getRTCClock(), batt_voltage); // record battery
|
battery_data.recordData(getRTCClock(), batt_voltage); // record battery
|
||||||
alertIf(batt_voltage < 3.4f, low_batt, "Battery low!");
|
alertIf(batt_voltage < 3.4f, low_batt, HIGH_PRI_ALERT, "Battery low!");
|
||||||
}
|
}
|
||||||
|
|
||||||
int querySeriesData(uint32_t start_secs_ago, uint32_t end_secs_ago, MinMaxAvg dest[], int max_num) override {
|
int querySeriesData(uint32_t start_secs_ago, uint32_t end_secs_ago, MinMaxAvg dest[], int max_num) override {
|
||||||
|
|||||||
Reference in New Issue
Block a user