Example #1
0
/*
 * Application's entry point
 */
int main(int argc, char** argv)
{
    SlSecParams_t secParams = {0};
    _i32 retVal = -1;

    retVal = initializeAppVariables();
    ASSERT_ON_ERROR(retVal);

    /* Stop WDT and initialize the system-clock of the MCU */
    stopWDT();
    initClk();

    /* Configure command line interface */
    CLI_Configure();

    displayBanner();

    /*
     * Following function configures the device to default state by cleaning
     * the persistent settings stored in NVMEM (viz. connection profiles &
     * policies, power policy etc.)
     *
     * Applications may choose to skip this step if the developer is sure
     * that the device is in its default state at start of application
     *
     * Note that all profiles and persistent settings that were done on the
     * device will be lost
     */
    retVal = configureSimpleLinkToDefaultState();
    if(retVal < 0)
    {
        if (DEVICE_NOT_IN_STATION_MODE == retVal)
            CLI_Write(" Failed to configure the device in its default state \n\r");

        LOOP_FOREVER();
    }

    CLI_Write(" Device is configured in default state \n\r");

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

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

    /* Delete all profiles (0xFF) stored and reset policy settings */
    retVal = sl_WlanProfileDel(0xFF);
    if(retVal < 0)
    {
        LOOP_FOREVER();
    }
    retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION ,
                     SL_CONNECTION_POLICY(0, 0, 0, 0, 0), 0, 0);
    if(retVal < 0)
    {
        LOOP_FOREVER();
    }

    /* Add unsecured AP profile with priority 6 (7 is highest) */
    retVal = sl_WlanProfileAdd((_i8 *)UNSEC_SSID_NAME,
                      pal_Strlen(UNSEC_SSID_NAME), g_BSSID, 0, 0, 6, 0);
    if(retVal < 0)
    {
        LOOP_FOREVER();
    }

    /* Add WPA2 secured AP profile with priority 7 (highest) */
    secParams.Type = SL_SEC_TYPE_WPA;
    secParams.Key = SEC_SSID_KEY;
    secParams.KeyLen = pal_Strlen(SEC_SSID_KEY);
    retVal = sl_WlanProfileAdd((_i8 *)SEC_SSID_NAME,
                      pal_Strlen(SEC_SSID_NAME), g_BSSID, &secParams, 0, 7, 0);
    if(retVal < 0)
    {
        LOOP_FOREVER();
    }

    /*
     * Enable auto connect (connection to stored profiles according to priority)
     * Connection should first be established to higher (secured) profile as in
     * this example
     */
    retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION ,
                     SL_CONNECTION_POLICY(1,0,0,0,0), 0, 0);
    if(retVal < 0)
    {
        LOOP_FOREVER();
    }

    /* Wait for the connection to be established */
    while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); }

    CLI_Write(" Device connected to the AP using 'auto' connection policy\n\r");

    /* Delete all profiles (0xFF) stored */
    retVal = sl_WlanProfileDel(0xFF);
    if(retVal < 0)
    {
        LOOP_FOREVER();
    }

    g_Status = 0;

    /* Restart the device */
    retVal = sl_Stop(SL_STOP_TIMEOUT);
    if(retVal < 0)
    {
        LOOP_FOREVER();
    }

    retVal = sl_Start(0, 0, 0);
    if ((retVal < 0) ||
        (ROLE_STA != retVal) )
    {
        CLI_Write(" Failed to start the device \n\r");
        LOOP_FOREVER();
    }

    /*
     * Set connection policy to Fast - Device will connect to the last connected AP.
     * This feature can be used to reconnect to AP
     */
    retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION,
                     SL_CONNECTION_POLICY(1, 1, 0, 0, 0), 0, 0);
    if(retVal < 0)
    {
        LOOP_FOREVER();
    }

    /* Connect to the open AP */
    retVal = establishConnectionWithAP();
    if(retVal < 0)
    {
        CLI_Write(" Failed to establish connection w/ an AP \n\r");
        LOOP_FOREVER();
    }
    CLI_Write(" Device was connected to the AP using host-driver API \n\r");

    g_Status = 0; /* Status variable */

    /* Restart the Device */
    retVal = sl_Stop(SL_STOP_TIMEOUT);
    if(retVal < 0)
    {
        LOOP_FOREVER();
    }

    retVal = sl_Start(0, 0, 0);
    if ((retVal < 0) ||
        (ROLE_STA != retVal) )
    {
        CLI_Write(" Failed to start the device \n\r");
        LOOP_FOREVER();
    }

    /* Wait for the connection to be established */
    while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); }
    CLI_Write(" Device connected to the AP using 'fast' connection policy\n\r");

    /* Delete all profiles (0xFF) stored */
    retVal = sl_WlanProfileDel(0xFF);
    if(retVal < 0)
    {
        LOOP_FOREVER();
    }

    /* Set Auto SmartConfig policy */
    retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION , SL_CONNECTION_POLICY(1,0,0,0,1), 0, 0);
    if(retVal < 0)
    {
        LOOP_FOREVER();
    }

    /* Restart the Device */
    g_Status = 0;
    retVal = sl_Stop(SL_STOP_TIMEOUT);
    if(retVal < 0)
    {
        LOOP_FOREVER();
    }

    retVal = sl_Start(0, 0, 0);
    if ((retVal < 0) ||
        (ROLE_STA != retVal) )
    {
        CLI_Write(" Failed to start the device \n\r");
        LOOP_FOREVER();
    }

    /*
     * After restarting , device will wait for a command for 2 second and start
     * the SmartConfig process if no command is received
     */
    CLI_Write(" Device waiting to be connected using SmartConfig technology \n\r");
    while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); }

    CLI_Write(" Device connected to the AP \n\r");

    /*
     * Cleaning all profiles and setting the default connection policy before exiting the application
     * Set connection policy to Auto + SmartConfig (Device's default connection policy)
     */
    retVal = sl_WlanProfileDel(0xFF);
    if(retVal < 0)
    {
        LOOP_FOREVER();
    }

    retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0);
    if(retVal < 0)
    {
        LOOP_FOREVER();
    }

    return 0;
}
Example #2
0
int main2(void)
{
    UINT8  IsDHCP = 0;
    int32_t i32CommandStatus;
    _NetCfgIpV4Args_t ipV4;

    unsigned char len = sizeof(_NetCfgIpV4Args_t);
    int Status = 0;

    /* Stop WDT */
    stopWDT();

    /* Initialize the system clock of MCU */
    initClk();

    Board_Init();       // initialize LaunchPad I/O and PD1 LED
    ConfigureUART();    // Initialize the UART.
    UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n");
    UARTprintf("This application is configured to measure analog signals from Ain7=PD0\n");
    UARTprintf("  and send UDP packets to IP: %d.%d.%d.%d  Port: %d\n\n",
      SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), 
      SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM);
    /* Initializing the CC3100 device */
    sl_Start(0, 0, 0);

    /* Connecting to WLAN AP - Set with static parameters defined at the top
       After this call we will be connected and have IP address */
    WlanConnect();

    /* Read the IP parameter */
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,
            (unsigned char *)&ipV4);

    //Print the IP
    UARTprintf("This node is at IP: %d.%d.%d.%d\n",  SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0));

    //
    // Loop forever waiting  for commands from PC...
    //
    while(1)
    {
        //
        // Print prompt for user.
        //
        UARTprintf("\n>");

        //
        // Peek to see if a full command is ready for processing.
        //
        while(UARTPeek('\r') == -1)
        {
            //
            // Approximately 1 millisecond delay.
            //
            ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3000);
        }

        //
        // A '\r' was detected so get the line of text from the receive buffer.
        //
        UARTgets(g_cInput,sizeof(g_cInput));

        //
        // Pass the line from the user to the command processor.
        // It will be parsed and valid commands executed.
        //
        i32CommandStatus = CmdLineProcess(g_cInput);

        //
        // Handle the case of bad command.
        //
        if(i32CommandStatus == CMDLINE_BAD_CMD)
        {
            UARTprintf("    Bad command. Try again.\n");
        }
        //
        // Handle the case of too many arguments.
        //
        else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS)
        {
            UARTprintf("    Too many arguments for command. Try again.\n");
        }
        //
        // Handle the case of too few arguments.
        //
        else if(i32CommandStatus == CMDLINE_TOO_FEW_ARGS)
        {
            UARTprintf("    Too few arguments for command. Try again.\n");
        }
        //
        // Handle the case of too few arguments.
        //
        else if(i32CommandStatus == CMDLINE_INVALID_ARG)
        {
            UARTprintf("    Invalid command argument(s). Try again.\n");
        }
    }
    
}
Example #3
0
/*
 * Application's entry point
 */
int main(int argc, char** argv)
{
    _i32 retVal = -1;

    retVal = initializeAppVariables();
    ASSERT_ON_ERROR(retVal);

    /* Stop WDT and initialize the system-clock of the MCU */
    stopWDT();
    initClk();

    /* Configure command line interface */
    CLI_Configure();

    displayBanner();

    /*
     * Following function configures the device to default state by cleaning
     * the persistent settings stored in NVMEM (viz. connection profiles &
     * policies, power policy etc)
     *
     * Applications may choose to skip this step if the developer is sure
     * that the device is in its default state at start of application
     *
     * Note that all profiles and persistent settings that were done on the
     * device will be lost
     */
    retVal = configureSimpleLinkToDefaultState();
    if(retVal < 0)
    {
        if (DEVICE_NOT_IN_STATION_MODE == retVal)
            CLI_Write((_u8 *)" Failed to configure the device in its default state \n\r");

        LOOP_FOREVER();
    }

    CLI_Write((_u8 *)" Device is configured in default state \n\r");

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

    CLI_Write((_u8 *)" Device started as STATION \n\r");

    /* Connecting to WLAN AP */
    retVal = establishConnectionWithAP();
    if(retVal < 0)
    {
        CLI_Write((_u8 *)" Failed to establish connection w/ an AP \n\r");
        LOOP_FOREVER();
    }

    CLI_Write((_u8 *)" Connection established w/ AP and IP is acquired \n\r");
    CLI_Write((_u8 *)" Pinging...! \n\r");

    retVal = checkLanConnection();
    if(retVal < 0)
    {
        CLI_Write((_u8 *)" Device couldn't connect to LAN \n\r");
        LOOP_FOREVER();
    }

    CLI_Write((_u8 *)" Device successfully connected to the LAN\r\n");

    retVal = checkInternetConnection();
    if(retVal < 0)
    {
        CLI_Write((_u8 *)" Device couldn't connect to the internet \n\r");
        LOOP_FOREVER();
    }

    CLI_Write((_u8 *)" Device successfully connected to the internet \n\r");
    return 0;
}
Example #4
0
int main1(void){
  UINT8             IsDHCP = 0;
  _NetCfgIpV4Args_t ipV4;
  SlSockAddrIn_t    Addr;
  UINT16            AddrSize = 0;
  INT16             SockID = 0;
  INT16             Status = 1;  // ok
  UINT32            data;
  unsigned char     len = sizeof(_NetCfgIpV4Args_t);
  stopWDT();        // Stop WDT 
  initClk();        // PLL 50 MHz, ADC needs PPL active
  Board_Init();     // initialize LaunchPad I/O 
  ConfigureUART();  // Initialize the UART.
  UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n");
#if ADC
  ADC0_InitSWTriggerSeq3(7);  // Ain7 is on PD0
  UARTprintf("This node is configured to measure signals from Ain7=PD0\n");
#endif
#if EKG
  UARTprintf("This node is configured to generate simulated EKG data\n");
#endif
  UARTprintf("  and send UDP packets to IP: %d.%d.%d.%d  Port: %d\n\n",
      SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), 
      SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM);
  while(1){
    sl_Start(0, 0, 0);/* Initializing the CC3100 device */
    /* Connecting to WLAN AP - Set with static parameters defined at the top
       After this call we will be connected and have IP address */
    WlanConnect();   // connect to AP
    /* Read the IP parameter */
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4);
    UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0));
    while(Status > 0){
      Addr.sin_family = SL_AF_INET;
      Addr.sin_port = sl_Htons((UINT16)PORT_NUM);
      Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR);
      AddrSize = sizeof(SlSockAddrIn_t);
      SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
      if( SockID < 0 ){
        UARTprintf("SockIDerror ");
        Status = -1; // error
      }else{
        while(Status>0){
          UARTprintf("\nSending a UDP packet ...");
          uBuf[0] = ATYPE;   // defines this as an analog data type
          uBuf[1] = '='; 
#if ADC
          data = ADC0_InSeq3(); // 0 to 4095, Ain7 is on PD0
#endif
#if EKG
          data = EKGbuf[EKGindex];
          EKGindex = (EKGindex+1)%EKGSIZE; // 100 Hz
#endif
          Int2Str(data,(char*)&uBuf[2]); // [2] to [7] is 6 digit number
          UARTprintf(" %s ",uBuf);
          LED_Toggle();
          Status = sl_SendTo(SockID, uBuf, BUF_SIZE, 0,
                           (SlSockAddr_t *)&Addr, AddrSize);
          ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25); // 80ms
          if( Status <= 0 ){
            UARTprintf("SockIDerror %d ",Status);
          }else{
           UARTprintf("ok");
          }     
        }
        sl_Close(SockID);
      }
    }
  }
}
Example #5
0
int main(void){
  UINT8             IsDHCP = 0;
  _NetCfgIpV4Args_t ipV4;
  SlSockAddrIn_t    Addr;
  SlSockAddrIn_t    LocalAddr;
  UINT16            AddrSize = 0;
  INT16             SockID = 0;
  INT16             Status = 1;  // ok
  UINT32            data;
  unsigned char     len = sizeof(_NetCfgIpV4Args_t);
  stopWDT();        // Stop WDT 
  initClk();        // PLL 50 MHz, ADC needs PPL active
  Board_Init();     // initialize LaunchPad I/O 
  ConfigureUART();  // Initialize the UART.
  UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n");
  UARTprintf("This node is configured to receive UDP packets\n");
  UARTprintf("This node should be at IP: %d.%d.%d.%d  Port: %d\n\n",
      SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), 
      SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM);
  ST7735_InitR(INITR_REDTAB);
  ST7735_OutString("Internet of Things\n");
  ST7735_OutString("Embedded Systems\n");
  ST7735_OutString("Vol. 2, Valvano");
  ST7735_PlotClear(0,4095);  // range from 0 to 4095
  while(1){
    sl_Start(0, 0, 0); /* Initializing the CC3100 device */
    /* Connecting to WLAN AP - Set with static parameters defined at the top
       After this call we will be connected and have IP address */
    WlanConnect();   // connect to AP
    /* Read the IP parameter */
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4);
    UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0));
    while(Status > 0){
      UARTprintf("\nReceiving a UDP packet ...");

      LocalAddr.sin_family = SL_AF_INET;
      LocalAddr.sin_port = sl_Htons((UINT16)PORT_NUM);
      LocalAddr.sin_addr.s_addr = 0;
      AddrSize = sizeof(SlSockAddrIn_t);
      SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);     
      if( SockID < 0 ){
        UARTprintf("SockIDerror\n");
        Status = -1; // error
      }else{
        Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);
        if( Status < 0 ){
          sl_Close(SockID); 
          UARTprintf("Sock Bind error\n");
        }else{
          Status = sl_RecvFrom(SockID, uBuf, BUF_SIZE, 0,
                  (SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize );
          if( Status <= 0 ){
            sl_Close(SockID);
            UARTprintf("Receive error %d ",Status);
          }else{
            LED_Toggle();
            sl_Close(SockID);
            UARTprintf("ok %s ",uBuf);
            if((uBuf[0]==ATYPE)&&(uBuf[1]== '=')){ int i,bOk; uint32_t place;
              data = 0; bOk = 1;
              i=4;  // ignore possible negative sign
              for(place = 1000; place; place = place/10){
                if((uBuf[i]&0xF0)==0x30){ // ignore spaces
                  data += place*(uBuf[i]-0x30);
                }else{
                  if((uBuf[i]&0xF0)!= ' '){
                    bOk = 0;
                  }
                }
                i++;
              }
              if(bOk){
                ST7735_PlotLine(data);
                ST7735_PlotNextErase(); 
              }
            }
          }
        }
      }
      ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25); // 120ms
    }
  }
}
Example #6
0
/*
 * Application's entry point
 */
int main(int argc, char** argv)
{
    _i32 retVal = -1;

    retVal = initializeAppVariables();
    ASSERT_ON_ERROR(retVal);

    /* Stop WDT and initialize the system-clock of the MCU
       These functions needs to be implemented in PAL */
    stopWDT();
    initClk();

    /* Configure command line interface */
    CLI_Configure();

    displayBanner();

    /*
     * Following function configures the device to default state by cleaning
     * the persistent settings stored in NVMEM (viz. connection profiles &
     * policies, power policy etc)
     *
     * Applications may choose to skip this step if the developer is sure
     * that the device is in its default state at start of application
     *
     * Note that all profiles and persistent settings that were done on the
     * device will be lost
     */
    retVal = configureSimpleLinkToDefaultState();
    if(retVal < 0)
    {
        if (DEVICE_NOT_IN_STATION_MODE == retVal)
        {
            CLI_Write(" Failed to configure the device in its default state \n\r");
        }

        LOOP_FOREVER();
    }

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

    CLI_Write(" Device is configured in default state \n\r");

    CLI_Write(" Starting smartconfig process \n\r");

    /* Connect to our AP using SmartConfig method */
    retVal = SmartConfigConnect();
    if(retVal < 0)
    {
        CLI_Write(" Failed to establish connection w/ an AP \n\r");
        LOOP_FOREVER();
    }

    CLI_Write(" Connection established w/ AP and IP is acquired \n\r");

    /* Delete all profiles */
    retVal = sl_WlanProfileDel(WLAN_DEL_ALL_PROFILES);
    if(retVal < 0)
        LOOP_FOREVER();

    return 0;
}
Example #7
0
File: main.c Project: bmxrt/CC3100
int main(int argc, char** argv)
{
    SlSockAddrIn_t      Addr = {0};

    _u32  cipher = SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA;
    _u32  googleIP = 0;
    _u8   method = SL_SO_SEC_METHOD_SSLV3;

    _i32   AddrSize = -1;
    _i32   g_SockID = -1;
    _i32   retVal = -1;

    retVal = initializeAppVariables();
    ASSERT_ON_ERROR(retVal);

    /* Stop WDT and initialize the system-clock of the MCU
       These functions needs to be implemented in PAL */
    stopWDT();
    initClk();

    /* Configure command line interface */
    CLI_Configure();

    displayBanner();

    /*
     * Following function configures the device to default state by cleaning
     * the persistent settings stored in NVMEM (viz. connection profiles &
     * policies, power policy etc)
     *
     * Applications may choose to skip this step if the developer is sure
     * that the device is in its default state at start of application
     *
     * Note that all profiles and persistent settings that were done on the
     * device will be lost
     */
    retVal = configureSimpleLinkToDefaultState();
    if(retVal < 0)
    {
        if (DEVICE_NOT_IN_STATION_MODE == retVal)
        {
            CLI_Write(" Failed to configure the device in its default state \n\r");
        }

        LOOP_FOREVER();
    }

    CLI_Write(" Device is configured in default state \n\r");

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

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

    /* Connecting to WLAN AP - Set with static parameters defined at the top
       After this call we will be connected and have IP address */
    retVal = establishConnectionWithAP();
    if(retVal < 0)
    {
        CLI_Write(" Failed to establish connection w/ an AP \n\r");
        LOOP_FOREVER();
    }

    CLI_Write(" Connection established w/ AP and IP is acquired \n\r");

    /* Update the CC3100 time */
    retVal = SetTime();
    if (retVal < 0)
    {
        CLI_Write(" Failed to set the device time \n\r");
        LOOP_FOREVER();
    }

    CLI_Write(" Establishing secure connection w/ google server \n\r");

    /* get the server name via a DNS request */
    retVal = sl_NetAppDnsGetHostByName(g_Google, pal_Strlen(g_Google),
                                       &googleIP, SL_AF_INET);
    if( retVal < 0 )
    {
        CLI_Write(" Failed to get the IP address \n\r");
        LOOP_FOREVER();
    }

    Addr.sin_family = SL_AF_INET;
    Addr.sin_port = sl_Htons(GOOGLE_DST_PORT);
    Addr.sin_addr.s_addr = sl_Htonl(googleIP);

    AddrSize = sizeof(SlSockAddrIn_t);

    /* opens a secure socket */
    g_SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET);
    if( g_SockID < 0 )
    {
        CLI_Write(" Failed to open socket \n\r");
        LOOP_FOREVER();
    }

    /* configure the socket as SSLV3.0 */
    retVal = sl_SetSockOpt(g_SockID, SL_SOL_SOCKET, SL_SO_SECMETHOD,
                           &method, sizeof(method));
    if( retVal < 0 )
    {
        CLI_Write(" Failed to configure the socket \n\r");
        LOOP_FOREVER();
    }

    /* configure the socket as RSA with RC4 128 SHA */
    retVal = sl_SetSockOpt(g_SockID, SL_SOL_SOCKET, SL_SO_SECURE_MASK,
                           &cipher, sizeof(cipher));
    if( retVal < 0 )
    {
        CLI_Write(" Failed to configure the socket \n\r");
        LOOP_FOREVER();
    }

    /* configure the socket with GOOGLE CA certificate-for server verification*/
    retVal = sl_SetSockOpt(g_SockID, SL_SOL_SOCKET, SL_SO_SECURE_FILES_CA_FILE_NAME,
                           SL_SSL_CA_CERT, pal_Strlen(SL_SSL_CA_CERT));
    if( retVal < 0 )
    {
        CLI_Write(" Failed to configure the socket \n\r");
        LOOP_FOREVER();
    }

    /* connect to the peer device - GMail server */
    retVal = sl_Connect(g_SockID, ( SlSockAddr_t *)&Addr, AddrSize);
    if (retVal < 0 )
    {
        CLI_Write(" Failed to connect w/ google server \n\r");
        LOOP_FOREVER();
    }

    CLI_Write(" Connection w/ google server established successfully \n\r");


    /* Stop the CC3100 device */
    retVal = sl_Stop(SL_STOP_TIMEOUT);
    if(retVal < 0)
        LOOP_FOREVER();

    return 0;
}
Example #8
0
/*
 * Application's entry point dynamic schedule.  Main is somewhat too large because of the MQTT stuff
 * allmighty whileloop
 */
int main(int argc, char** argv)
{

    /* Stop WDT and initialize lcd, clcks, main interfaces */
    stopWDT();
    init_clocks(); //init clock for LCD
    init_lcd();
    initClk(); //init clock for wifi
    Delay(5);
    init_main();
    Delay(5);

    load_data();

    int rc = 0;
    unsigned char buf[100];
    unsigned char readbuf[100];

    NewNetwork(&n);
    rc = ConnectNetwork(&n, MQTT_BROKER_SERVER, 1883);

    if (rc != 0) {
        CLI_Write(" Failed to connect to MQTT broker \n\r");
    }

    MQTTClient(&hMQTTClient, &n, 1000, buf, 100, readbuf, 100);
    MQTTPacket_connectData cdata = MQTTPacket_connectData_initializer;
    cdata.MQTTVersion = 3;
    cdata.clientID.cstring = "daniel";
    rc = MQTTConnect(&hMQTTClient, &cdata);

    if (rc != 0) {
        CLI_Write(" Failed to start MQTT client \n\r");
        //LOOP_FOREVER();
    }

    rc = MQTTSubscribe(&hMQTTClient, SUBSCRIBE_TOPIC, QOS0, messageArrived);

    if (rc != 0) {
        CLI_Write(" Failed to subscribe to /msp/cc3100/demo topic \n\r");
        //LOOP_FOREVER();
    }

    MQTTYield(&hMQTTClient, 10);
    int8_t buffer[2] = "on";
    MQTTMessage msg;
    msg.dup = 0;
    msg.id = 0;
    msg.payload = buffer;
    msg.payloadlen = 8;
    msg.qos = QOS0;
    msg.retained = 0;
    MQTTPublish(&hMQTTClient, PUBLISH_TOPIC, &msg);
    Delay(20);

    backlight_off();
    while(1) {
        MQTTYield(&hMQTTClient, 10);
        debounce++;

        if(send_goal_bool) {
            int8_t buffer2[15] = "               ";
            sprintf(buffer2, "%d", goal_steps);
            msg;
            msg.dup = 0;
            msg.id = 0;
            msg.payload = buffer2;
            msg.payloadlen = 15;
            msg.qos = QOS0;
            msg.retained = 0;
            MQTTPublish(&hMQTTClient, PUBLISH_TOPIC, &msg);
            Delay(20);
            send_goal_bool = 0;
        }else if(send_on_bool) {
            int8_t buffer2[2] = "on";
            msg;
            msg.dup = 0;
            msg.id = 0;
            msg.payload = buffer2;
            msg.payloadlen = 2;
            msg.qos = QOS0;
            msg.retained = 0;
            MQTTPublish(&hMQTTClient, PUBLISH_TOPIC, &msg);
            Delay(20);
            send_on_bool = 0;
        } else if( (P3IN & BIT5) == 0 && debounce > 20) {
          debounce = 0;
          menu_select();
        } else if ( (P1IN & BIT4) == 0 && debounce > 10) {
          debounce = 0;
          menu();
        } else if ( steps_taken >= goal_steps && active_bool == 1 ) {
          P1OUT &= ~BIT0;
          int8_t buffer2[1] = "g";
          msg;
          msg.dup = 0;
          msg.id = 0;
          msg.payload = buffer2;
          msg.payloadlen = 1;
          msg.qos = QOS0;
          msg.retained = 0;
          MQTTPublish(&hMQTTClient, "on", &msg);
          Delay(20);
          MAP_Interrupt_disableInterrupt(INT_ADC14);
          active_bool = 0;
          view_goal_menu();
        }
    }
}
Example #9
0
int main(void){
  int32_t retVal = 0;
  char *pConfig = NULL;
  retVal = initializeAppVariables();
  stopWDT();        // Stop WDT 
  initClk();        // PLL 50 MHz
  LCD_Init();
  LED_Init();       // initialize LaunchPad I/O 
//  LCD_OutString("Weather App\n");
  LCD_OutString("Lab 16 IoT\n");
  /*
     * Following function configures the device to default state by cleaning
     * the persistent settings stored in NVMEM (viz. connection profiles &
     * policies, power policy etc)
     *
     * Applications may choose to skip this step if the developer is sure
     * that the device is in its default state at start of application
     *
     * Note that all profiles and persistent settings that were done on the
     * device will be lost
     */
  retVal = configureSimpleLinkToDefaultState(pConfig);
  if(retVal < 0){
    if(DEVICE_NOT_IN_STATION_MODE == retVal){
       LCD_OutString(" Failed to configure the device in its default state \r\n");
       Crash(4000000);
    }
  }

    /*
     * Assumption is that the device is configured in station mode already
     * and it is in its default state
     */
  retVal = sl_Start(0, pConfig, 0);
  if((retVal < 0) || (ROLE_STA != retVal) ){
    LCD_OutString(" Failed to start the device \r\n");
    Crash(8000000);

  }
  WlanConnect();
  LCD_OutString("Connected\n");

/* Get weather report */
  while(1){
    Nokia5110_SetCursor(0,2);
 //   retVal = getWeather();
    retVal = Lab16();
    if(retVal == 0){  // valid
      LED_GreenOn();
      UARTprintf("\r\n\r\n");
      UARToutString(appData.Recvbuff); UARTprintf("\r\n");
//      LCD_OutString(City); LCD_OutString("\n");
//      LCD_OutString(Temperature); LCD_OutString(" C\n");
//      LCD_OutString(Weather);
      LCD_OutString(Id); LCD_OutString("\n");
      LCD_OutString(Score); LCD_OutString("\n");
      LCD_OutString(Edxpost);
    }
    while(Board_Input()==0){}; // wait for touch
    LED_GreenOff();
  }
}
Example #10
0
/*
 * Application's entry point
 */
int main(int argc, char** argv)
{
    _i32 retVal = -1;

    retVal = initializeAppVariables();
    ASSERT_ON_ERROR(retVal);

    /* Stop WDT and initialize the system-clock of the MCU
       These functions needs to be implemented in PAL */
    stopWDT();
    initClk();

    /* Configure command line interface */
    CLI_Configure();

    displayBanner();

    /*
     * Following function configures the device to default state by cleaning
     * the persistent settings stored in NVMEM (viz. connection profiles &
     * policies, power policy etc)
     *
     * Applications may choose to skip this step if the developer is sure
     * that the device is in its default state at start of application
     *
     * Note that all profiles and persistent settings that were done on the
     * device will be lost
     */
    retVal = configureSimpleLinkToDefaultState();
    if(retVal < 0)
    {
        if (DEVICE_NOT_IN_STATION_MODE == retVal)
        {
            CLI_Write(" Failed to configure the device in its default state \n\r");
        }

        LOOP_FOREVER();
    }

    CLI_Write(" Device is configured in default state \n\r");

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

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

    /* Set the power policy to always On (SL_ALWAYS_ON_POLICY)
     * Both NWP and Wifi will remain active
     * Other Valid options are:
     *        - SL_NORMAL_POLICY
     *        - SL_LOW_POWER_POLICY
     *        - SL_LONG_SLEEP_INTERVAL_POLICY
     *
     * For Long sleep policy the max sleep time can be defined by
     * _u16 pBuff[4] = {0, 0, time, 0}, time:100-2000 in ms
     * sl_WlanPolicySet(SL_POLICY_PM , SL_LONG_SLEEP_INTERVAL_POLICY, pBuff, sizeof(pBuff)*/
    retVal = sl_WlanPolicySet(SL_POLICY_PM , SL_ALWAYS_ON_POLICY, NULL,0);
    if(retVal < 0)
        LOOP_FOREVER();

    CLI_Write(" Power mode enabled \n\r");

    /* Stop the CC3100 device */
    retVal = sl_Stop(SL_STOP_TIMEOUT);
    if(retVal < 0)
        LOOP_FOREVER();

    return 0;
}
Example #11
0
int main(void)
{
    UINT8  IsDHCP = 0;
    int32_t i32CommandStatus;
    _NetCfgIpV4Args_t ipV4;
		SlSockAddrIn_t    Addr; 
		UINT16            AddrSize = 0; 
		INT16             SockID = 0; 
		UINT32            data; 
		long x = 0; //counter
    unsigned char len = sizeof(_NetCfgIpV4Args_t);
    int Status = 0;
    /* Stop WDT */
    stopWDT();
    /* Initialize the system clock of MCU */
    initClk();
		Board_Init();       // initialize LaunchPad I/O and PD1 LED
    ConfigureUART();    // Initialize the UART.
    UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n");
    UARTprintf("This application is configured to generate text\n");
    UARTprintf("  and send UDP packets to IP: %d.%d.%d.%d  Port: %d\n\n",
      SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), 
      SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM);
		//added code from the powerpoint slide
    /* Initializing the CC3100 device */
    sl_Start(0, 0, 0);
    /* Connecting to WLAN AP - Set with static parameters defined at the top
       After this call we will be connected and have IP address */
    WlanConnect();
    /* Read the IP parameter */
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4);
    UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0));
    Addr.sin_family = SL_AF_INET;
    Addr.sin_port = sl_Htons((UINT16)PORT_NUM);
    Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR);
    AddrSize = sizeof(SlSockAddrIn_t);
    SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
    // Loop forever waiting  for commands from PC...
    //
    while(1)
    {
        // Print prompt for user.
        UARTprintf("\n>");
        // Peek to see if a full command is ready for processing.
        while(UARTPeek('\r') == -1)
						LED_On();
            // Approximately 1 millisecond delay.
            ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3000);

        }
        // A '\r' was detected so get the line of text from the receive buffer.
		while(Status >= 0){
      UARTprintf("\nSending a UDP packet ...\n");
		
			UARTgets(g_cInput,sizeof(g_cInput)); //this function receives the input from the Putty and places it in a string

			
			
			//DO NOT CHANGE ANYTHING ABOVE THIS COMMENT
			
			//WHAT WE NEED TO DO:
			//work with the g_cInput to get the array of letters typed into the Putty
			//then send that Array using UARTprintf
			uBuf[0] = ATYPE;   // defines this as an analog data type
			uBuf[1] = '='; 
			data = 1000;

			Int2Str(data,(char*)&uBuf[2]); // [2] to [7] is 6 digit number
      UARTprintf(" %s ",uBuf); //this line sends a string to the receiver
      //the above 5 lines print out a = 1000;
			//everything below this is just error cases
			if( SockID < 0 ){
        UARTprintf("SockIDerror ");
        Status = -1; // error
      }else{
        LED_Toggle();
        Status = sl_SendTo(SockID, uBuf, BUF_SIZE, 0,
                           (SlSockAddr_t *)&Addr, AddrSize);
        if( Status <= 0 ){
          sl_Close(SockID);
          UARTprintf("SockIDerror %d ",Status);
        }else{
          UARTprintf("ok");
        }
      }
      ROM_SysCtlDelay(ROM_SysCtlClockGet() / 100); // 10ms
			LED_Off();
		}
   }
Example #12
0
File: main.c Project: Mecabot/IoT
/*
 * Application's entry point
 */
int main(int argc, char** argv)
{
    _i32 retVal = -1;

    retVal = initializeAppVariables();
    ASSERT_ON_ERROR(retVal);

    /* Stop WDT and initialize the system-clock of the MCU */
    stopWDT();
    initClk();


    /* Configure command line interface */
    CLI_Configure();

    displayBanner();

    /*
     * Following function configures the device to default state by cleaning
     * the persistent settings stored in NVMEM (viz. connection profiles &
     * policies, power policy etc)
     *
     * Applications may choose to skip this step if the developer is sure
     * that the device is in its default state at start of application
     *
     * Note that all profiles and persistent settings that were done on the
     * device will be lost
     */
    retVal = configureSimpleLinkToDefaultState();
    if(retVal < 0)
    {
        if (DEVICE_NOT_IN_STATION_MODE == retVal)
            CLI_Write(" Failed to configure the device in its default state \n\r");

        LOOP_FOREVER();
    }

    CLI_Write(" Device is configured in default state \n\r");

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

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

    /* Connecting to WLAN AP */
    retVal = establishConnectionWithAP();
    if(retVal < 0)
    {
        CLI_Write(" Failed to establish connection w/ an AP \n\r");
        LOOP_FOREVER();
    }

    CLI_Write(" Connection established w/ AP and IP is acquired \n\r");

    //
    // Main Program Loop
	//
    while(1)
	{

		//
		// Get the current time from an SNTP server
		//
    	retVal = GetCurrentTime();
		if(retVal < 0)
		{
			CLI_Write(" Failed to GetCurrentTime.\n\r");
		}

		//
		// Send the JSON packet with temperature to Event Hub
		//
		retVal = PostEventHubSSL();
		if(retVal < 0)
		{
			CLI_Write(" Failed to PostEventHubSSL.\n\r");
		}

		//
		// Wait a while before resuming.
		// This is an estimate, for more accuracy other methods should be implemented.
		//
		Delay(SLEEP_TIME);
	}
}
Example #13
0
/*
 * Application's entry point
 */
int main(int argc, char** argv)
{
    SlPingStartCommand_t PingParams = {0};
    SlPingReport_t Report = {0};

    _u8 SecType = 0;
    _i32 mode = ROLE_STA;
    _i32 retVal = -1;

    retVal = initializeAppVariables();
    ASSERT_ON_ERROR(retVal);

    /* Stop WDT and initialize the system-clock of the MCU */
    stopWDT();
    initClk();

    /* Configure command line interface */
    CLI_Configure();

    displayBanner();

    CLR_STATUS_BIT(g_Status, STATUS_BIT_PING_DONE);
    g_PingPacketsRecv = 0;

    /*
     * Following function configures the device to default state by cleaning
     * the persistent settings stored in NVMEM (viz. connection profiles &
     * policies, power policy etc)
     *
     * Applications may choose to skip this step if the developer is sure
     * that the device is in its default state at start of application
     *
     * Note that all profiles and persistent settings that were done on the
     * device will be lost
     */
    retVal = configureSimpleLinkToDefaultState();
    if(retVal < 0)
    {
        if (DEVICE_NOT_IN_STATION_MODE == retVal)
            CLI_Write((_u8 *)" Failed to configure the device in its default state \n\r");

        LOOP_FOREVER();
    }

    CLI_Write((_u8 *)" Device is configured in default state \n\r");

    /*
     * Assumption is that the device is configured in station mode already
     * and it is in its default state
     */
    mode = sl_Start(0, 0, 0);
    if (ROLE_AP == mode)
    {
        /* If the device is in AP mode, we need to wait for this event before doing anything */
        while(!IS_IP_ACQUIRED(g_Status)) { _SlNonOsMainLoopTask(); }
    }
    else
    {
        /* Configure CC3100 to start in AP mode */
        retVal = sl_WlanSetMode(ROLE_AP);
        if(retVal < 0)
            LOOP_FOREVER();

        /* Configure the SSID of the CC3100 */
        retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID,
                pal_Strlen(SSID_AP_MODE), (_u8 *)SSID_AP_MODE);
        if(retVal < 0)
            LOOP_FOREVER();

        SecType = SEC_TYPE_AP_MODE;
        /* Configure the Security parameter the AP mode */
        retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SECURITY_TYPE, 1,
                (_u8 *)&SecType);
        if(retVal < 0)
            LOOP_FOREVER();

        retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_PASSWORD, pal_Strlen(PASSWORD_AP_MODE),
                (_u8 *)PASSWORD_AP_MODE);
        if(retVal < 0)
            LOOP_FOREVER();

        retVal = sl_Stop(SL_STOP_TIMEOUT);
        if(retVal < 0)
            LOOP_FOREVER();

        CLR_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED);

        mode = sl_Start(0, 0, 0);
        if (ROLE_AP == mode)
        {
            /* If the device is in AP mode, we need to wait for this event before doing anything */
            while(!IS_IP_ACQUIRED(g_Status)) { _SlNonOsMainLoopTask(); }
        }
        else
        {
            CLI_Write((_u8 *)" Device couldn't be configured in AP mode \n\r");
            LOOP_FOREVER();
        }
    }

    CLI_Write((_u8 *)" Device started as Access Point\n\r");
while(1){
    /* Wait */
    CLI_Write((_u8 *)" Waiting for clients to connect...!\n\r");
    while((!IS_IP_LEASED(g_Status)) || (!IS_STA_CONNECTED(g_Status))) { _SlNonOsMainLoopTask(); }
    CLI_Write((_u8 *)" Client connected to the device \n\r");
    CLI_Write((_u8 *)" Pinging...! \n\r");

    /* Set the ping parameters */
    PingParams.PingIntervalTime = PING_INTERVAL;
    PingParams.PingSize = PING_SIZE;
    PingParams.PingRequestTimeout = PING_REQUEST_TIMEOUT;
    PingParams.TotalNumberOfAttempts = PING_ATTEMPT;
    PingParams.Flags = 0;
    PingParams.Ip = g_StationIP; /* Fill the station IP address connected to CC3100 */

    /* Ping client connected to CC3100 */
    retVal = sl_NetAppPingStart((SlPingStartCommand_t*)&PingParams, SL_AF_INET,
                       (SlPingReport_t*)&Report, SimpleLinkPingReport);
    if(retVal < 0)
        LOOP_FOREVER();

    /* Wait */
    while(!IS_PING_DONE(g_Status)) { _SlNonOsMainLoopTask(); }

    if (0 == g_PingPacketsRecv)
    {
        CLI_Write((_u8 *)" A STATION couldn't connect to the device \n\r");
        ASSERT_ON_ERROR(LAN_CONNECTION_FAILED);
    }

    CLI_Write((_u8 *)" Device and the station are successfully connected \n\r");
}
    return SUCCESS;
}
/*
 * Application's entry point
 */
int main(int argc, char** argv)
{
    _u8   SecType = 0;
    _i32   retVal = -1;
    _i32   mode = ROLE_STA;

    retVal = initializeAppVariables();
    ASSERT_ON_ERROR(retVal);

    /* Stop WDT and initialize the system-clock of the MCU */ 
    stopWDT();//WDT-Watch Dog Timer
    initClk();

    initLEDs();

    /* Configure command line interface */
    CLI_Configure();

    displayBanner();

    /*
     * Following function configures the device to default state by cleaning
     * the persistent settings stored in NVMEM (viz. connection profiles &
     * policies, power policy etc)
     *
     * Applications may choose to skip this step if the developer is sure
     * that the device is in its default state at start of application
     *
     * Note that all profiles and persistent settings that were done on the
     * device will be lost
     */
    retVal = configureSimpleLinkToDefaultState();
    if(retVal < 0)
    {
        if (DEVICE_NOT_IN_STATION_MODE == retVal)
            CLI_Write(" Failed to configure the device in its default state \n\r");

        LOOP_FOREVER();
    }

    CLI_Write(" Device is configured in default state \n\r");

    /*
     * Assumption is that the device is configured in station mode already
     * and it is in its default state
     */
    mode = sl_Start(0, 0, 0);
    if(mode < 0)
    {
        LOOP_FOREVER();
    }
    else
    {
        if (ROLE_AP == mode)
        {
            /* If the device is in AP mode, we need to wait for this
             * event before doing anything */
            while(!IS_IP_ACQUIRED(g_Status)) { _SlNonOsMainLoopTask(); }
        }
        else
        {
            /* Configure CC3100 to start in AP mode */
            retVal = sl_WlanSetMode(ROLE_AP);
            if(retVal < 0)
                LOOP_FOREVER();
        }
    }

    /* Configure AP mode without security */
    retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID,
               pal_Strlen(SSID_AP_MODE), (_u8 *)SSID_AP_MODE);
    if(retVal < 0)
        LOOP_FOREVER();

    SecType = SEC_TYPE_AP_MODE;
    /* Configure the Security parameter in the AP mode */
    retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SECURITY_TYPE, 1,
            (_u8 *)&SecType);
    if(retVal < 0)
        LOOP_FOREVER();

    retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_PASSWORD, pal_Strlen(PASSWORD_AP_MODE),
            (_u8 *)PASSWORD_AP_MODE);
    if(retVal < 0)
        LOOP_FOREVER();

    /* Restart the CC3100 */
    retVal = sl_Stop(SL_STOP_TIMEOUT);
    if(retVal < 0)
        LOOP_FOREVER();

    g_Status = 0;

    mode = sl_Start(0, 0, 0);
    if (ROLE_AP == mode)
    {
        /* If the device is in AP mode, we need to wait for this event before doing anything */
        while(!IS_IP_ACQUIRED(g_Status)) { _SlNonOsMainLoopTask(); }
    }
    else
    {
        CLI_Write(" Device couldn't come in AP mode \n\r");
        LOOP_FOREVER();
    }

    CLI_Write(" \r\n Device is configured in AP mode \n\r");

    CLI_Write(" Waiting for client to connect\n\r");
    /* wait for client to connect */
    while((!IS_IP_LEASED(g_Status)) || (!IS_STA_CONNECTED(g_Status))) { _SlNonOsMainLoopTask(); }

    CLI_Write(" Client connected\n\r");

    /* Enable the HTTP Authentication */
    retVal = set_authentication_check(TRUE);
    if(retVal < 0)
        LOOP_FOREVER();

    /* Get authentication parameters */
    retVal = get_auth_name(g_auth_name);
    if(retVal < 0)
        LOOP_FOREVER();

    retVal = get_auth_password(g_auth_password);
    if(retVal < 0)
        LOOP_FOREVER();

    retVal = get_auth_realm(g_auth_realm);
    if(retVal < 0)
        LOOP_FOREVER();

    CLI_Write((_u8 *)"\r\n Authentication parameters: ");
    CLI_Write((_u8 *)"\r\n Name = ");
    CLI_Write(g_auth_name);
    CLI_Write((_u8 *)"\r\n Password = "******"\r\n Realm = ");
    CLI_Write(g_auth_realm);

    /* Get the domain name */
    retVal = get_domain_name(g_domain_name);
    if(retVal < 0)
        LOOP_FOREVER();

    CLI_Write((_u8 *)"\r\n\r\n Domain name = ");
    CLI_Write(g_domain_name);

    /* Get URN */
    retVal = get_device_urn(g_device_urn);
    if(retVal < 0)
        LOOP_FOREVER();

    CLI_Write((_u8 *)"\r\n Device URN = ");
    CLI_Write(g_device_urn);
    CLI_Write((_u8 *)"\r\n");

    /* Process the async events from the NWP */
    while(1)
    {
        _SlNonOsMainLoopTask();
    }
}