LOCAL int ICACHE_FLASH_ATTR temp_json_get(struct jsontree_context *js_ctx) { const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1); if (os_strncmp(path, "temperature", 11) == 0) { jsontree_write_string(js_ctx, temperature); } return 0; }
LOCAL int ICACHE_FLASH_ATTR json_get(struct jsontree_context *js_ctx) { const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1); if (os_strncmp(path, "humidity", 8) == 0) { jsontree_write_string(js_ctx, humidity); } return 0; }
LOCAL int ICACHE_FLASH_ATTR json_get(struct jsontree_context *js_ctx) { const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1); if (os_strncmp(path, "switch", 6) == 0) { jsontree_write_string(js_ctx, GPIO_REG_READ(BUTTON_GPIO) & BIT2 ? "on" : "off"); } return 0; }
LOCAL int ICACHE_FLASH_ATTR version_get(struct jsontree_context *js_ctx) { const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1); char string[32]; os_printf("got %s \n", path); if (os_strncmp(path, "hardware", 8) == 0) { os_sprintf(string, "0.1"); } jsontree_write_string(js_ctx, string); return 0; }
/****************************************************************************** * scan *******************************************************************************/ static int ICACHE_FLASH_ATTR scan_get(struct jsontree_context *js_ctx) { const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1); if (os_strncmp(path, "id", 2) == 0) { jsontree_write_string(js_ctx, param.id); } else if (os_strncmp(path, "data", 4) == 0) { jsontree_write_string(js_ctx, ssOk == param.scan_status ? "OK" : "ERROR"); } return 0; }
LOCAL int ICACHE_FLASH_ATTR card_info_json_get(struct jsontree_context *js_ctx) { const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1); jsontree_write_string(js_ctx, uidstr); return 0; }
/****************************************************************************** * FunctionName : scan_get * Description : set up the scan data as a JSON format * Parameters : js_ctx -- A pointer to a JSON set up * Returns : result *******************************************************************************/ LOCAL int ICACHE_FLASH_ATTR scanres_get(struct jsontree_context *js_ctx) { const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1); struct user_wifi_scanresult *sr = NULL; if(param.le) sr = param.le->data; if (os_strncmp(path, "id", 2) == 0) { jsontree_write_string(js_ctx, param.id); } else if (os_strncmp(path, "totalpage", 9) == 0) { jsontree_write_int(js_ctx, param.totalpage); } else if (os_strncmp(path, "pagenum", 7) == 0) { jsontree_write_int(js_ctx, param.pagenum); } else if (os_strncmp(path, "bssid", 5) == 0) { jsontree_write_string(js_ctx, sr ? sr->bssid : ""); } else if (os_strncmp(path, "ssid", 4) == 0) { jsontree_write_string(js_ctx, sr ? sr->ssid : ""); } else if (os_strncmp(path, "rssi", 4) == 0) { jsontree_write_int(js_ctx, sr ? -(sr->rssi) : 0); } else if (os_strncmp(path, "authmode", 8) == 0) { if(sr) { struct le *cur = param.le; param.le = cur->next; switch(sr->authmode) { case AUTH_OPEN: jsontree_write_string(js_ctx, "OPEN"); break; case AUTH_WEP: jsontree_write_string(js_ctx, "WEP"); break; case AUTH_WPA_PSK: jsontree_write_string(js_ctx, "WPAPSK"); break; case AUTH_WPA2_PSK: jsontree_write_string(js_ctx, "WPA2PSK"); break; case AUTH_WPA_WPA2_PSK: jsontree_write_string(js_ctx, "WPAPSK/WPA2PSK"); break; default : jsontree_write_int(js_ctx, sr->authmode); break; } } else jsontree_write_string(js_ctx, ""); } return 0; }