Toggle LED on CC3200 not work


#1

Hi!

I playing with Launchpad CC3200 and Exosite Portal for couple of days.
I successfully connect Launchpad to Portal for watching my room temperature and Accelerometer data on dashboard.

But when I tried to push button on Launchpad to activate action of sending email or if I want to toggle LED on Launchpad over Portal dashboard, there is no success.

I use code form link https://github.com/exosite-garage/CC3200CloudDemo/tree/v2/. When I modified code for sending value of pressed button on Launchpad, function of sending email over Portal works.

But there is still problem with trigger LED on Launchpad over Portal.
Is problem on code posted on upper link, or should I need to open any port on my router?

If anybody have suggestion, pleas help.

Mihec


#2

Yep that is something that hasn’t been implemented in that code yet. Look at the ‘known issues’ section, one of the items is “Setting the LED on or off has not been implemented yet.”

There is an old version of that code that does turn the LED on and off, but I hadn’t gotten in in the new version before I had to leave that project be for awhile.

Here’s a snippet that shows how you would implement something like turning the LED on or off, I can’t promise that it’ll just work as it’s one of my personal projects that I never finished, but it should give you the general idea.

static void ExositeTask(void *pvParameters)
{
    uint16_t len = 0;
    long   ret = -1;
    unsigned long long retry_delay = 100;
    unsigned long long counter = 0;
    char buf[1024];
    EXO_STATE state = EXO_STATE_NOT_COMPLETE;

    //Read Device Mode Configuration
    ReadDeviceConfiguration();

    //Connect to Network
    ret = ConnectToNetwork();
    if(ret < 0)
    {
        ERR_PRINT(ret);
        LOOP_FOREVER();
    }

    // Wait here if we're in AP Mode
    while(g_uiDeviceModeConfig != ROLE_STA){
        osi_Sleep(1000);
    }

    //Handle Async Events
    while(1)
    {
        //TODO: Wrap all Exosite calls in a check to see if we're connected.
        while(state != EXO_STATE_INIT_COMPLETE){
            UART_PRINT("[EXO] Exosite Init\r\n");
            state = exosite_init("patrick","sunrise-v1");
            if(state == EXO_STATE_INIT_COMPLETE){
                UART_PRINT("[EXO] Activated, Ready to Go\r\n");
            }else if(state == EXO_STATE_INIT_ERROR){
                UART_PRINT("[EXO] Error Activating on Exosite (Add to Account or Re-enable for Activation)\r\n");
                retry_delay *= 2;
                osi_Sleep(retry_delay);
            }else if(state == EXO_STATE_CONNECTION_ERROR){
                UART_PRINT("[EXO] Error Connecting to Exosite, Check Your Connection\r\n");
                //retry_delay *= 2;
                osi_Sleep(retry_delay);
            }else if(state == EXO_STATE_NO_RESPONSE){
                UART_PRINT("[EXO] We connected, but timed-out waiting for a response. Try again.\r\n");
                retry_delay *= 2;
                osi_Sleep(retry_delay);
            }else if(state == EXO_STATE_DEVICE_NOT_ENABLED){
                UART_PRINT("[EXO] Couldn't Activate on Exosite (Add to Account or Re-enable for Activation)\r\n");
                retry_delay *= 2;
                osi_Sleep(retry_delay);
            }else if(state == EXO_STATE_R_W_ERROR){
                UART_PRINT("[EXO] Read/Write Error\r\n");
                retry_delay *= 2;
                osi_Sleep(retry_delay);
            }else{
                UART_PRINT("[EXO] Unknown State in Init");
                return;
            }
        }


        UART_PRINT("[EXO] Reading Light Level...");
        ret = exosite_read("l", buf, 1024, &len);
        if(ret == 0){
            UART_PRINT("OK\r\n");
            retry_delay = 1000;

            //UART_PRINT("%*s (%i)\r\n", len, buf, len);
            sscanf (buf,"l=%u",&g_lightLevel);
            UART_PRINT("Light Level: %u\r\n", g_lightLevel);

            GPIO_IF_LedOff(MCU_ORANGE_LED_GPIO);
            GPIO_IF_LedOn(MCU_GREEN_LED_GPIO);

            if(g_lightLevel > 50)
                GPIO_IF_LedOn(MCU_RED_LED_GPIO);
            else
                GPIO_IF_LedOff(MCU_RED_LED_GPIO);
        }else{
            UART_PRINT("ERROR\r\n");
            retry_delay *= 2;
            state = EXO_STATE_NOT_COMPLETE;
            ERR_PRINT(ret);
            GPIO_IF_LedOn(MCU_ORANGE_LED_GPIO);
            GPIO_IF_LedOff(MCU_GREEN_LED_GPIO);
        }

        // Limit Retry Delay to 10 Seconds During Development
        if(retry_delay > 10000)
            retry_delay = 10000;

        osi_Sleep(retry_delay);

        counter++;
    }
}

That is the ExositeTask function in main.c, the important part is about half way down. It does a read of the dataport “l” and if the value is greater than 50 it turns the LED on, if it’s less it turns it off.


#3

Thank you for your suggestion.
Now code for switching red LED On and Off on Launchpad over Dashboard works.

Here is the code for “ExositeTask” rutine for demo from link:

Code:

static void ExositeTask(void *pvParameters)
{
	uint16_t len = 0;
    long   ret = -1;
    unsigned long long retry_delay = 100;
    unsigned long long counter = 0;
    char buf[1024];
    EXO_STATE state = EXO_STATE_NOT_COMPLETE;

    //Read Device Mode Configuration
    ReadDeviceConfiguration();

    //Connect to Network
    ret = ConnectToNetwork();
    if(ret < 0)
    {
        ERR_PRINT(ret);
        LOOP_FOREVER();
    }

    // Wait here if we're in AP Mode
    while(g_uiDeviceModeConfig != ROLE_STA){
        osi_Sleep(1000);
    }

    //Handle Async Events
    while(1)
    {
    	//TODO: Wrap all Exosite calls in a check to see if we're connected.
        while(state != EXO_STATE_INIT_COMPLETE){
    		UART_PRINT("[EXO] Exosite Init\r\n");
    		state = exosite_init("texasinstruments","cc3200lp_v1");
    		if(state == EXO_STATE_INIT_COMPLETE){
    			UART_PRINT("[EXO] Activated, Ready to Go\r\n");
    		}else if(state == EXO_STATE_INIT_ERROR){
    			UART_PRINT("[EXO] Error Activating on Exosite (Add to Account or Re-enable for Activation)\r\n");
    			retry_delay *= 2;
    	        osi_Sleep(retry_delay);
    		}else if(state == EXO_STATE_CONNECTION_ERROR){
    			UART_PRINT("[EXO] Error Connecting to Exosite, Check Your Connection\r\n");
    			//retry_delay *= 2;
    	        osi_Sleep(retry_delay);
    		}else if(state == EXO_STATE_NO_RESPONSE){
    			UART_PRINT("[EXO] We connected, but timed-out waiting for a response. Try again.\r\n");
    			retry_delay *= 2;
    	        osi_Sleep(retry_delay);
    		}else if(state == EXO_STATE_DEVICE_NOT_ENABLED){
    			UART_PRINT("[EXO] Couldn't Activate on Exosite (Add to Account or Re-enable for Activation)\r\n");
    			retry_delay *= 2;
    	        osi_Sleep(retry_delay);
    		}else if(state == EXO_STATE_R_W_ERROR){
    			UART_PRINT("[EXO] Read/Write Error\r\n");
    			retry_delay *= 2;
    	        osi_Sleep(retry_delay);
    		}else{
    			UART_PRINT("[EXO] Unknown State in Init");
    			return;
    		}
        }


        UART_PRINT("[EXO] Writing Values...");

    	AccSample(); // Just do a single reading for now. TODO: Make Async.
        SetAccAvg();

        float sensorTemp;
        TMP006DrvGetTemp(&sensorTemp);
        snprintf(buf, 1023, "ontime=%llu&acc=%.0f&accX=%.0f&accY=%.0f&accZ=%.0f&sensortemp=%.2f&usrsw=%llu",
                g_uptimeSec,
                g_accTotalAvg,
                g_accXAvg,
                g_accYAvg,
                g_accZAvg,
                sensorTemp,
                g_SW2Counter);
        ret = exosite_write(buf,strlen(buf));
        if(ret == 0){
        	UART_PRINT("OK\r\n");
        	retry_delay = 1000;
        }else{
        	UART_PRINT("ERROR\r\n");
        	retry_delay *= 2;
        	state = EXO_STATE_NOT_COMPLETE;
        	ERR_PRINT(ret);
        }

        UART_PRINT("[EXO] Reading button LED D7 on Dashboard...");
		ret = exosite_read("ledd7", buf, 1024, &len);
		if(ret == 0)
		{
			if(buf[6] == 49)
			{
				g_ucLEDStatus = LED_ON;
				UART_PRINT("ON\r\n");
			}
			else if(buf[6] == 48)
			{
				UART_PRINT("OFF\r\n");
				g_ucLEDStatus = LED_OFF;
			}
			retry_delay = 1000;
		}

        //LED Actions
        if(g_ucLEDStatus == LED_ON)
        {
            GPIO_IF_LedOn(MCU_RED_LED_GPIO);
        }
        if(g_ucLEDStatus == LED_OFF)
        {
            GPIO_IF_LedOff(MCU_RED_LED_GPIO);
        }
        if(g_ucLEDStatus==LED_BLINK)
        {
        	GPIO_IF_LedToggle(MCU_RED_LED_GPIO);
        }


        // Limit Retry Delay to 10 Seconds During Development
        if(retry_delay > 10000)
        	retry_delay = 10000;

        osi_Sleep(retry_delay);

        counter++;
    }
}

Mihec


#4

Awesome! Thanks for the code updates. If it’s alright with you, I’d like to update the repo with your modifications. Is that alright?


#5

Yes, no problem.

In next days I’ll write rutine for push button to. I’ll publish code here.

Mihec


#6

Great, thanks! I’ll get it tested and pushed out in the next few days.


#7

I’ve been using the the V2 branch of the CC3200 project with Mihec edits to the Exosite Task to connect to my white label account. The data is not getting consistently read correctly.

Most the time that the exocite_read function is ran I get a HTTP response status code of 200 but with no content. Once in a while there is content, but it is sporadic.

Do you think this is an issue with the CC3200 or with the portal?


#8

@David, I’d bet that it’s an issue on the 3200 end as we haven’t had any other reports as far as I know.

If you want to pm me the first 10 chars of your CIK I can check our logs and at least see if there was a body being sent. You should never get a 200 with no body as far as I’m aware, that should only happen with a 204.

Other than that I’d suggest using the debugger and seeing what is getting returned exactly. Otherwise I’ll be doing some testing when I get a chance to pull in @Mihec’s changes.


#9

@Patrick I sent you an email, not sure how to PM you


#10

That is a very odd looking response. I’m still thinking that it is a problem on the 3200, I found that exact request and the server sure thinks it sent 31 bytes of body like the content-length suggests it did.

I do see another request at exactly the same time that returned a 204 (and thus no body), you’re not using the library from two different threads are you? That library is not reentrant.


#11

The 204 response is from previous exosite_write routine.

In the exosite_read function I added a delay between the socketWrites and the socketRead and I started receiving data.