2021-06-27 01:07 AM
I connect with the module to an Access Point and get IP. Now I have some devices connected to the same Access Point. I want to receive UDP packets from the devices.
What should I do? I can connect only with TCP
if (WIFI_StartServer(SOCKET, WIFI_TCP_PROTOCOL , 1, "", PORT) == WIFI_STATUS_OK)
USART_SendString(SYS_USART, "Start server - SUCCESS\r");
else
USART_SendString(SYS_USART, "Start server - ERROR\r");
WIFI_UDP_PROTOCOL connection fails. How can I get UDP packets?
2021-06-27 03:34 AM
OK. I connect to AP and set UDP server
ES_WIFI_Status_t ES_WIFI_StartUdpServer(ES_WIFIObject_t *Obj, uint16_t port)
{
ES_WIFI_Status_t ret = ES_WIFI_STATUS_ERROR;
//Select UDP Protocol
sprintf((char*)Obj->CmdData, "P1=1\r");
ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData);
if( ret == ES_WIFI_STATUS_OK)
{
//Set Port
sprintf((char*)Obj->CmdData,"P2=%d\r", port);
ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData);
if( ret == ES_WIFI_STATUS_OK)
{
//Start UDP Comm Server
sprintf((char*)Obj->CmdData, "P5=1\r");
ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData);
}
}
return ret;
}
I get
WIFI INIT OK
MAC ADDRESS C4:7F:51:7:B5:A5
Connected: Got IP Address 172.16.1.120
UDP server - SUCCESS
Now I receive a data
ES_WIFI_Status_t ES_WIFI_AltReceiveData(ES_WIFIObject_t *Obj, uint8_t Socket, uint8_t *pdata, uint16_t Reqlen, uint16_t *Receivedlen, uint32_t Timeout)
{
uint32_t wkgTimeOut;
ES_WIFI_Status_t ret = ES_WIFI_STATUS_ERROR;
if (Timeout == 0)
{
wkgTimeOut = NET_DEFAULT_NOBLOCKING_READ_TIMEOUT;
}
else
{
wkgTimeOut = Timeout;
}
LOCK_WIFI();
if(Reqlen <= ES_WIFI_PAYLOAD_SIZE )
{
sprintf((char*)Obj->CmdData,"R1=%d\r", Reqlen);
ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData);
if(ret == ES_WIFI_STATUS_OK)
{
sprintf((char*)Obj->CmdData,"R2=%lu\r", wkgTimeOut);
ret = AT_ExecuteCommand(Obj, Obj->CmdData, Obj->CmdData);
if(ret == ES_WIFI_STATUS_OK)
{
sprintf((char*)Obj->CmdData,"R0\r");
ret = AT_RequestReceiveData(Obj, Obj->CmdData, (char *)pdata, Reqlen, Receivedlen);
if (ret != ES_WIFI_STATUS_OK)
{
DEBUG("AT_RequestReceiveData failed\n");
}
}
else
{
DEBUG("setting timeout failed\n");
}
}
else
{
DEBUG("setting requested len failed\n");
*Receivedlen = 0;
}
}
UNLOCK_WIFI();
return ret;
}
On
sprintf((char*)Obj->CmdData,"R0\r");
ret = AT_RequestReceiveData(Obj, Obj->CmdData, (char *)pdata, Reqlen, Receivedlen);
I get - ret = ES_WIFI_STATUS_UNEXPECTED_CLOSED_SOCKET
What's wrong?