Close

UART via WiFi, send messages to a webpage

A project log for Internet-of-things with CC3200 Dev Board

Internet-of-things with CC3200 development board or my new wireless Thingamajiggy.

romanRoman 06/19/2016 at 14:270 Comments

Currently there are tree tockens defined in param_demos.html:

=__SL_G_UTP

=__SL_G_UAC

=__SL_G_ULD

The tockens are defined in the main.c function:

//*****************************************************************************
//                 GLOBAL VARIABLES -- Start
//*****************************************************************************
static const char pcDigits[] = "0123456789";
static unsigned char POST_token[] = "__SL_P_ULD";
static unsigned char GET_token_TEMP[]  = "__SL_G_UTP";
static unsigned char GET_token_ACC[]  = "__SL_G_UAC";
static unsigned char GET_token_UIC[]  = "__SL_G_UIC";
static unsigned char GET_token_URT[]  = "__SL_G_URT";

I have added __SL_G_URT token to the definition list above. I will be using it for

UART communications.

$(function() {
    var Device_Temperature = $('#Device_Temperature_out'),
        Device_Accelerometer = $('#Device_Accelerometer_out'),
        demoPolling = new com.TI.tokenPoller({
            "paramPage": <a href="#param"><font size="3" color="blue">"param_demos.html",</a></font> 
            "refreshRate": 200,
            "valueMap": [{
            "paramId": "Device_Temperature",
                "outputSuccess": function(output) {
		// Print temperature data. id="Device_Temperature" __SL_G_UTP tocken is received
                    Device_Temperature.html(output);
                },
                "outputDefault": function() {
                    Device_Temperature.html("<i>reloading</i>");
                }
            },
            {
            "paramId": "Device_Accelerometer",
                "outputSuccess": function(output) {
                	// Print accelerometer data. Device_Accelerometer is the token received
                    Device_Accelerometer.html(output);
                },
                "outputDefault": function() {
                    Device_Accelerometer.html("<i>reloading</i>");
                }
            }]
        });
});

I have added the new GET_token_URT token to the definition list:

static unsigned char GET_token_URT[] = "__SL_G_URT";

Below is shown new token reader I am using for UART communications.

/*
* New UART token *************************************************************************
*/
if(memcmp(pSlHttpServerEvent->EventData.httpTokenName.data,
	GET_token_URT, strlen((const char *)GET_token_URT)) == 0)
	{

		UART_PRINT("\n\r\rExecuting UptimeTask Enter a string and press enter\n\r\r");
		
		//g_UartHaveCmd=GETChar(&g_ucUARTRecvBuffer[0]);
		//g_ucUARTRecvBuffer[0] = 'H';
		//uart = g_ucUARTRecvBuffer;
		//uart = "hello uart";
		//short sLenuart = itoa(g_accXIntervalSum,(char*)uart);	
			
		//Get length of the sring stored in g_ucUARTRecvBuffer
		strcpy((char*)pSlHttpServerResponse->ResponseData.token_value.data,"hello uart");
		pSlHttpServerResponse->ResponseData.token_value.len += strlen("hello uart");
		//Pointer to the entered string
		//pSlHttpServerResponse->ResponseData.token_value.data = uart;
		//pSlHttpServerResponse->ResponseData.token_value.len += sLenuart;
	}
}
The updated list of tockes in param_demos.html looks as follows now:

demos-appliances.html has a new "paramId" for reading data from UART tocken:

{
	"paramId": "UART",
	"outputSuccess": function(output) {
		// Print accelerometer data. Device_Accelerometer is the token received
		Device_UART.html(output);
	},
	"outputDefault": function() {
		Device_UART.html("<i>Reading UART data</i>");
	}
}]

To get ready to send strings of variable lengths I have done a couple of changes to the GET_token_URT. First I have declared unsigned char *uart in the SL_NETAPP_HTTPGE TTOKENVALUE_EVENT

switch (pSlHttpServerEvent->Event)
    {
        case SL_NETAPP_HTTPGETTOKENVALUE_EVENT:     // Get data from the server
        {
            unsigned char *ptr;
            unsigned char *ptraccX;
            unsigned char *ptraccY;
            unsigned char *ptraccZ;
            unsigned char *uart;
            ...
        }
        ...
    }

And the new UART tocken looks like this now:

/*
* New UART token ****************************New UART token*********************************** New UART token
*/
if(memcmp(pSlHttpServerEvent->EventData.httpTokenName.data,
GET_token_URT, strlen((const char *)GET_token_URT)) == 0)
{
	uart = "Sending srings of data";                
	strcpy((char*)pSlHttpServerResponse->ResponseData.token_value.data, (const char *) uart);
	pSlHttpServerResponse->ResponseData.token_value.len += strlen((const char *) uart);
} 

I have declared unsigned char g_ucUARTRecvBuffer1[80] a Global 80 character long array. The array will be used to store entered strings.

....
unsigned char printflag = 0;
unsigned char g_ucUARTRecvBuffer1[80];
typedef enum
{
  LED_OFF = 0,
  LED_ON,
  LED_BLINK
}eLEDStatus;
.....

The Uptime Task in the main function with the new g_ucUARTRecvBuffer1[80] array now looks as follows:

static void UptimeTask( void *pvParameters )
{
    while(1)
    {
        //GPIO_IF_LedOff(MCU_ORANGE_LED_GPIO);
        g_uptimeSec++;
        UART_PRINT("\n\r\rExecuting UptimeTask Enter a string and press enter\n\r\r");
        // Returns UART line read from the console. Parameter is unsigned char array
        g_UartHaveCmd = GETChar(&g_ucUARTRecvBuffer1[0]);	// Load buffer from the serial terminal        
        osi_Sleep(1000);
    }
}

The only change to the UART tocken is that *uart now points to the beginning address of the g_ucUARTRecvBuffer1 buffer.

/*
 * New UART token ****************************New UART token*****************************
 */
if(memcmp(pSlHttpServerEvent->EventData.httpTokenName.data,
GET_token_URT, strlen((const char *)GET_token_URT)) == 0)
{               
	uart = g_ucUARTRecvBuffer1; //g_ucUARTRecvBuffer                
	strcpy((char*)pSlHttpServerResponse->ResponseData.token_value.data, (const char *) uart);	//Works
	pSlHttpServerResponse->ResponseData.token_value.len += strlen((const char *) uart);				//Works
}

This code allows me to send varios messages to the demos-appliences.html webpage, the only issue is that I cannot clear old messages off the screen. I also change #define HIGH_TASK_PRIORITY to 4.


Download all the updated files from the GITHUB.

Visit my webpage for daily updates: CC3200.

Discussions