Mario Ghecea

Major Failure on SPWF04 during wifi_socket_client_write()

Discussion created by Mario Ghecea on Nov 8, 2017
Latest reply on Nov 11, 2017 by Gerardo Gallucci

After about one full hour or sometimes two of continuous cloud writes the following line fails : 


WiFi_Status_t wifi_socket_client_write(uint8_t sock_id, uint16_t DataLength, char * pData)
/* AT+S.SOCKW=00,11<cr> */
WiFi_Status_t status = WiFi_MODULE_SUCCESS;

//Check if sock_id is open
return WiFi_NOT_READY;

if(DataLength>=1021 || DataLength<=0)

status = USART_Receive_AT_Resp( );
return status;


I don't mean any disrespect, but most of the wait events testing for io completion should have an escape clause...This is very bad programming practice to hang the socket or the WIFI Reset and many other such layers waiting for commands to arrive or complete an action! I would honestly even go as far as saying most of the code is a disaster waiting to happen...I have gone quite far enough to make sure that the code does not hang during socket recovery or socket hangs and even wifi disconnects. But lines such as the ones below are death-traps waiting to happen! 



void Queue_Client_Write_Event(uint8_t sock_id, uint16_t DataLength, char * pData)
WiFi_Counter_Variables.curr_DataLength = DataLength;
WiFi_Counter_Variables.curr_data = pData;
WiFi_Counter_Variables.curr_sockID = sock_id;

wifi_instances.wifi_event.event = WIFI_CLIENT_SOCKET_WRITE_EVENT;
push_eventbuffer_queue(&wifi_instances.event_buff, wifi_instances.wifi_event);



* @brief Wait_For_Sock_Read_To_Complete
* Wait till sock read is over and the OK of read arrives
* @param None
* @retval None
void Wait_For_Sock_Read_To_Complete(void)
//wait if read is ongoing or read OK is yet to arrive
while(IO_status_flag.sock_read_ongoing == WIFI_TRUE ||
(IO_status_flag.prevent_push_OK_event == WIFI_TRUE && IO_status_flag.client_socket_close_ongoing != WIFI_TRUE)) // to make sure the prevent_push_OK_event is of socket read and not of socket close.
__NOP(); //nothing to do     <- Death Trap! This will hang here FOREVER...


How can I make this code production ready for hardware devices to cloud propagation when such things exist all over the place ? We need timeout elements in all such blocking code! 


Any idea why these happen and have not been fixed ?


Mario G.