Esempio n. 1
0
{
    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;
}

LOCAL struct jsontree_callback version_callback =
                                JSONTREE_CALLBACK(version_get, NULL);

//JSONTREE_OBJECT(hardware,
//                JSONTREE_PAIR("hardware", &version_callback));
                
JSONTREE_OBJECT(INFOTree,
                JSONTREE_PAIR("hardware", &version_callback));



LOCAL int ICACHE_FLASH_ATTR msg_set(struct jsontree_context *js_ctx, struct jsonparse_state *parse)
{
    int type;
    while ((type = jsonparse_next(parse)) != 0)
    {
        if (jsonparse_strcmp_value(parse,"v") == 0)
Esempio n. 2
0
    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;
}

static struct jsontree_callback scan_callback =
    JSONTREE_CALLBACK(scan_get, NULL);

JSONTREE_OBJECT(
    scan_tree,
    JSONTREE_PAIR("id", &scan_callback),
    JSONTREE_PAIR("data", &scan_callback)
);

JSONTREE_OBJECT(
    scan,
    JSONTREE_PAIR("scan", &scan_tree)
);

/******************************************************************************
 * dispatch handler
*******************************************************************************/
#ifdef MENJINDEBUG
				os_printf("\nstudent ID :%s\n", buffer);
#endif
			}
		}
	}
	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;
}
LOCAL struct ICACHE_FLASH_ATTR jsontree_callback humidity_callback =
JSONTREE_CALLBACK(json_get, NULL);
LOCAL struct ICACHE_FLASH_ATTR jsontree_callback temperature_callback =
JSONTREE_CALLBACK(temp_json_get, NULL);
LOCAL struct ICACHE_FLASH_ATTR jsontree_callback cardid_info_tree_cb =
JSONTREE_CALLBACK(card_info_json_get, NULL);
LOCAL struct ICACHE_FLASH_ATTR jsontree_callback userid_info_tree_cb =
JSONTREE_CALLBACK(NULL, user_info_json_set);
LOCAL struct ICACHE_FLASH_ATTR jsontree_callback open_door_cmd_tree_cb =
JSONTREE_CALLBACK(NULL, open_door_cmd_json_set);
JSONTREE_OBJECT(open_door_cmd_tree,
		JSONTREE_PAIR("cmd",&open_door_cmd_tree_cb));
JSONTREE_OBJECT(environment_tree, JSONTREE_PAIR("humidity", &humidity_callback),
		JSONTREE_PAIR("temperature", &temperature_callback));
JSONTREE_OBJECT(cardid_tree, JSONTREE_PAIR("cardID",&cardid_info_tree_cb));
JSONTREE_OBJECT(userid_tree, JSONTREE_PAIR("studentID",&userid_info_tree_cb));
JSONTREE_OBJECT(cardid_info_tree, JSONTREE_PAIR("cardID",&cardid_tree));
                jsonparse_copy_value(parser, buffer, sizeof(buffer));
                if (!strcoll(buffer, "on")) {
                	INFO("JSON: Switch on\n", buffer);
        			GPIO_OUTPUT_SET(SWITCH03_GPIO, 1);
                } else if (!strcoll(buffer, "off")) {
                	INFO("JSON: Switch off\n", buffer);
        			GPIO_OUTPUT_SET(SWITCH03_GPIO, 0);
                }
            }
        }
    }
    return 0;
}

LOCAL struct jsontree_callback switch_callback =
    JSONTREE_CALLBACK(json_get, json_set);
JSONTREE_OBJECT(switch_tree,
                JSONTREE_PAIR("switch", &switch_callback));
JSONTREE_OBJECT(device_tree,
				JSONTREE_PAIR("device", &switch_tree));

void ICACHE_FLASH_ATTR
wifi_connect_cb(uint8_t status)
{
	if(status == STATION_GOT_IP){
		MQTT_Connect(&mqttClient);
	} else {
		MQTT_Disconnect(&mqttClient);
	}
}