This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3200 WiFi TCP Socket failed to send data when Camera module is continuously running

Other Parts Discussed in Thread: CC3200

Hi,

Scenario:

Just like most examples from CC3200 sdk, I created a new task for initializing Simplelink, connecting to an AP and setting up a TCP socket server within an single FreeRTOS task.

After a client has been connected to CC3200 (using nodejs), the CC3200 client socket will be set as NON-BLOCKING socket, and the simplelink task started initializing camera module etc and start receiving DMA and end-of-frame interrupts CONTINUOUSLY.

The difference between my application and the Websocket Camera example is that, I NEVER STOP the camera, and all image frames are continuously feeded into a circular buffer(with some properties to remember all starting points of a frame).

When a new frame was detected (in a while loop checking if new frames are buffered in, everything here is 100% correct), that Simplelink task start sending the frame over the connected socket. HOWEVER, non of the data were actually being received from client side (nodejs), not at all, not a bit. After about 6KB ~ 30KB of data being "SENT" from CC3200, the sl_Send started reporting error code -11 (note: it's been set to NON-BLOCKING socket), which is TRY_AGAIN.

However, if I get rid of Camera module for a moment, only sending 1000 arrays of 1024 sized buffer to the socket, everything just go fine, so I'm very curious whether the camera module holds an higher priority and the WiFi process never get a chance to send the data?

Anyone has any idea?

int camera_send_frame (int sock, uint8_t* buf, uint32_t len, int mode) {
	mediap_t sock_media;
	int media_sent = 0;
	int snd, snt;
	//long lNonBlocking = 0;
	sock_media.magic = 0xFEED;
	sock_media.meta = mode;
	sock_media.image_width = x_pixels_size;
	sock_media.image_height = y_pixels_size;
	sock_media.length = len;
	// try sync mode
	//int iStatus = sl_SetSockOpt(sock, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &lNonBlocking, sizeof(lNonBlocking));
	// Send data over socket
	UART_PRINT("Sending %d bytes via socket \n\r", len);
	while (len > 0) {
		if (!media_sent) {
			snt = sl_Send (sock, &sock_media, sizeof(sock_media), 0);
			UART_PRINT("SND: %d, SNT: %d \n\r", sizeof(sock_media), snt);
			media_sent = 1;
		}
		snd = len > 1024? 1024: len;
		snt = sl_Send (sock, buf, snd, 0);
		UART_PRINT("SND: %d, SNT: %d \n\r", snd, snt);
		if (snt == SL_EAGAIN || !snt) continue;
		if (snt < 0) {
			return CAMERA_ERROR_SOCKET;
		}
		buf += snt;
		len -= snt;
	}
	return mode;
}

int camera_shoot_video (int sock, int* control) {
	int index = 0;
	int cmd = CAMERA_VIDEO_MODE;
	int err = CAMERA_VIDEO_MODE;
	MAP_CameraCaptureStart(CAMERA_BASE);
	while (*control) {
		UART_PRINT("WAITING FOR a FRAME \n\r");
		while (!image_buffer.frame_loc[index] && !frame_error);
		if (frame_error) {
			return CAMERA_ERROR_FRAME_OVERFLOW;
		}
		UART_PRINT("FRAME DONE \n\r");
		uint8_t* buf = (uint8_t*)image_buffer.frame_loc[index];
		uint32_t len = image_buffer.frame_sz[index];
		image_buffer.frame_loc[index] = NULL;
		image_buffer.frame_sz[index] = 0;
		index = (++index)%2;
		// Send data over socket
		err = camera_send_frame(sock, buf, len, CAMERA_VIDEO_MODE);
		if (err != CAMERA_VIDEO_MODE) break;
		// receive cmd from sock
		int16_t rcvd = sl_Recv(sock, &cmd, 1, 0);
		if (rcvd == SL_EAGAIN || !rcvd) continue;
		if (rcvd < 0) {
			err= CAMERA_ERROR_SOCKET;
			break;
		}
		err = cmd;
		break;
	}
	MAP_CameraCaptureStop(CAMERA_BASE, true);
	return err;
}

The logs below illustrates that initially, sl_Send sends some data "Successfully" which is not because the client side(nodejs) has never received any data. Then after it continues returning error code -11.

[CAMERA MODULE] init camera done.
WAITING FOR a FRAME
# CI EOF 27
FRAME DONE
Sending 6912 bytes via socket
SND: 12, SNT: 12
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 768, SNT: 768
WAITING FOR a FRAME
# CI EOF 28
FRAME DONE
Sending 7168 bytes via socket
SND: 12, SNT: 12
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
WAITING FOR a FRAME
# CI EOF 28
FRAME DONE
Sending 7168 bytes via socket
SND: 12, SNT: 12
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
WAITING FOR a FRAME
# CI EOF 32
FRAME DONE
Sending 8192 bytes via socket
SND: 12, SNT: 12
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
WAITING FOR a FRAME
# CI EOF 32
FRAME DONE
Sending 8192 bytes via socket
SND: 12, SNT: 12
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
WAITING FOR a FRAME
# CI EOF 32
FRAME DONE
Sending 8192 bytes via socket
SND: 12, SNT: 12
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
WAITING FOR a FRAME
# CI EOF 32
FRAME DONE
Sending 8192 bytes via socket
SND: 12, SNT: 12
SND: 1024, SNT: 1024
SND: 1024, SNT: 1024
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11
SND: 1024, SNT: -11

  • Update: I just lower the camera clocking and now the client side can receive some data for about 10 secs and then CC3200 blocks and fails sending new data. Camera module is stilling running with DMA and End-Of-Frame interrupts feeding new data.

    Update 2: For the Websocket camera example, if I change the Camera clocking speed faster enough, browser will also not be able to receive any data. And the CC3200 will report SOCKET ERROR -107.

    TI: Would you be able to reproduce this kind of error on your side?

  • Hi Yunfeng,


    We will look into this and get back to you.


    Regards,
    Aashish
  • Hi Ashish, Thank you. please keep me updated.
  • Hi Aashish,

    Would you be able to do a quick verfication? If you change the Websocket Camera Example to be running as station (connect to CC3200 on browser using IP), then, no matter what speed camera have, you always receive socket error -107.

    Pretty sure it's something related to STATION mode. AP mode so far so good.

    Please let me know if you observe the same result.

    Best,
    Yunfeng

  • Hi Yunfeng,


    Interrupt always has higher priority than user task. Ans it seems sender task not getting chance to run as interrupt keep on coming. Also regarding -107 error (transport endpoint is not connected), please make sure server not terminating TCP connection or your application using right socket fd to send data.

    Can you please share all changes you made in websocket app?


    Regards,
    Aashish
  • Hi Aashish,

    Here's the changes I made:

    1. Start Webksocket Camera as STATION mode instead of AP, connect to an AP wait for IP acquired then access the camera_demo.html using IP

    void HttpServerAppTask(void * param)
    {
           lRetVal = Network_IF_InitDriver(ROLE_STA);    // <<<<====== Changed to STATION mode, the original one is AP mode
           ... ...
        // Connect to an AP
        SlSecParams_t secParams = {0};
    
        secParams.Key = (signed char*)SECURITY_KEY;
        secParams.KeyLen = strlen(SECURITY_KEY);
        secParams.Type = SECURITY_TYPE;
    
        lRetVal = sl_WlanConnect((signed char*)SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0); // <<<<<<<====== Connect to an AP.
        ... ...
    }

    2. In order to print out the acquired IP, I also changed to UART_PRINT to be using "PRCM_UARTA1" instead of "PRCM_UARTA0", then 

    MAP_PRCMPeripheralClkEnable(PRCM_UARTA1, PRCM_RUN_MODE_CLK);
    
    MAP_PinTypeUART(PIN_01, PIN_MODE_7); // pin-0 as TX pin, no RX pin required.

    3. In order to use UART1 you also have to change the following in uart_if.h file:

    #define CONSOLE         UARTA1_BASE   // << ==== original is UARTA0_BASE
    #define CONSOLE_PERIPH  PRCM_UARTA1   // << ==== original is PRCM_UARTA0

    I'm sure that TCP socket was never been terminated. (CC3200 is running as server), and the socket fd is correct.

    The problem only exist of you switched Websocket camera WLAN from AP mode to STATION mode. In that case, sender never sends data.

    What's the best way to find out whether the simplelink is not sending data out? Why is this only happening in STATION mode when Camera module is used? Beware, if I'm not using Camera module at all, the STATION can send out data without any issue no matter CC3200 is in AP or STATION mode.

    Would you be able to reproduce this from your side and let me know? Would be you be able to point out the simplelink codes that is responsible for sending data under station mode? I'm curious:

    1. Is the socket sender task ever sends data via SPI to WiFI co-processor? If not, then that's the issue.

    2. If yes, then is the WiFi co-processor ever sends the data? I believe that's inside of servicepack functions, right?

    3. What's the differen when the sender task is running under AP mode and STATION mode? What difference could cause sender task succeed in AP and fail in STATION mode?

    Error logs from simplink callback event:

    [SOCK ERROR] - TX FAILED  :  socket 21 , reason (-107)
    
                                                           [SOCK ERROR] - TX FAILED  :  socket 21 , reason (-107)
    
                                    [SOCK ERROR] - TX FAILED  :  socket 21 , reason (-107)
    
             [SOCK ERROR] - TX FAILED  :  socket 21 , reason (-107)
    
                                                                    [SOCK ERROR] - TX FAILED  :  socket 21 , reason (-107)
    
                                             [SOCK ERROR] - TX FAILED  :  socket 21 , reason (-107)
    
                      [SOCK ERROR] - TX FAILED  :  socket 21 , reason (-107)
    
                                                                             [SOCK ERROR] - TX FAILED  :  socket 21 , reason (-107)
    
                                                      [SOCK ERROR] - TX FAILED  :  socket 21 , reason (-107)
    
                               [SOCK ERROR] - TX FAILED  :  socket 21 , reason (-107)

  • Hi Yunfeng,


    We modified websocket_camera example to run in station mode and it is working without any issue. We are able to see images on browser. We did following changes:
    1. in HttpServerAppTask() in httpserverapp.c
    Replace "lRetVal = Network_IF_InitDriver(ROLE_AP);" with "lRetVal = Network_IF_InitDriver(ROLE_STA);"

    2. In Network_IF_InitDriver() in common\network_if.c
    Added below code in else part

    if(uiMode == ROLE_AP)
    {
    //No change
    }
    else if(uiMode == ROLE_P2P)
    {
    //No change
    }
    else
    {
    //Added below code
    lRetVal = sl_WlanSetMode(ROLE_STA);
    if (lRetVal < 0)
    {
    ERR_PRINT(lRetVal);
    LOOP_FOREVER();
    }
    lRetVal = sl_Stop(0xFF);
    if (lRetVal < 0)
    {
    ERR_PRINT(lRetVal);
    LOOP_FOREVER();
    }

    //
    // Assumption is that the device is configured in station mode already
    // and it is in its default state
    //
    lRetVal = sl_Start(0, 0, 0);
    if (lRetVal < 0 || ROLE_STA != lRetVal)
    {
    UART_PRINT("Failed to start the device \n\r");
    LOOP_FOREVER();
    }

    UART_PRINT("Device started as STATION \n\r");

    // Device already started in STA-Mode
    SlSecParams_t secParams = {0};

    secParams.Key = (signed char*)SECURITY_KEY;
    secParams.KeyLen = strlen(SECURITY_KEY);
    secParams.Type = SECURITY_TYPE;

    lRetVal = sl_WlanConnect((signed char*)SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0);
    ASSERT_ON_ERROR(lRetVal);

    // Wait for WLAN Event
    while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
    {
    // Toggle LEDs to Indicate Connection Progress
    MAP_UtilsDelay(800000);
    }
    }

    And recompile the application

    To run:
    1. In browser we type IP acquired by CC3200 and click on "Web camera" tab.
    2. change ws://192.168.1.1 to ws://192.168.1.9 [In our case CC3200 acquired 192.168.1.9 IP] and click on connect
    3. On successful websocket connection click on "send" and after some time we are able to see images


    Can you please review your code once again?


    Regards,
    Aashish
  • Hi Aashish,

    Thanks for the reply. I just changed to your codes and tested. However, it still won't send under XCLK=24MHz (socket error -107). However, if I decrease the XCLK speed from 24Mhz to 6MHz, The Websocket works, picture can be received and displayed on browser in VERY low frame rate. (~2 fps).

    Just let you know that I'm using OV2640 camera instead of MT9D11. OV2640 works fine in 24MHz, super smooth fps under AP mode using raw TCP/IP socket or Websocket. However, it won't send if under STATION mode. It seems to be something related to clock speed, something interferes the WiFi signal? or just not responsive?

    Conclusion of my results:

    Using OV2640 camera,

    1. CC3200 under AP mode, 24Mhz and 6Mhz XCLK both works.

    2. CC3200 under STATION mode, 6Mhz XCLK works, 24Mhz doesn't work( socket error -107).

     

    Do you have any ideas?

    Best,
    Yunfeng

  • Hi Yunfeng,


    As we don't have OV2640 with us so can't test at our end. But we have tested MT9D111 and OV3660 with 24MHz and both are working without any issue. Can you please stop camera by calling MAP_PRCMPeripheralClkDisable for camera before sending data and see whether able to send data or not?


    Regards,
    Aashish
  • Hi Yunfeng,
    I have a board with the OV2640, but I only tested some of the official examples for now (that worked fine).
    If you are ready to share your code, I could test it on my board.
    That could help both of us to move forward with our projects.
    Best regards,
    Tobias
  • Dear Yunfeng,
    Did you already resolve your issue?
    Could you please share your code?

    If your errors are not yet resolved, I could help you checking out your code on my board.

    Best regards,
    Tobias