void ICACHE_FLASH_ATTR user_websocket_event(char *url, char *data, struct espconn *pConnection) { char event[WEBSERVER_MAX_VALUE + os_strlen(url) + os_strlen(data)]; user_event_build(event, url, data); websocket_send_message(url, data, pConnection); websocket_send_message(EVENTS_URL, event, pConnection); }
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 ); } }
void ICACHE_FLASH_ATTR user_event_progress(uint8 progress) { LOCAL uint8 prev = 0; uint32 heap = system_get_free_heap_size(); if (abs(progress - prev) < 3 || heap < 5000) { return; } prev = progress; char status[WEBSERVER_MAX_VALUE]; char progress_str[WEBSERVER_MAX_VALUE]; json_status(status, ESP8266, json_sprintf(progress_str, "Progress: %d\%", progress), NULL); #if EVENTS_DEBUG debug("EVENTS: Progress [%d]\n", progress); #endif char event[WEBSERVER_MAX_VALUE + os_strlen(webserver_chunk_url()) + os_strlen(status)]; user_event_build(event, webserver_chunk_url(), status); websocket_send_message(EVENTS_URL, event, NULL); }
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); }