Exemple #1
0
void ICACHE_FLASH_ATTR user_event_raise(char *url, char *data) {
	if (data == NULL || os_strlen(data) == 0) {
		return;
	}
	
	uint16 event_size = 
		WEBSERVER_MAX_VALUE + 
		(url == NULL ? 0 : os_strlen(url)) + 
		os_strlen(data)
	;
	
	char event[event_size];
	user_event_build(event, url, data);
	
	if (url == NULL) {
		websocket_send_message(EVENTS_URL, data, NULL);
		long_poll_response(EVENTS_URL, data);
	} else {
		// WebSockets
		websocket_send_message(url, data, NULL);
		websocket_send_message(EVENTS_URL, event, NULL);
		
		// Long Polls
		long_poll_response(url, data);
		long_poll_response(EVENTS_URL, event);
	}
	
	// POST to IoT server
	if (user_config_events_websocket()) {
		webclient_socket(
			user_config_events_ssl(),
			user_config_events_user(),
			user_config_events_password(),
			user_config_events_server(),
			user_config_events_ssl() ?
				WEBSERVER_SSL_PORT
				:
				WEBSERVER_PORT
			,
			user_config_events_path(),
			event
		);
	} else {
		webclient_post(
			user_config_events_ssl(),
			user_config_events_user(),
			user_config_events_password(),
			user_config_events_server(),
			user_config_events_ssl() ?
				WEBSERVER_SSL_PORT
				:
				WEBSERVER_PORT
			,
			user_config_events_path(),
			event
		);
	}
}
Exemple #2
0
void ICACHE_FLASH_ATTR user_event_raise(char *url, char *data) {
	if (data == NULL || os_strlen(data) == 0) {
		return;
	}
	
	uint16 event_size = 
		WEBSERVER_MAX_VALUE + 
		(url == NULL ? 0 : os_strlen(url)) + 
		os_strlen(data)
	;
	
	char *event = (char *)os_malloc(event_size);
	if (event == NULL) {
#if EVENTS_DEBUG
		debug("EVENTS: Cannot allocate memory\n");
#endif
		return;
	}
	
	user_event_build(event, url, data);
	
	if (url == NULL) {
		websocket_send_message(EVENTS_URL, data, NULL);
		long_poll_response(EVENTS_URL, data);
	} else {
		// WebSockets
		websocket_send_message(url, data, NULL);
		websocket_send_message(EVENTS_URL, event, NULL);
		
		// Long Polls
		long_poll_response(url, data);
		long_poll_response(EVENTS_URL, event);
	}
	
	// POST to IoT server
	if (user_config_events_websocket()) {
		webclient_socket(
			user_config_events_ssl(),
			user_config_events_user(),
			user_config_events_password(),
			user_config_events_server(),
			user_config_events_ssl() ?
				WEBSERVER_SSL_PORT
				:
				WEBSERVER_PORT
			,
			user_config_events_path(),
			event
		);
	} else {
		webclient_post(
			user_config_events_ssl(),
			user_config_events_user(),
			user_config_events_password(),
			user_config_events_server(),
			user_config_events_ssl() ?
				WEBSERVER_SSL_PORT
				:
				WEBSERVER_PORT
			,
			user_config_events_path(),
			event
		);
	}
	os_free(event);
}