basic/system_monitor/system_monitor.c

See examples/basic/system-monitor

/*
* ZentriOS SDK LICENSE AGREEMENT | Zentri.com, 2015.
*
* Use of source code and/or libraries contained in the ZentriOS SDK is
* subject to the Zentri Operating System SDK license agreement and
* applicable open source license agreements.
*
*/
/* Documentation for this app is available online.
* See https://docs.zentri.com/wifi/sdk/latest/examples/basic/system-monitor
*/
#include "zos.h"
#define MAX_DELAY 7000
static zos_system_monitor_t system_monitor;
static int counter;
/*************************************************************************************************/
void zn_app_init(void)
{
ZOS_LOG("System Monitor app running ...");
zn_register_system_monitor(&system_monitor, MAX_DELAY);
counter = 3;
// register a periodic event to update the system monitor;
zn_event_register_periodic(update_system_monitor_event_handler, NULL, MAX_DELAY/2, 0);
}
/*************************************************************************************************/
void zn_app_deinit(void)
{
// MUST unregister the system monitor when we're done
zn_unregister_system_monitor(&system_monitor);
}
/*************************************************************************************************/
static void update_system_monitor_event_handler(void *arg)
{
ZOS_LOG("Updating system monitor");
// update the monitor to indicate everything is working correctly
zn_update_system_monitor(&system_monitor, MAX_DELAY);
// once the counter reaches 0, unregister the update event handler
// this simulates something locking up
// when the system monitor stops getting updated a watchdog will be triggered
if(--counter <= 0)
{
ZOS_LOG("Simulating system lock up, watchdog will be triggered in %d seconds ...", MAX_DELAY/1000);
zn_event_unregister(update_system_monitor_event_handler, NULL);
}
}