| | |
| | | #define PROG_VERSION "v1.0.0" |
| | | #define DAEMON_PIDFILE "/tmp/.iotd.pid" |
| | | |
| | | void control_thread_loop(void *args); |
| | | |
| | | static void program_usage(char *progname) |
| | | { |
| | |
| | | int debug = 0; |
| | | int opt; |
| | | char *progname=NULL; |
| | | float lux = 0.0; |
| | | |
| | | struct option long_options[] = { |
| | | {"conf", required_argument, NULL, 'c'}, |
| | |
| | | } |
| | | log_nrml("Initialise hardware okay.\n"); |
| | | |
| | | return 0; /* todo: debug and removed */ |
| | | |
| | | install_default_signal(); |
| | | |
| | | if( check_set_program_running(daemon, DAEMON_PIDFILE) < 0 ) |
| | | goto OUT; |
| | | |
| | |
| | | log_nrml("Start MQTT subsciber worker thread ok\n"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /*+--------------------------------------------+ |
| | | *| Start MQTT publisher thread if enable | |
| | |
| | | } /* ----- End of main() ----- */ |
| | | |
| | | |
| | | void control_thread_loop(void *ctx) |
| | | void control_thread_loop(void *args) |
| | | { |
| | | iotd_ctx_t *ctx = (iotd_ctx_t *)ctx; |
| | | iotd_ctx_t *ctx = (iotd_ctx_t *)args; |
| | | hal_ctx_t *hal_ctx; |
| | | |
| | | float lux = 0.0; |
| | | |
| | | hal_ctx = &ctx->hal_ctx; |
| | | |
| | | log_nrml("Start control thread working...\n"); |
| | | |
| | | while( ! g_signal.stop ) |
| | | { |
| | | lux = tsl2561_get_lux(); |
| | | if( lux > hal_ctx->lux_threshold ) |
| | | if( hal_ctx->lux_enable ) |
| | | { |
| | | log_nrml("Lux[%.3f] > Treshold[%.3f], don't need auto light.\n", lux, hal_ctx->lux_threshold); |
| | | sleep(30); |
| | | continue; |
| | | lux = tsl2561_get_lux(); |
| | | log_dbg("TSL2561 get Lux[%.3f].\n", lux); |
| | | |
| | | if( lux > hal_ctx->lux_threshold ) |
| | | { |
| | | log_nrml("Lux[%.3f] > Treshold[%.3f], don't need light on.\n", lux, hal_ctx->lux_threshold); |
| | | sleep(30); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | log_nrml("start infrared monitor detect...\n"); |
| | | if( infrared_detect() ) |
| | | { |
| | | log_nrml("Someone incoming detected by infrared\n"); |
| | | if( lux < hal_ctx->lux_threshold ) |
| | | { |
| | | log_nrml("Lux[%.3f] < Treshold[%.3f], auto light on now..\n", lux, hal_ctx->lux_threshold); |
| | | //turn_light(LIGHT_HALLWAY, ON); |
| | | alarm(hal_ctx->gpio.light_intval); |
| | | } |
| | | } |
| | | |
| | | sleep(1); |
| | | } |
| | | } |
| | | |