MeterLogger
Data Structures | Macros | Typedefs | Functions
cron.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cron_job_t
 
struct  cron_jobs_t
 

Macros

#define TOPIC_L   64
 
#define MESSAGE_L   100
 
#define FUNCTIONNAME_L   32
 
#define KEY_VALUE_L   64
 
#define COMMAND_L   32
 
#define CRON_JOBS_MAX   32
 
#define CRON_FIELD_L   8
 

Typedefs

typedef cron_job_t cron_job_list_t[CRON_JOBS_MAX]
 

Functions

ICACHE_FLASH_ATTR void cron_init ()
 
ICACHE_FLASH_ATTR unsigned int add_cron_job_from_query (char *query)
 
ICACHE_FLASH_ATTR void clear_cron_jobs ()
 

Macro Definition Documentation

◆ COMMAND_L

#define COMMAND_L   32

Definition at line 5 of file cron.h.

Referenced by add_cron_job_from_query(), and minute_timer_func().

◆ CRON_FIELD_L

#define CRON_FIELD_L   8

Definition at line 8 of file cron.h.

Referenced by add_cron_job_from_query(), and minute_timer_func().

◆ CRON_JOBS_MAX

#define CRON_JOBS_MAX   32

Definition at line 7 of file cron.h.

Referenced by add_cron_job_from_query().

◆ FUNCTIONNAME_L

#define FUNCTIONNAME_L   32

Definition at line 3 of file cron.h.

◆ KEY_VALUE_L

#define KEY_VALUE_L   64

Definition at line 4 of file cron.h.

Referenced by add_cron_job_from_query().

◆ MESSAGE_L

#define MESSAGE_L   100

Definition at line 2 of file cron.h.

◆ TOPIC_L

#define TOPIC_L   64

Definition at line 1 of file cron.h.

Typedef Documentation

◆ cron_job_list_t

typedef cron_job_t cron_job_list_t[CRON_JOBS_MAX]

Definition at line 26 of file cron.h.

Function Documentation

◆ add_cron_job_from_query()

ICACHE_FLASH_ATTR unsigned int add_cron_job_from_query ( char *  query)

Definition at line 226 of file cron.c.

References cfg_save_defered(), COMMAND_L, CRON_FIELD_L, cron_jobs_t::cron_job_list, syscfg_t::cron_jobs, CRON_JOBS_MAX, ICACHE_FLASH_ATTR, key, KEY_VALUE_L, memset, cron_jobs_t::n, NULL, os_printf, strncmp, strncpy, and sys_cfg.

226  {
227  char *str;
228  char *key, *value;
229  char key_value[KEY_VALUE_L];
230  char *context_query_string, *context_key_value;
231 
232  if (sys_cfg.cron_jobs.n <= CRON_JOBS_MAX - 1) { // if there are room for more cron jobs
233  // parse mqtt message for query string
235  str = strtok_r(query, "&", &context_query_string);
236  while (str != NULL) {
237  strncpy(key_value, str, KEY_VALUE_L);
238  key = strtok_r(key_value, "=", &context_key_value);
239  value = strtok_r(NULL, "=", &context_key_value);
240  if (strncmp(key, "minute", KEY_VALUE_L) == 0) {
242  }
243  else if (strncmp(key, "hour", KEY_VALUE_L) == 0) {
245  }
246  else if (strncmp(key, "day_of_month", KEY_VALUE_L) == 0) {
248  }
249  else if (strncmp(key, "month", KEY_VALUE_L) == 0) {
251  }
252  else if (strncmp(key, "day_of_week", KEY_VALUE_L) == 0) {
254  }
255  else if (strncmp(key, "command", COMMAND_L) == 0) {
257 #ifdef DEBUG
258  os_printf("job #%d added\n\r", sys_cfg.cron_jobs.n);
259 #endif
260  sys_cfg.cron_jobs.n++;
261  }
262 
263  str = strtok_r(NULL, "&", &context_query_string);
264  }
265  // save it to flash
267  }
268 
269  return sys_cfg.cron_jobs.n;
270 }
cron_jobs_t cron_jobs
Definition: config.h:63
#define memset(x, a, b)
Definition: platform.h:21
#define KEY_VALUE_L
Definition: cron.h:4
#define NULL
Definition: def.h:47
#define COMMAND_L
Definition: cron.h:5
#define os_printf
Definition: osapi.h:62
void ICACHE_FLASH_ATTR cfg_save_defered()
Definition: config.c:144
unsigned char n
Definition: cron.h:29
cron_job_list_t cron_job_list
Definition: cron.h:30
#define strncmp(a, b, c)
Definition: platform.h:18
#define CRON_FIELD_L
Definition: cron.h:8
#define strncpy(a, b, c)
Definition: platform.h:16
static const char key[]
Definition: config.h:42
syscfg_t sys_cfg
Definition: config.c:12
#define CRON_JOBS_MAX
Definition: cron.h:7
Here is the call graph for this function:

◆ clear_cron_jobs()

ICACHE_FLASH_ATTR void clear_cron_jobs ( )

Definition at line 273 of file cron.c.

References cfg_save_defered(), syscfg_t::cron_jobs, memset, os_printf, and sys_cfg.

273  {
274 #ifdef DEBUG
275  //debug_cron_jobs();
276 #endif
277  memset(&sys_cfg.cron_jobs, 0, sizeof(cron_job_t));
278 
279  // save it to flash
281 #ifdef DEBUG
282  os_printf("\n\rcleared all jobs\n\r");
283 #endif
284 }
cron_jobs_t cron_jobs
Definition: config.h:63
#define memset(x, a, b)
Definition: platform.h:21
#define os_printf
Definition: osapi.h:62
void ICACHE_FLASH_ATTR cfg_save_defered()
Definition: config.c:144
syscfg_t sys_cfg
Definition: config.c:12
Here is the call graph for this function:

◆ cron_init()

ICACHE_FLASH_ATTR void cron_init ( )

Definition at line 212 of file cron.c.

References syscfg_t::cron_jobs, ICACHE_FLASH_ATTR, minute_timer, minute_timer_func(), cron_jobs_t::n, NULL, os_printf, os_timer_arm, os_timer_disarm, os_timer_func_t, os_timer_setfn, and sys_cfg.

212  {
213  //memset(&sys_cfg.cron_jobs, 0, sizeof(cron_job_t));
214 
215  // check if there are any cron jobs to run every minute
218  os_timer_arm(&minute_timer, 60000, 1);
219 
220 #ifdef DEBUG
221  os_printf("\n\rcron jobs: %d\n\r", sys_cfg.cron_jobs.n);
222 #endif
223 }
cron_jobs_t cron_jobs
Definition: config.h:63
ICACHE_FLASH_ATTR static void minute_timer_func(void *arg)
Definition: cron.c:13
#define os_timer_disarm
Definition: osapi.h:51
#define NULL
Definition: def.h:47
#define os_timer_func_t
Definition: os_type.h:35
#define os_printf
Definition: osapi.h:62
#define os_timer_setfn
Definition: osapi.h:52
unsigned char n
Definition: cron.h:29
#define os_timer_arm(a, b, c)
Definition: osapi.h:50
static os_timer_t minute_timer
Definition: cron.c:9
syscfg_t sys_cfg
Definition: config.c:12
Here is the call graph for this function: