Beispiel #1
0
LOCAL bool ICACHE_FLASH_ATTR switch2_parse(char *data, uint16 data_len) {
	struct jsonparse_state parser;
	int type;
	
	int preference1 = switch2_hardware[2].preference;
	int preference2 = switch2_hardware[3].preference;
	
	jsonparse_setup(&parser, data, data_len);
	while ((type = jsonparse_next(&parser)) != 0) {
		if (type == JSON_TYPE_PAIR_NAME) {
			if (jsonparse_strcmp_value(&parser, "Relay1") == 0) {
				jsonparse_next(&parser);
				jsonparse_next(&parser);
				user_switch2_set(0, jsonparse_get_value_as_sint(&parser));
			} else if (jsonparse_strcmp_value(&parser, "Relay2") == 0) {
				jsonparse_next(&parser);
				jsonparse_next(&parser);
				user_switch2_set(1, jsonparse_get_value_as_sint(&parser));
			} else if (jsonparse_strcmp_value(&parser, "Preference1") == 0) {
				jsonparse_next(&parser);
				jsonparse_next(&parser);
				switch2_hardware[2].preference = jsonparse_get_value_as_sint(&parser);
			} else if (jsonparse_strcmp_value(&parser, "Preference2") == 0) {
				jsonparse_next(&parser);
				jsonparse_next(&parser);
				switch2_hardware[3].preference = jsonparse_get_value_as_sint(&parser);
			}
		}
	}
	
	return (
		preference1 != switch2_hardware[2].preference ||
		preference2 != switch2_hardware[3].preference
	);
}
Beispiel #2
0
void ICACHE_FLASH_ATTR relay_handler(
	struct espconn *pConnection, 
	request_method method, 
	char *url, 
	char *data, 
	uint16 data_len, 
	uint32 content_len, 
	char *response,
	uint16 response_len
) {
	struct jsonparse_state parser;
	int type;
	int state = relay_state;
	
	if (method == POST && data != NULL && data_len != 0) {
		jsonparse_setup(&parser, data, data_len);
		
		while ((type = jsonparse_next(&parser)) != 0) {
			if (type == JSON_TYPE_PAIR_NAME) {
				if (jsonparse_strcmp_value(&parser, "Relay") == 0) {
					jsonparse_next(&parser);
					jsonparse_next(&parser);
					state = jsonparse_get_value_as_sint(&parser);
				}
			}
		}
		
		user_relay_set(state);
	}
	
	user_relay_state(response);
}
void ICACHE_FLASH_ATTR mb_pcd8544_handler(
	struct espconn *pConnection, 
	request_method method, 
	char *url, 
	char *data, 
	uint16 data_len, 
	uint32 content_len, 
	char *response,
	uint16 response_len
) {
	struct jsonparse_state parser;
	int type;
	char tmp_str[20];
	
	mb_pcd8544_config_t *p_config = mb_p_pcd8544_config;
	bool is_post = (method == POST);
	int start_cmd = -1;	// 0=STOP, 1=START other none
	uint8 tmp_ret = 0xFF;
	
	// post config for INIT
	if (method == POST && data != NULL && data_len != 0) {
		jsonparse_setup(&parser, data, data_len);
		while ((type = jsonparse_next(&parser)) != 0) {
			if (type == JSON_TYPE_PAIR_NAME) {
				if (jsonparse_strcmp_value(&parser, "Reset_pin") == 0) {
					jsonparse_next(&parser);jsonparse_next(&parser);
					p_config->resetPin = jsonparse_get_value_as_sint(&parser);
					MB_PCD8544_DEBUG("PCD8544:CFG:Reset_pin:%d\n", p_config->resetPin);
				} else if (jsonparse_strcmp_value(&parser, "Sce_pin") == 0) {
					jsonparse_next(&parser);jsonparse_next(&parser);
					p_config->scePin = jsonparse_get_value_as_sint(&parser);
					MB_PCD8544_DEBUG("PCD8544:CFG:Sce_pin:%d\n", p_config->scePin);
				} else if (jsonparse_strcmp_value(&parser, "Dc_pin") == 0) {
					jsonparse_next(&parser);jsonparse_next(&parser);
					p_config->dcPin = jsonparse_get_value_as_sint(&parser);
					MB_PCD8544_DEBUG("PCD8544:CFG:Dc_pin:%d\n", p_config->dcPin);
				} else if (jsonparse_strcmp_value(&parser, "Sdin_pin") == 0) {
					jsonparse_next(&parser);jsonparse_next(&parser);
					p_config->sdinPin = jsonparse_get_value_as_sint(&parser);
					MB_PCD8544_DEBUG("PCD8544:CFG:Sdin_pin:%d\n", p_config->sdinPin);
				} else if (jsonparse_strcmp_value(&parser, "Sclk_pin") == 0) {
					jsonparse_next(&parser);jsonparse_next(&parser);
					p_config->sclkPin = jsonparse_get_value_as_sint(&parser);
					MB_PCD8544_DEBUG("PCD8544:CFG:Sclk_pin: %d\n", p_config->sclkPin);
				} else if (tmp_ret = user_app_config_handler_part(&parser) != 0xFF){	// check for common app commands
					MB_PCD8544_DEBUG("PCD8544:CFG:APPCONFIG:%d\n", tmp_ret);
				}
				else if (jsonparse_strcmp_value(&parser, "Goto_xy") == 0) {		// 11,22
					is_post = false;
					jsonparse_next(&parser);jsonparse_next(&parser);
					char tmp_goto[32];
					jsonparse_copy_value(&parser, tmp_goto, 32);
					char *p_comma = (char *)os_strstr(tmp_goto, ",");
					if (tmp_goto > 0 && p_comma - tmp_goto < 32) {
						char tmp_goto_[32];
						strncpy(tmp_goto_, tmp_goto, p_comma - tmp_goto - 1);
						int goto_x = atoi(tmp_goto_);
						tmp_goto_[0] = 0x00;
						strncpy(tmp_goto_, p_comma+1, 32);
						int goto_y = atoi(tmp_goto_);
						PCD8544_gotoXY(goto_x, goto_y);
						MB_PCD8544_DEBUG("PCD8544:Goto_x/y:%d/%d\n", goto_x, goto_y);
					}
					MB_PCD8544_DEBUG("PCD8544:Goto_x/y:NA\n");
				} else if (jsonparse_strcmp_value(&parser, "") == 0) {
					is_post = false;
					jsonparse_next(&parser);jsonparse_next(&parser);
					char tmp_str[128];
					jsonparse_copy_value(&parser, tmp_str, MB_VARNAMEMAX);
					PCD8544_lcdPrint(tmp_str);
					MB_PCD8544_DEBUG("PCD8544:lcdPrint:%s\n", tmp_str);
				}
			}
		}

		if (is_post) {
			mb_pcd8544_hw_init();
		}
	}
	
	mb_PCD8544_set_response(response, false, is_post ? MB_REQTYPE_POST : MB_REQTYPE_GET);
}