Maybe i cant send a message from "Event loop task" to http task ?
wss_server.c file:
Code: Select all
void resp_Ws_With_Message_Sync( httpd_req_t *req, char* message, uint8_t command )
{
ESP_LOGI(TAG, LOG_USER("FUNCTION: %s"), __func__ );
ESP_LOGI(TAG, LOG_USER("Message: %s\n"), message);
ESP_LOGI(TAG, LOG_USER("[%s] req: %p"), __func__, req );
ESP_LOGI(TAG, LOG_USER("[%s] req->aux: %p\n"), __func__, req->aux );
size_t strSize = strlen(message);
init_ws_pkt( 1 + strSize ); // command size + error message size
ws_pkt.payload[0] = command;
for( uint32_t i = 0 ; i < strSize ; i++ )
{
ws_pkt.payload[i+1] = message[i]; // add a message after the command.
}
httpd_ws_send_frame( req, &ws_pkt );
}
my_ota.c file:
Code: Select all
static httpd_req_t* http_req = NULL;
////////////////////////////////////////////////////////////////////////////////////////////
// Send eventhandler messages to phone app and lcd display.
static void send_ota_message( char* message )
{
ESP_LOGI(TAG, LOG_USER("FUNCTION: %s"), __func__ );
ESP_LOGI(TAG, LOG_USER("[%s] http_req: %p\n"), __func__, http_req );
if( http_req != NULL )
{
resp_Ws_With_Message_Sync( http_req, message, req_command );
// send message to lcd display
}
else
{
// send message to lcd display
}
}
////////////////////////////////////////////////////////////////////////////////////////////
// Event handler for catching ota system events
static void ota_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
{
ESP_LOGI(TAG, LOG_USER("FUNCTION: %s"), __func__ );
if( event_base == ESP_HTTPS_OTA_EVENT )
{
switch( event_id )
{
case ESP_HTTPS_OTA_START:
{
ESP_LOGI(TAG, TEXT_OTA_START);
send_ota_message( TEXT_OTA_START ); // calback need to return quickly, try create a task to send the message to websocket client. Send message from this task to new task using queue.
break;
}
case ESP_HTTPS_OTA_CONNECTED:
{
ESP_LOGI(TAG, TEXT_OTA_CONNECTED);
send_ota_message( TEXT_OTA_CONNECTED );
break;
}
case ESP_HTTPS_OTA_GET_IMG_DESC:
{
ESP_LOGI(TAG, TEXT_OTA_GET_IMG_DESC);
send_ota_message( TEXT_OTA_GET_IMG_DESC );
break;
}
case ESP_HTTPS_OTA_VERIFY_CHIP_ID:
{
ESP_LOGI(TAG, TEXT_OTA_VERIFY_CHIP_ID"%d", *(esp_chip_id_t *)event_data);
char* str = NULL;
if( concat_text_int( TEXT_OTA_VERIFY_CHIP_ID, *(esp_chip_id_t *)event_data, &str ) != ESP_OK ) return;
send_ota_message( str );
free(str);
break;
}
case ESP_HTTPS_OTA_DECRYPT_CB:
{
ESP_LOGI(TAG, TEXT_OTA_DECRYPT_CB);
send_ota_message( TEXT_OTA_DECRYPT_CB );
break;
}
case ESP_HTTPS_OTA_WRITE_FLASH:
{
ESP_LOGI(TAG, LOG_USER1(TEXT_OTA_WRITE_FLASH"%d"), *(int *)event_data);
char* str = NULL;
if( concat_text_int( TEXT_OTA_WRITE_FLASH, *(int *)event_data, &str ) != ESP_OK ) return;
send_ota_message( str );
free(str);
break;
}
case ESP_HTTPS_OTA_UPDATE_BOOT_PARTITION:
{
ESP_LOGI(TAG, TEXT_OTA_UPDATE_BOOT_PARTITION"%d", *(esp_partition_subtype_t *)event_data);
char* str = NULL;
if( concat_text_int( TEXT_OTA_UPDATE_BOOT_PARTITION, *(esp_partition_subtype_t *)event_data, &str ) != ESP_OK ) return;
send_ota_message( str );
free(str);
break;
}
case ESP_HTTPS_OTA_FINISH:
{
ESP_LOGI(TAG, TEXT_OTA_FINISH);
send_ota_message( TEXT_OTA_FINISH );
http_req = NULL;
break;
}
case ESP_HTTPS_OTA_ABORT:
{
ESP_LOGI(TAG, TEXT_OTA_ABORT);
send_ota_message( TEXT_OTA_ABORT );
http_req = NULL;
break;
}
}
}
}