Other Parts Discussed in Thread: CC3200
My requirement is to make WiFi to UART bridge. I have used TCP IP socket sdk code and modified it with FreeRTOS in two different task as show below:
//part of code added in the main
osi_TaskCreate( UART_to_WiFi, "WiFi_Tx",\
OSI_STACK_SIZE, NULL, 3, NULL );
/* Task creation for Data from WiFi to UART */
osi_TaskCreate( WiFi_to_UART, "WiFi_Rx",\
OSI_STACK_SIZE, NULL, 2, NULL );
/* Start the scheduler */
osi_start();
//UART_to_WiFi code
static void UART_to_WiFi(void *pvParameters)
{
/* local variables */
char tx_buffer[1024];
int index = 0;
char chr;
while(1)
{
/* clearing data */
memset(tx_buffer,'\0',sizeof(tx_buffer));
/* Read data from UART */
for(;;)
{
chr = UartGetChar();
if(chr == '\n')
{
tx_buffer[index] = chr;
index = 0;
break;
}
else
{
tx_buffer[index] = chr;
index++;
}
}
if(strlen(tx_buffer) > 0)
{
/* Sending data over WiFi */
int err = sl_Send(sock, tx_buffer, strlen(tx_buffer), 0);
if( err < 0 )
{
UART_PRINT("Error occurred during sending data \n\r");
}
}
/* Task delay */
osi_Sleep(12);
}
}
//WiFi_to_UART code
static void WiFi_to_UART(void *pvParameters)
{
/* local variables */
char rx_buffer[1024];
int index = 0;
while(1)
{
/* clearing data */
memset(rx_buffer,'\0',sizeof(rx_buffer));
/* Receiving data over wifi */
int err = sl_Recv(sock, rx_buffer, sizeof(rx_buffer), 0);
if(err > 0)
{
/* Write data to the UART */
while(index < strlen(rx_buffer))
{
UartPutChar(rx_buffer[index]);
index++;
}
index = 0;
}
/* Task delay */
osi_Sleep(15);
}
}
The issue is that data its getting transmitted over WiFi but for the first time recv() function is not working. Due to this, the data is mismatching i.e. 2 Tx data is the 1Rx data and 3rd Tx data is the 2 Rx data and so on.
Addditionally, the socket function is as show below:
void socket_connect()
{
/* Socket variables */
int iStatus;
SlSockAddrIn_t sAddr;
int iAddrSize;
/* Assign values to variables */
sAddr.sin_family = SL_AF_INET;
sAddr.sin_port = sl_Htons((unsigned short)g_uiPortNum);
sAddr.sin_addr.s_addr = sl_Htonl((unsigned int)g_ulDestinationIp);
iAddrSize = sizeof(SlSockAddrIn_t);
while(1)
{
/* Socket creation */
sock = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
if( sock < 0 )
{
UART_PRINT("Socket is not created \r\n");
}
else
{
UART_PRINT("Socket has been created \r\n");
}
/* Socket connection */
iStatus = sl_Connect(sock, ( SlSockAddr_t *)&sAddr, iAddrSize);
if( iStatus < 0 )
{
UART_PRINT("Socket disconnected ... \r\n");
}
else
{
UART_PRINT("Socket has successfully connected \r\n");
/* Show Green LED when socket is created successfully */
GPIO_IF_LedOn(MCU_GREEN_LED_GPIO);
break;
}
}
}
To the above, I have tried Non-blocking method, the client is getting connected to WiFi and socket but when during send function I am getting error code as -1
Can you please tell where the issue is going on?
Thanks,
Devaharsha