void ICACHE_FLASH_ATTR pn532_send_read_cmd_cb() { os_timer_disarm(&pn532readID); uint8 uid[4]; uint8 *uidlen; bool a = readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid, &uidlen, 20); uint8 i; if (a) { #ifdef MENJINDEBUG os_printf("\nUID:"); for (i = 0; i < 4; i++) { os_printf("0x%x ", uid[i]); } os_printf("\n"); #endif char *id = "ID:"; hextochar(uidstr, uid, 4); uidstr[8] = '\0'; char *json_buf = NULL; json_buf = (char *) os_zalloc(jsonSize); json_ws_send((struct jsontree_value *) &cardid_info_tree, "cardID", json_buf); MQTT_Publish(&mqttClient, "/tc503/onCardRead", json_buf, strlen(json_buf), 0, 0); os_free(json_buf); json_buf = NULL; } os_timer_arm(&pn532readID, PN532_SEND_READ_CMD_DELAY, 1); }
/****************************************************************************** * dispatch handler *******************************************************************************/ static void ICACHE_FLASH_ATTR scan_dispatch_handler(char *id, struct jsonrpc_transfer *trans, void *buf, int len) { char res_buf[256]; user_wifi_scan_status_t status; DEBUG_PRINTF("begin | id: %s\n", id); param.id = mem_deref(param.id); param.id = mem_ref(id); status = user_wifi_get_scan_status(); if(user_wifi_scan_idle == status) param.scan_status = (0 != user_wifi_scan() ? ssError : ssOk); else param.scan_status = ssOk; json_ws_send((struct jsontree_value *)&scan, "scan", res_buf); trans->send(res_buf, str_len(res_buf)); DEBUG_PRINTF("end\n"); }
void ICACHE_FLASH_ATTR button_press() { ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts // Button interrupt received INFO("BUTTON: Button pressed\r\n"); // Button pressed, flip switch if (GPIO_REG_READ(BUTTON_GPIO) & BIT2) { INFO("BUTTON: Switch off\r\n"); GPIO_OUTPUT_SET(SWITCH03_GPIO, 0); } else { INFO("BUTTON: Switch on\r\n"); GPIO_OUTPUT_SET(SWITCH03_GPIO, 1); } // Send new status to the MQTT broker char *json_buf = NULL; json_buf = (char *)os_zalloc(jsonSize); json_ws_send((struct jsontree_value *)&device_tree, "device", json_buf); INFO("BUTTON: Sending current switch status\r\n"); MQTT_Publish(&mqttClient, config.mqtt_topic_s01, json_buf, strlen(json_buf), 0, 0); os_free(json_buf); json_buf = NULL; // Debounce os_delay_us(200000); // Clear interrupt status uint32 gpio_status; gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS); GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status); ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts }
static void ICACHE_FLASH_ATTR scanres_dispatch_handler(char *id, struct jsonrpc_transfer *trans, void *buf, int len) { int i; struct jsontree_context js_ctx; char res_buf[jsonSize]; DEBUG_PRINTF("begin | id: %s\n", id); param.id = mem_deref(param.id); param.id = mem_ref(id); param.scanresult_list = mem_ref(user_wifi_scan_result()); if(param.scanresult_list) { param.le = list_head(param.scanresult_list); param.totalpage = (scannum / 8) + ((scannum % 8) ? 1 : 0); param.pagenum = 0; jsontree_setup(&js_ctx, (struct jsontree_value *)&scanresult_req, json_putchar); json_parse_buf(&js_ctx, buf, len); if(param.totalpage > 0) { if(param.pagenum >= param.totalpage) param.pagenum = param.totalpage - 1; } DEBUG_PRINTF("page=%d\n", param.pagenum); if(param.pagenum > 0) { int i; struct le *le; struct le *cur; i = (param.pagenum - 1) * 8; le = list_head(param.scanresult_list); while(le && (i > 0)) { cur = le; le = cur->next; --i; } param.le = le; } } os_bzero(res_buf, jsonSize); json_ws_send((struct jsontree_value *)&scanresult_res, "scanresult_res", res_buf); trans->send(res_buf, str_len(res_buf)); param.scanresult_list = mem_deref(param.scanresult_list); DEBUG_PRINTF("end\n"); }
void ICACHE_FLASH_ATTR get_environment_info_cb(void *arg) { os_timer_disarm(&get_environment_info_timer); get_dht11(temperature, humidity); // Send data the MQTT broker if (isNeedSendENV) { char *json_buf = NULL; json_buf = (char *) os_zalloc(jsonSize); json_ws_send((struct jsontree_value *) &environment_tree, "environment", json_buf); MQTT_Publish(&mqttClient, "/tc503/environment", json_buf, strlen(json_buf), 0, 0); os_free(json_buf); json_buf = NULL; } os_timer_arm(&get_environment_info_timer, DELAY, 1); }
int json_test(void) { char json_buffer[32] = {0}; json_ws_send((struct jsontree_value *)&INFOTree, "info", json_buffer); os_printf("[JSON]: = %s \n", json_buffer); //char * parse_string = "{\"v\":100}"; //struct jsontree_context js; //jsontree_setup(&js, (struct jsontree_value *)&msg_tree, json_putchar); //json_parse(&js, parse_string); // os_printf("[JSON]: == %s \n", json_buffer); struct jsontree_context js; char * parse_string2 = "{\"version\":{\"main\":300,\"sub\":200}}"; jsontree_setup(&js, (struct jsontree_value *)&msg_tree_lv2, json_putchar); json_parse(&js, parse_string2); }