Device Heartbeat
To find out remotely what the status of your device is (like sensor readings, on/off state etc) there are various concepts that could be used, for example:
- Sending a request to the device and waiting for it to report its state back. This is sort of pull mechanism
- The device sends on regular intervals a heartbeat with the status of all of its components and we save that info so it can be retreived anytime we want even if the device is offline. This is sort of push mechanism
- Combination of the push & pull
If you want to find out more why I believe the heartbeat approach is a better option for an IoT device concept, post a question in the forum and I will be happy to explain in more detail my thinking process.
Sending a heartbeat
The device heartbeat is nothing more than a JSON formatted string containing some properties that you send on regular intervals.
You can also find examples for every device and its component in theDev Console > Devices
You can also find examples for every device and its component in the
IMPORTANT: You can send a heartbeat once every 10 seconds or slower. Heartbeats sent faster will be rejected, you will get system warnings and potentially get system violations marked on your account.
Here is a "heartbeat" JSON example event sent by a device:
{"api_call":"heartbeat","command":"heartbeat","uuid":"ChpChpUsRf5c40b64c03f0b607ae9b51a3803","device_id":"0000001","status":{"temperature_sensor":{"value":23},"motion_sensor":"{"value":"NOT_DETECTED"}}
On success you should receive a response from ChipChop
{"status":"OK","timestamp":1668870714611}
Heartbeat JSON explained
api_call
Should be set as:
heartbeat
command
Should be set as:
heartbeat
uuid
Your ChipChop UUID
You can find your UUID in the Dev Console > My Account
device_id
Device ID as you have set it in the Dev Console > Devices
status
JSON collection containing the statuses of each component that you have specified in the Dev Console
{"motion_sensor":{"value":"DETECTED"},"led":{"value":"ON"},"temperature":{"value":23}}
The "value" property can be either a string or a number so pay attention when using quotes. Incorrectly formatted JSON will be rejected by ChipChop.