Added sendHeatbeat()
Allow a sensor to send a "dummy" message to controller to say "I'm still alive!". The payload will be an incremental uint16.
This commit is contained in:
@@ -146,7 +146,8 @@ typedef enum {
|
|||||||
I_BATTERY_LEVEL, I_TIME, I_VERSION, I_ID_REQUEST, I_ID_RESPONSE,
|
I_BATTERY_LEVEL, I_TIME, I_VERSION, I_ID_REQUEST, I_ID_RESPONSE,
|
||||||
I_INCLUSION_MODE, I_CONFIG, I_FIND_PARENT, I_FIND_PARENT_RESPONSE,
|
I_INCLUSION_MODE, I_CONFIG, I_FIND_PARENT, I_FIND_PARENT_RESPONSE,
|
||||||
I_LOG_MESSAGE, I_CHILDREN, I_SKETCH_NAME, I_SKETCH_VERSION,
|
I_LOG_MESSAGE, I_CHILDREN, I_SKETCH_NAME, I_SKETCH_VERSION,
|
||||||
I_REBOOT, I_GATEWAY_READY, I_REQUEST_SIGNING, I_GET_NONCE, I_GET_NONCE_RESPONSE
|
I_REBOOT, I_GATEWAY_READY, I_REQUEST_SIGNING, I_GET_NONCE, I_GET_NONCE_RESPONSE,
|
||||||
|
I_HEARTBEAT
|
||||||
} mysensor_internal;
|
} mysensor_internal;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -487,6 +487,11 @@ void MySensor::sendBatteryLevel(uint8_t value, bool enableAck) {
|
|||||||
sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_BATTERY_LEVEL, enableAck).set(value));
|
sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_BATTERY_LEVEL, enableAck).set(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MySensor::sendHeartbeat(void) {
|
||||||
|
sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_HEARTBEAT, false).set(heartbeat++));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void MySensor::present(uint8_t childSensorId, uint8_t sensorType, const char *description, bool enableAck) {
|
void MySensor::present(uint8_t childSensorId, uint8_t sensorType, const char *description, bool enableAck) {
|
||||||
sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, childSensorId, C_PRESENTATION, sensorType, enableAck).set(childSensorId==NODE_SENSOR_ID?LIBRARY_VERSION:description));
|
sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, childSensorId, C_PRESENTATION, sensorType, enableAck).set(childSensorId==NODE_SENSOR_ID?LIBRARY_VERSION:description));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -219,6 +219,12 @@ class MySensor
|
|||||||
*/
|
*/
|
||||||
void sendBatteryLevel(uint8_t level, bool ack=false);
|
void sendBatteryLevel(uint8_t level, bool ack=false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a heartbeat message (I'm alive!) to the gateway/controller.
|
||||||
|
* The payload will be an incremental 16 bit integer value starting at 1 when sensor is powered on.
|
||||||
|
*/
|
||||||
|
void sendHeartbeat(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests a value from gateway or some other sensor in the radio network.
|
* Requests a value from gateway or some other sensor in the radio network.
|
||||||
* Make sure to add callback-method in begin-method to handle request responses.
|
* Make sure to add callback-method in begin-method to handle request responses.
|
||||||
@@ -373,6 +379,7 @@ class MySensor
|
|||||||
char convBuf[MAX_PAYLOAD*2+1];
|
char convBuf[MAX_PAYLOAD*2+1];
|
||||||
#endif
|
#endif
|
||||||
uint8_t failedTransmissions;
|
uint8_t failedTransmissions;
|
||||||
|
uint16_t heartbeat;
|
||||||
void (*timeCallback)(unsigned long); // Callback for requested time messages
|
void (*timeCallback)(unsigned long); // Callback for requested time messages
|
||||||
void (*msgCallback)(const MyMessage &); // Callback for incoming messages from other nodes and gateway.
|
void (*msgCallback)(const MyMessage &); // Callback for incoming messages from other nodes and gateway.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user