Al,
So my main function essentially inits the board and runs two tasks. The first task is the wifiTask, which uses TI’s SmartConfig technology to pass wifi credentials to the CC3200. This task works fine - the CC3200 successfully connects to a WLAN network. I won’t include the code for this task, because I know it’s working OK. The second task is the MQTT task which is supposed to subscribe to messages sent from “ iot.eclipse.org.” It’s code is below main.
Thanks for the help.
void main() { initBoard();
// // Pinmux for UART // PinMuxConfig();
// // Initializing DMA // UDMAInit(); #ifndef NOTERM // // Configuring UART // UARTInit(CONSOLEsettings); #endif
// // Display Application Banner // displayBanner(APP_NAME);
// // Start the SimpleLink Host // VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
// // Create the wifiTask // osi_TaskCreate(wifiTask, (const signed char*)"Wifi Task", OSI_STACK_SIZE, NULL, 1, NULL);
// // Create the MQTT Task // osi_TaskCreate(MQTTTask, (const signed char*)"MQTT Task", OSI_STACK_SIZE, NULL, 1, NULL);
// // Start the task scheduler // osi_start(); }
//opts struct needed for MQTT class struct opts_struct { char* clientid; int nodelimiter; char* delimiter; enum QoS qos; char* username; char* password; char* host; int port; int showtopics; } opts = { ( char*) "stdout-subscriber", 0, ( char*) "\n", QOS2, NULL, NULL, ( char*) "iot.eclipse.org", 1883, 0 };
void messageArrived(MessageData* md) { MQTTMessage* message = md->message;
if (opts.showtopics) Report("%.*s\t", md->topicName->lenstring.len, md->topicName->lenstring.data); if (opts.nodelimiter) Report("%.*s", (int)message->payloadlen, (char*)message->payload); else Report("%.*s%s", (int)message->payloadlen, (char*)message->payload, opts.delimiter); //fflush(stdout); }
void MQTTTask(void *pvParameters) {
while(g_ipAdressAcquired == 0) { //do nothing, not yet connected to the internet osi_Sleep(200); }
UART_PRINT("Im in the MQTT Task. \n\r");
int rc = 0; unsigned char buf[100]; unsigned char readbuf[100];
memset(buf, 0, sizeof(unsigned char)*100); memset(readbuf, 0, sizeof(unsigned char)*100);
Network n; Client c; const char topic[100] = "wallflower/command";
NewNetwork(&n); ConnectNetwork( &n, opts.host, opts.port); MQTTClient( &c, &n, 1000, buf, 100, readbuf, 100);
MQTTPacket_connectData data = ""> data.willFlag = 0; data.MQTTVersion = 3; data.clientID.cstring = opts.clientid; data.username.cstring = opts.username; data.password.cstring = opts.password;
data.keepAliveInterval = 10; data.cleansession = 1; UART_PRINT("Connecting to %s, port: %d\n", opts.host, opts.port);
rc = MQTTConnect( &c, &data); UART_PRINT("Connected %d\n", rc);
UART_PRINT("Subscribing to %s\n", topic); rc = MQTTSubscribe( &c, topic, opts.qos, messageArrived); UART_PRINT("Subscribed %d\n", rc);
// while( !toStop) // { // MQTTYield( &c, 1000); // }
UART_PRINT("Stopping\n");
MQTTDisconnect( &c); n.disconnect( &n);
while(1) { //do nothing } }
|