| | |
| | | } |
| | | |
| | | log_nrml("Subscriber connect to broker server[%s:%d] successfully\n", ctx->mqtt_ctx.host, ctx->mqtt_ctx.port); |
| | | |
| | | log_nrml("Subscriber subTopic '%s' with Qos[%d]\n", ctx->mqtt_ctx.subTopic, ctx->mqtt_ctx.subQos); |
| | | mosquitto_subscribe(mosq, NULL, ctx->mqtt_ctx.subTopic, ctx->mqtt_ctx.subQos); |
| | | } |
| | | |
| | |
| | | { |
| | | value = cJSON_Print(item); |
| | | |
| | | /* light controled by relay */ |
| | | if( !strcasecmp(item->string, "hallway") ) |
| | | log_dbg("JSON Parser key: %s value: %s\n", item->string, value); |
| | | if( strstr(item->string, "light") || strstr(item->string, "led") || strstr(item->string, "relay")) |
| | | { |
| | | if( strcasestr(value, "on") ) |
| | | if( strstr(value, "on") || strstr(value, "off") ) |
| | | { |
| | | //turn_light(LIGHT_HALLWAY, ON); |
| | | log_nrml("Turn on hallway light\n"); |
| | | } |
| | | else if( strcasestr(value, "off") ) |
| | | { |
| | | //turn_light(LIGHT_HALLWAY, OFF); |
| | | log_nrml("Turn off hallway light\n"); |
| | | } |
| | | } |
| | | else if( !strcasecmp(item->string, "livroom_left") ) |
| | | { |
| | | if( strcasestr(value, "on") ) |
| | | { |
| | | //turn_light(LIGHT_LVROOM_LEFT, ON); |
| | | log_nrml("Turn on livingroom left light\n"); |
| | | } |
| | | else if( strcasestr(value, "off") ) |
| | | { |
| | | //turn_light(LIGHT_LVROOM_LEFT, OFF); |
| | | log_nrml("Turn off livingroom left light\n"); |
| | | } |
| | | } |
| | | if( !strcasecmp(item->string, "livroom_right") ) |
| | | { |
| | | if( strcasestr(value, "on") ) |
| | | { |
| | | //turn_light(LIGHT_LVROOM_RIGHT, ON); |
| | | log_nrml("Turn on livingroom right light\n"); |
| | | } |
| | | else if( strcasestr(value, "off") ) |
| | | { |
| | | //turn_light(LIGHT_LVROOM_RIGHT, OFF); |
| | | log_nrml("Turn off livingroom right light\n"); |
| | | log_nrml("parser get turn '%s' %s from JSON string\n", item->string, value); |
| | | gpio_out(item->string, value); |
| | | } |
| | | } |
| | | |
| | | free(value); /* must free it, or it will result memory leak */ |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | void sub_message_callback(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message) |