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.

websock_camera InitCameraComponents() function problem

Other Parts Discussed in Thread: CC3200, HDC1050

Hi,

I am working around with CC3200 websock_camera example and i am having some troubles in function InitCameraComponents: I can connect to the soft AP mysimplelink-<MAC ADRR> and open the url 192.168.1.1/camera_demo.html, then open a websocket to the CC3200, everything works fine. But i cant receive any images from the camera, i got stuck in function CameraSensorInit() in InitCameraComponents(). When i dig deeper, i find out there is a problem with

I2CBufferWrite  in for loop. 

:

static long RegLstWrite(s_RegList *pRegLst, unsigned long ulNofItems) {
	unsigned long ulNdx;
	unsigned short usTemp;
	unsigned char i;
	unsigned char ucBuffer[20];
	unsigned long ulSize;
	long lRetVal = -1;

	if (pRegLst == NULL) {
		UART_PRINT("\r\nDebug InitCameraComponents - 1\r\n");
		return RET_ERROR;
	}

	for (ulNdx = 0; ulNdx < ulNofItems; ulNdx++) {
		if (pRegLst->ucPageAddr == 100) {
			// PageAddr == 100, insret a delay equal to reg value
			MT9D111Delay(pRegLst->usValue * 80000 / 3);
			UART_PRINT("\r\nDebug InitCameraComponents - 2\r\n");
		} else if (pRegLst->ucPageAddr == 111) {
			UART_PRINT("\r\nDebug InitCameraComponents - 3\r\n");
			// PageAddr == 111, wait for specified register value
			do {
				ucBuffer[0] = pRegLst->ucRegAddr;
				lRetVal = I2CBufferWrite(CAM_I2C_SLAVE_ADDR, ucBuffer, 1, 1);
				ASSERT_ON_ERROR(lRetVal);
				if (I2CBufferRead(CAM_I2C_SLAVE_ADDR, ucBuffer, 2, 1)) {
					return RET_ERROR;
				}

				usTemp = ucBuffer[0] << 8;
				usTemp |= ucBuffer[1];
			} while (usTemp != pRegLst->usValue);
		} else {
			UART_PRINT("\r\nDebug InitCameraComponents - 4\r\n");
			// Set the page
			ucBuffer[0] = SENSOR_PAGE_REG;
			ucBuffer[1] = 0x00;
			ucBuffer[2] = (unsigned char) (pRegLst->ucPageAddr);
			//
			// ==> The following I2CBufferWrite never complete
			// 
			if (0 != I2CBufferWrite(CAM_I2C_SLAVE_ADDR, ucBuffer, 3,
			I2C_SEND_STOP)) {
				UART_PRINT("\r\nDebug InitCameraComponents - 5\r\n");
				return RET_ERROR;
			}

Please help me to solve this problem.

Thank you very much.

Regards,

N.T

192.168.1.1/camera_demo.html

  • Hi NT,

    From above description it's clear that i2c is not working. Pleas check all connection are proper.

    Regards,

    Aashish

  • Hi Aashish,
    - I have misunderstood the code flow: I see that the function gets stuck at ulNdx = 1, then i think that there was a successful I2C transaction before (ulNdx = 0).
    - I test the I2C connection with an HDC1050 sensor and it works fine but i still cant read data from mt9d111, so i think there are some problems with my mt9d111 camera board. Then i add an 10K pull-down resistor t0 the DEN pin of mt9d111, then i can read value 0x1519 from register 0x00 of mt9d111 via i2c connection. But i still cannot get image from mt9d111 and I am digging deeper to get images from mt9d111.
    Thanks for your support.
    Regards,
    N.T
  • Hi NT,


    Is it CameraSensorInit() going through or not. If not then I2C operation with camera sensor is failing in between or not working at all. And loose connections are very common cause of I2C operation failure with camera sensor. Please make sure connection and contacts are proper. Please share logic analyzer capture for I2C operation.


    Regards,
    Aashish
  • Hi Aashish,

    - I think I2C operation with camera sensor is working well because i can read some register data from camera sensor with I2C connection.

    - I've modified static long RegLstWrite(s_RegList *pRegLst, unsigned long ulNofItems) function in mt9d111.c:

    => Replace I2CBufferWrite function with I2C_IF_Write function.

    => Replace I2CBufferRead funtion with I2C_IF_Read function.

    After these changes, function CameraSensorInit() is done, but the code get stuck at function StartSensorInJpegMode. I debug and see it's stucked at { 0, 0x20, 0x0000 },      // READ_MODE_B (Image flip settings) entry in capture_cmds_list[] array.

    Regards,

    N.T

  • Hi NT,

    Please use I2CBufferWrite/Read only. As we requested last time please share logic analyzer capture for I2C.

    Regards,

    Aashish 

  • Hi Aashish,

    It's hardware problem. I have removed the daughter board and connected CC3200LPX to MT9D111 camera module directly then everything has worked well, i could get stream images.

    By the way, why should we use I2CBufferWrite/Read only?

    Thank you very much for your support.
    Regards,
    N.T
  • Hi NT,

    I2C_IF_Write/Read uses timeout for write/read operation where as I2CBufferWrite/Read continuously try to perform write/read. As you mentioned in previous post after using I2C_IF_Write CameraSensorInit() was passing through but stuck in StartSensorInJpegMode(). So we are suspecting may because of timeout in I2C_IF_Write CameraSensorInit() passing through and in real it didn't initialize camera sensor so it stuck in StartSensorInJpegMode().

    Please close the thread if issue is reolved.


    Regards,
    Aashish
  • Hi Aashish,

    With my current hardware, if i use I2CBufferWrite/Read functions, the CameraSensorInit cant be done, it gets stuck. And how many connection can connect to websocket at a same time to get streamming data? I read the Httpcore.c and see there is a define that allow maximum 10 connections, but when i test, just 1 connection can get data.

    Regards,
    N.T

    P/s: please help me close the topic, i dont know how to close it. Thanks.

  • Hi NT,


    Current library support at max 10 HTTP connection. Number of web-socket connection depend upon implementation of WebSocketRecvEventHandler(). In current example we are handling only one connection by creating only one thread.


    Regards,
    Aashish
  • Hi Aashish,

    I am trying to make websock_camera application work like an IP camera. I have modifed the implementation of CameraAppTask() that allow the cc3200 to send jpeg images to multiple connections at the same time. The problem is is If i have loaded the webpage \camera_demo.html on browsers before and open websocket connections to cc3200 then i can get streaming video on multiple clients at the same time, but if i currently streaming video on a connections then i load the html webpage on another connections, the program gets stuck. Would you mind to give me some ideas to solve that problem?

    1 more question: why does the system get stuck when it meets socket async event [SOCK ERROR] - TX FAILED with reason code (-107)?

    Thanks for your support,
    Regards,
    N.T

  • Hi NT,

    Are you trying to open multiple connection on same IP? If you are using same IP with different browser than you need to implement web session. Please share the changes for review.

    Regards,

    Aashish

  • Hi Aashish,

    I have done some simple changes with the idea:

    - Send image capture to all opened websocket connection

    - If image is capturing, then reject all connection request

    - If there is a html reload request, then dont do capture and send image

    So i change the code:

    - I added a global variable g_ucConnIndex[HTTP_CORE_MAX_CONNECTIONS] in httpserverapp to manage websocket connections connect to the webserver then send image to these websocket connections via a loop:

    unsigned char g_ucConnIndex[HTTP_CORE_MAX_CONNECTIONS]; // use to manage connections
    unsigned char g_ucPrintDebugCnt = 0; // use to print debug sentenses slowly
    unsigned char g_ucCapturing = 0; // use to flag whenever camera is capturing
    
    void CameraAppTask(void *param) {
        UINT8 Opcode = 0x02;
        struct HttpBlob Write;
        int i;
    
        UART_PRINT("\r\nInitCameraComponents() --> Starts\r\n");
        InitCameraComponents(640, 480);
        UART_PRINT("\r\nInitCameraComponents() --> Finish\r\n");
    
        while (1) {
            if (g_close == 0) {
            // If there is a html page reload request, dont capture and send images    

    for (i = 0; i < HTTP_CORE_MAX_CONNECTIONS; i++) { if (g_ucConnIndex[i] == 2) { if (g_ucPrintDebugCnt == 1) { UART_PRINT("\r\ng_ucConnIndex[%d] == 2\r\n", i); } goto wait; } } // Capture image Write.uLength = StartCamera((char **) &Write.pData); // Send image to websocket connections for (i = 0; i < HTTP_CORE_MAX_CONNECTIONS; i++) { if (g_ucConnIndex[i] == 1) { if (!sl_WebSocketSend(i, Write, Opcode)) { while (1) { if (g_ucPrintDebugCnt == 1) { UART_PRINT( "\r\nRemove connection %d from camera sending queue.\r\n", i); } HttpCore_CloseConnection(i); g_ucConnIndex[i] = 0; break; } } if (g_ucPrintDebugCnt == 1) { UART_PRINT("\r\nSend data to client %d\r\n", i); } } } wait: i = 0; } // Added by Thinh TN else { if (g_ucPrintDebugCnt == 1) { UART_PRINT("\r\nAll clients disconnected.\r\n"); } for (i = 0; i < HTTP_CORE_MAX_CONNECTIONS; i++) g_ucConnIndex[i] = 0; if (g_iCameraTaskHdl != 0) { osi_TaskDelete(&g_iCameraTaskHdl); g_iCameraTaskHdl = 0; } return; } g_ucPrintDebugCnt = 0; } }

    void WebSocketHandshakeEventHandler(UINT16 uConnection) {
    	g_success = 1;
    	g_uConnection = uConnection;
    	g_ucConnIndex[uConnection] = 1; // Have new websocket connection request image
    }

    void WebSocketCloseSessionHandler(void) {
        // Added by Thinh TN
        {
            int i = 0;
            for (i = 0; i < HTTP_CORE_MAX_CONNECTIONS; i++)
                if (g_ucConnIndex[i] == 1)
                    return;
        }

        g_close = 1;
    }

    - I also change the httpcore.c:

    void RunHttpServer(void) {
    	int iRecvLen = 0, sock = -1, uConnection = 0;
    	struct HttpBlob blob;
    	while (1) {
    		// Create the listener socket for HTTP Server.
    		if (g_state.listenSocket < 0) {
    			sock = CreateTCPServerSocket(HTTP_CORE_SERVER_PORT);
    			if (sock >= 0) {
    				g_state.listenSocket = sock;
    			}
    			HttpDebug(
    					"\r\n\r\nRunHttpServer: Http server is listenning on socket: %d.\r\n\r\n",
    					g_state.listenSocket);
    		}
    		// Listenter socket created
    		if (g_state.listenSocket >= 0) {
    			// Number of connections is less than HTTP_CORE_MAX_CONNECTIONS (10)
                            // and all images is captured
    			if (g_state.uOpenConnections < HTTP_CORE_MAX_CONNECTIONS
    					&& g_ucCapturing == 0) {

    void HttpCore_CloseConnection(UINT16 uConnection) {
    
    	// Added by Thinh TN
    	g_ucConnIndex[uConnection] = 0;
            // Original code here
    	...
    }
    static int HttpCore_HandleRequestPacket(UINT16 uConnection,
    		struct HttpBlob packet) {
         // Original code
         .....
         while (1) {
    		if (g_state.connections[uConnection].connectionState == RequestMethod
    				|| g_state.connections[uConnection].connectionState
    						== RequestHeaders
    				|| g_state.connections[uConnection].connectionState
    						== DropCurrentHeader
    				|| g_state.connections[uConnection].connectionState
    						== WebSocketRequest
    				|| g_state.connections[uConnection].connectionState
    						== WebSocketResponse
    				|| g_state.connections[uConnection].connectionState
    						== WebSocketDataRecv) {
    
    			if (g_state.connections[uConnection].connectionState
    					!= WebSocketDataRecv)
    				g_ucConnIndex[uConnection] = 2;
    			// Original code
    			...
         }
    }

    - And the camera_app.c:

    static unsigned short CaptureImage(char** WriteBuffer) {
    #ifdef ENABLE_JPEG
    	unsigned short shift;
    #endif
    	g_ucCapturing = 1; // Start capturing image
    
    	// Original code
    	....
    
    	g_ucCapturing = 0; // Finish
    	return (g_header_length + g_frame_size_in_bytes);
    }

    With these changes, now i can receive image on different connections at a same time, but sometime code gets stuck at HttpStatic_ProcessRequest() and i am trying to solve it.

    Regards,

    N.T

  • Hi NT,

    Is this problem resolved? If yes please close the thread.


    Regards,
    Aashish