Ejemplo n.º 1
0
/*---------------------------------------------------------------------------*
 * Routine:  WIFI_Associate
 *---------------------------------------------------------------------------*
 * Description:
 *      Association and show result on the LCD
 * Inputs:
 *      void
 * Outputs:
 *      ATLIBGS_MSG_ID_E
 *---------------------------------------------------------------------------*/
ATLIBGS_MSG_ID_E WIFI_Associate(void)
{
    ATLIBGS_MSG_ID_E rxMsgId = ATLIBGS_MSG_ID_NONE;
    static ATLIBGS_AUTHMODE_E WEPMode=ATLIBGS_AUTHMODE_OPEN_WEP;
    int retVal;

    DisplayLCD(LCD_LINE4, "wl_trycon.. ");

    /* Associate to a particular AP specified by SSID  */
    if (strlen(GNV_Setting.webprov.ssid) > 0)
    {
        rxMsgId = AtLibGs_Assoc(GNV_Setting.webprov.ssid,NULL,HOST_APP_AP_CHANNEL);
    }
    else
    {
        rxMsgId = AtLibGs_Assoc(HOST_APP_AP_SSID, NULL, HOST_APP_AP_CHANNEL);
    }
    if (ATLIBGS_MSG_ID_OK != rxMsgId) 
    {
        /* Association error - we can retry */
        if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WEP)
        {
            if(WEPMode==ATLIBGS_AUTHMODE_OPEN_WEP)
            {
                rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_SHARED_WEP);// Potenially it's a WEP shared AP
                WEPMode=ATLIBGS_AUTHMODE_SHARED_WEP;
            }
            else
            {
                rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_OPEN_WEP);// Potenially it's a WEP shared AP
                WEPMode=ATLIBGS_AUTHMODE_OPEN_WEP;         
            }
        }
        DisplayLCD(LCD_LINE4, "Assoc failed...");
        MSTimerDelay(2000);
        DisplayLCD(LCD_LINE4, "Trying again...");
    } 
    else 
    {
        /* Association success */
        AtLibGs_SetNodeAssociationFlag();
        DisplayLCD(LCD_LINE4, "wl_connect  ");
        MSTimerDelay(2000);
        retVal = App_ConnectMqtt();
        switch(retVal)
        {
        case 0:    
            DisplayLCD(LCD_LINE5, "MQTT Connected");
            break;
        case -1:    
            DisplayLCD(LCD_LINE5, "MQTT packet error");
            break;
        case -2:    
            DisplayLCD(LCD_LINE5, "MQTT connack error");
            break;      
        }
    }

    return rxMsgId;
}
Ejemplo n.º 2
0
/*---------------------------------------------------------------------------*
 * Routine:  WIFI_Associate
 *---------------------------------------------------------------------------*
 * Description:
 *      Association and show result on the LCD
 * Inputs:
 *      void
 * Outputs:
 *      ATLIBGS_MSG_ID_E
 *---------------------------------------------------------------------------*/
ATLIBGS_MSG_ID_E WIFI_Associate(void)
{
  ATLIBGS_MSG_ID_E rxMsgId = ATLIBGS_MSG_ID_NONE;

  DisplayLCD(LCD_LINE7, " Connecting ");

  /* Associate to a particular AP specified by SSID  */
  if (strlen(GNV_Setting.webprov.ssid) > 0)
  {
    DisplayLCD(LCD_LINE8, (const uint8_t *)GNV_Setting.webprov.ssid);
    rxMsgId = AtLibGs_Assoc(GNV_Setting.webprov.ssid,NULL,HOST_APP_AP_CHANNEL);
  }
  else
  {
    DisplayLCD(LCD_LINE8, HOST_APP_AP_SSID);
    rxMsgId = AtLibGs_Assoc(HOST_APP_AP_SSID, NULL, HOST_APP_AP_CHANNEL);
  }
  if (ATLIBGS_MSG_ID_OK != rxMsgId) {
    /* Association error - we can retry */
#ifdef HOST_APP_DEBUG_ENABLE
        ConsolePrintf("\n Association error - retry now \n");
#endif
    DisplayLCD(LCD_LINE7, " Connecting..");
    MSTimerDelay(2000);
    DisplayLCD(LCD_LINE7, "");
  } else {
    /* Association success */
    AtLibGs_SetNodeAssociationFlag();
    DisplayLCD(LCD_LINE7, " Connected ");
    MSTimerDelay(2000);
    DisplayLCD(LCD_LINE7, "");
  }

  return rxMsgId;
}
Ejemplo n.º 3
0
/*---------------------------------------------------------------------------*
 * Routine:  App_StartupLimitedAP
 *---------------------------------------------------------------------------*
 * Description:
 *      Put the unit into a limited AP mode using the configuration in the
 *      default LimitedAP settings.
 * Inputs:
 *      void
 * Outputs:
 *      void
 *---------------------------------------------------------------------------*/
void App_StartupLimitedAP(char *mySSID)
{
    ATLIBGS_MSG_ID_E r;

    DisplayLCD(LCD_LINE3, "Limited AP:");
    DisplayLCD(LCD_LINE4, (uint8_t const *)mySSID);

#ifdef ATLIBGS_DEBUG_ENABLE
    ConsolePrintf("Starting Limited AP: %s\n", ATLIBGS_LIMITED_AP_SSID);
#endif

    /* Try to disassociate if not already associated */
    AtLibGs_DisAssoc();
    while (1) {
        DisplayLCD(LCD_LINE6, " Setting up");
           
        r =AtLibGs_EnableRadio(1);                       // enable radio
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad Mode!");
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_Mode(ATLIBGS_STATIONMODE_LIMITED_AP);
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad Mode!");
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_IPSet(ATLIBGS_LIMITED_AP_IP, ATLIBGS_LIMITED_AP_MASK,
                ATLIBGS_LIMITED_AP_GATEWAY);
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad IP!");
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_EnableDHCPServer();
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad DHCPSrv!");
            AtLibGs_DisableDHCPServer();
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_Assoc(mySSID /*ATLIBGS_LIMITED_AP_SSID*/, 0,
                ATLIBGS_LIMITED_AP_CHANNEL);
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "AP Failed!");
            MSTimerDelay(2000);
            continue;
        }
        break;
    }
    DisplayLCD(LCD_LINE6, "");
#ifdef ATLIBGS_DEBUG_ENABLE
    ConsolePrintf("Limited AP Started\n");
#endif
}
Ejemplo n.º 4
0
/*---------------------------------------------------------------------------*
 * Routine:  App_StartWPS
 *---------------------------------------------------------------------------*
 * Description:
 *      Put the unit into WPS pushbutton mode. After pushing the button on the 
 *      AP the unit will retrieve its SSID and pass phrase, then connect to it
 * Inputs:
 *      void
 * Outputs:
 *      void
 *---------------------------------------------------------------------------*/
void App_StartWPS(void)
{
    ATLIBGS_MSG_ID_E rxMsgId;
    ATLIBGS_NetworkStatus network;
    AtLibGs_WPSResult result;
    char text[20];
    
    while (1) {
        // Ensure we are not connected to any network (from previous runs)
        AtLibGs_DisAssoc();

        /* Pushbutton WPS demo */
        /* Use Wi-Fi Protected Setup (WPS) FW */
        /* turn on DHCP client */
        AtLibGs_DHCPSet(1);

        /* set to connect to AP mode */
        AtLibGs_Mode(ATLIBGS_STATIONMODE_INFRASTRUCTURE);
        DisplayLCD(LCD_LINE5, "  Push the  ");
        DisplayLCD(LCD_LINE6, "button on AP");

        /* push the button on the AP so the GS module can connect */
        while (AtLibGs_StartWPSPUSH(&result) != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE8, " Not found!");
            MSTimerDelay(1000);
            DisplayLCD(LCD_LINE8, " Retrying...");
            MSTimerDelay(1000);
            DisplayLCD(LCD_LINE8, "");
        }

        /* Connect to AP (found from pushbutton) after setting pass phrase */
        AtLibGs_SetPassPhrase(result.password);
        AtLibGs_Assoc(result.ssid, "", result.channel);

        rxMsgId = AtLibGs_GetNetworkStatus(&network);
        if (rxMsgId != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE8, "Bad Network!");
            MSTimerDelay(2000);
            DisplayLCD(LCD_LINE8, "");
            continue;
        } else {
            strncpy(text, network.ssid, 12);
            DisplayLCD(LCD_LINE4, (const uint8_t *)text);
        }
        break;
    }

    DisplayLCD(LCD_LINE5, "");
    DisplayLCD(LCD_LINE6, "");
}
Ejemplo n.º 5
0
/*****************************************************************************
*
*  show_status
*
*  \param  None
*
*  \return None
*
*  \brief  Shows the status message on the LCD display
*
*****************************************************************************/
void
show_status(void)
{
  int code = Exosite_StatusCode();

  DisplayLCD(LCD_LINE6, "  Exosite  ");

  if (code == EXO_STATUS_BAD_TCP) {
    DisplayLCD(LCD_LINE7, "Connecting ");
    DisplayLCD(LCD_LINE8, "   Retry   ");
  } else if (code == EXO_STATUS_BAD_UUID) {
    DisplayLCD(LCD_LINE7, "  Bad UUID ");
  } else if (code == EXO_STATUS_BAD_VENDOR) {
    DisplayLCD(LCD_LINE7, " Incorrect ");
    DisplayLCD(LCD_LINE8, "Vendor Name");
  } else if (code == EXO_STATUS_BAD_MODEL) {
    DisplayLCD(LCD_LINE7, " Incorrect ");
    DisplayLCD(LCD_LINE8, " Model Name");
  } else if (code == EXO_STATUS_BAD_SN) {
    DisplayLCD(LCD_LINE7, " Add Device");
    DisplayLCD(LCD_LINE8, "  to Portal");
  } else if (code == EXO_STATUS_BAD_CIK) {
    DisplayLCD(LCD_LINE7, "CIK Invalid");
    MSTimerDelay(1000);
    DisplayLCD(LCD_LINE7, "  Re-enable");
    DisplayLCD(LCD_LINE8, "   Device  ");
  } else if (code == EXO_STATUS_CONFLICT) {
    DisplayLCD(LCD_LINE7, "  Re-enable");
    DisplayLCD(LCD_LINE8, "   Device  ");
  } else if (code == EXO_STATUS_NOAUTH) {
    DisplayLCD(LCD_LINE7, "CIK Invalid");
  }

  return;
}
Ejemplo n.º 6
0
/*---------------------------------------------------------------------------*
 * Routine:  App_InitModule
 *---------------------------------------------------------------------------*
 * Description:
 *      Setup the mode by first checking if there is a link and either
 *      report or continue to the rest of the program.
 * Inputs:
 *      void
 * Outputs:
 *      void
 *---------------------------------------------------------------------------*/
void App_InitModule(void)
{
    ATLIBGS_MSG_ID_E r = ATLIBGS_MSG_ID_NONE;

    DisplayLCD(LCD_LINE7, " Preparing");
    DisplayLCD(LCD_LINE8, "  Init Mod");

    /* Give the unit a little time to start up */
    /* (300 ms for GS1011 and 1000 ms for GS1500) */
    MSTimerDelay(1000);

    /* Check the link */
#ifdef ATLIBGS_DEBUG_ENABLE
    ConsolePrintf("Checking link\r\n");
#endif

    /* Wait for the banner (if any) */
    MSTimerDelay(500);

    /* Clear out the buffers */
    AtLibGs_FlushRxBuffer();

    /* Send command to check */
    do {
        AtLibGs_FlushIncomingMessage();
        DisplayLCD(LCD_LINE8, "Checking...");
        r = AtLibGs_Check();
    } while (ATLIBGS_MSG_ID_OK != r);

    /* Send command to DISABLE echo */
    do {
        DisplayLCD(LCD_LINE8, "Echo Off...");
        r = AtLibGs_SetEcho(ATLIBGS_DISABLE);
    } while (ATLIBGS_MSG_ID_OK != r);

    /* Done */
    DisplayLCD(LCD_LINE7, "");
    DisplayLCD(LCD_LINE8, "");
}
Ejemplo n.º 7
0
/*---------------------------------------------------------------------------*
 * Routine:  App_OverTheAirProgrammingPushMetheod
 *---------------------------------------------------------------------------*
 * Description:
 *      Put the unit into over the air programming mode in Push Method after connecting to an
 *      access point in infrastructure mode.
 * Inputs:
 *      void
 * Outputs:
 *      void
 *---------------------------------------------------------------------------*/
void App_OverTheAirProgrammingPushMetheod(void)
{
    ATLIBGS_MSG_ID_E r;

    App_InitModule();

    while(1)
    {
       r = AtLibGs_GetMAC(WiFiMAC);
       if(r != ATLIBGS_MSG_ID_OK) 
       {
          DisplayLCD(LCD_LINE6, "Get MAC Failed!");
          MSTimerDelay(2000);
          continue;
       } 
       break;
    }; 
    
    if(r == ATLIBGS_MSG_ID_OK)
      AtLibGs_ParseGetMacResponse(WiFiMACStr);    
    strcpy(str_config_ssid, (char const*)ATLIBGS_ADK_SSID); 
    strcat(str_config_ssid, &WiFiMACStr[6]);                     // concatenate last 6 digis of MAC as SSID  
    
    App_StartupLimitedAP(str_config_ssid);
    
    r = AtLibGs_WebProv(",", ",");
    while(r != ATLIBGS_MSG_ID_OK) {
        DisplayLCD(LCD_LINE6, "Bad WebProv!");
        MSTimerDelay(2000);
        continue;
    }
    DisplayLCD(LCD_LINE6, "Download ON");   
    DisplayLCD(LCD_LINE7, (const uint8_t *) "192.168.240.");
    DisplayLCD(LCD_LINE8, (const uint8_t *) "1/otafu.html");  
    while(1)
      ;
}
Ejemplo n.º 8
0
/*****************************************************************************
*
*  ReadCloudCommands
*
*  \param  None
*
*  \return None
*
*  \brief  Reads the commands from Exosite cloud
*
*****************************************************************************/
void ReadCloudCommands(void)
{
  char * pbuf = exo_buffer;
  DisplayLCD(LCD_LINE6, "  Exosite  ");
  DisplayLCD(LCD_LINE7, "    Read   ");
  if (Exosite_Read("led_ctrl", pbuf, EXO_BUFFER_SIZE)) {
    DisplayLCD(LCD_LINE8, "     OK    ");
    if (!strncmp(pbuf, "0", 1)) 
      led_all_off();
    else if (!strncmp(pbuf, "1", 1)) 
      led_all_on();
  }
  else show_status();
  MSTimerDelay(500);

  return;
}
Ejemplo n.º 9
0
/*******************************************************************************
 * Outline      : EEPROM_Write
 * Description  : This function writes the given contents to the
 *                 EEPROM, at the given location.
 * Argument     : offset -- Offset byte from start of EEPROM
 *                aData -- Pointer to bytes to write to EEPROM
 *                aSize -- number of bytes to write to EEPROM
 * Return value : 0 = success, else failure
 *******************************************************************************/
uint8_t EEPROM_Write(uint16_t offset, uint8_t *aData, uint16_t aSize)
{
    I2C_Request r;
    uint32_t timeout = MSTimerGet();
    uint8_t writeData[EEPROM_BYTES_PER_WRITE+2];
    uint16_t i, j, bytesToWrite;

    r.iAddr = EEPROM_ADDR>>1;
    r.iSpeed = 100; /* kHz */
    
    // Write Data in groups of size defined by EEPROM_BYTES_PER_WRITE
    for(i=0; i<aSize; i+=EEPROM_BYTES_PER_WRITE) {
      
        // Data Address in the EEPROM to write to
        writeData[0] = (uint8_t)(i + offset)<<8;
        writeData[1] = (uint8_t)(i + offset);
        
        for(j=0; j<EEPROM_BYTES_PER_WRITE; j++) {
            writeData[2+j] = aData[i+j];
        }
        
        if((aSize - i) < EEPROM_BYTES_PER_WRITE)
            bytesToWrite = aSize - i;
        else
            bytesToWrite = EEPROM_BYTES_PER_WRITE;
        
        r.iWriteData = writeData;
        r.iWriteLength = 2+bytesToWrite;
        r.iReadData = 0;
        r.iReadLength = 0;
    
        I2C_Start();
        I2C_Write(&r, 0);
        MSTimerDelay(10); // Part requires a 5ms to process a data write
        while ((I2C_IsBusy()) && (MSTimerDelta(timeout) < EEPROM_TIMEOUT))
            {}
    }
    
    return 0;
}
Ejemplo n.º 10
0
/*---------------------------------------------------------------------------*/
void App_TCPClientDemo(void)
{
    ATLIBGS_MSG_ID_E rxMsgId = ATLIBGS_MSG_ID_NONE;
    static char content[512];
    uint8_t cid = 0;
    static int16_t G_adc_int[2] = { 0, 0 };
    static char G_temp_int[2] = { 0, 0 };
    uint8_t remoteTcpSrvIp[20];
    
    bool connected = false; // when connected to TCP server this is true
    uint32_t time = MSTimerGet();
    ATLIBGS_TCPMessage msg;
    ATLIBGS_NetworkStatus networkStatus;
    
    AtLibGs_GetNetworkStatus(&networkStatus);
    
    AppTCPSetIPMenu(&networkStatus);

    sprintf((char*)remoteTcpSrvIp, "%d.%d.%d.%d",
            networkStatus.addr.ipv4[0],
            networkStatus.addr.ipv4[1],
            networkStatus.addr.ipv4[2],
            G_nvsettings.webprov.tcpIPClientHostIP);
    
    App_PrepareIncomingData();
    while (1) {
        if (!AtLibGs_IsNodeAssociated()) {
            App_Connect(&G_nvsettings.webprov);
            connected = false;
        } else if (!connected) {
            DisplayLCD(LCD_LINE7, "Connecting");
            // Start a TCP client
            rxMsgId = AtLibGs_TCPClientStart((char *)remoteTcpSrvIp,
                    TCP_DEMO_REMOTE_TCP_SRVR_PORT, &cid);
            if (rxMsgId != ATLIBGS_MSG_ID_OK) {
                DisplayLCD(LCD_LINE7, "No Connect!");
                MSTimerDelay(2000);
                DisplayLCD(LCD_LINE7, "");
                continue;
            }
            if (cid == ATLIBGS_INVALID_CID) {
                DisplayLCD(LCD_LINE7, "No CID!");
                MSTimerDelay(2000);
                DisplayLCD(LCD_LINE7, "");
                continue;
            }
            DisplayLCD(LCD_LINE7, "");
            App_PrepareIncomingData();
            connected = true;
        } else {
            App_TemperatureReadingUpdate(G_temp_int, true);
            App_PotentiometerUpdate(G_adc_int, true);

            // Look to see if there is a message
            if ((G_receivedCount) || (AtLibGs_WaitForTCPMessage(250)
                    == ATLIBGS_MSG_ID_DATA_RX)) {
                // Got data!  Its sitting in G_received, but in a <CID> <data> format
                // We need to send it back
                AtLibGs_ParseTCPData(G_received, G_receivedCount, &msg);

                // Prepare for the next batch of incoming data
                App_PrepareIncomingData();

                // Copy the data out of the receive message (its sitting in G_recieved)
                memcpy(content, msg.message, msg.numBytes);

                // Now send this back over the TCP/IP connection
                rxMsgId = AtLibGs_SendTCPData(cid, (uint8_t *)content,
                        msg.numBytes);
                if (rxMsgId != ATLIBGS_MSG_ID_OK) {
                    DisplayLCD(LCD_LINE7, " Send Fail!");
                    MSTimerDelay(2000);
                    DisplayLCD(LCD_LINE7, "");
                    continue;
                }
            } else if (MSTimerDelta(time) >= TCP_DEMO_UPDATE_INTERVAL) {
                time = MSTimerGet();
                // send temp and ADC to last received TCP client every X seconds

                DisplayLCD(LCD_LINE7, " Sending");
                sprintf(content, "Temp: %d.%d, Pot: %d.%d%%\r\n", G_temp_int[0],
                        G_temp_int[1], G_adc_int[0], G_adc_int[1]);
                // send data to server
                rxMsgId = AtLibGs_SendTCPData(cid, (uint8_t *)content, strlen(
                        content));
                if (rxMsgId != ATLIBGS_MSG_ID_OK) {
                    DisplayLCD(LCD_LINE7, " Send Fail!");
                    MSTimerDelay(2000);
                    DisplayLCD(LCD_LINE7, "");
                    connected = false;
                    continue;
                } // end if
                DisplayLCD(LCD_LINE7, "");
            } // end else if
        } // end else
    } // end while
}
Ejemplo n.º 11
0
/*---------------------------------------------------------------------------*
 * Routine:  App_StartupADKDemo
 *---------------------------------------------------------------------------*
 * Description:
 *      Put the unit into a limited AP mode, enable XML parse, and setup mDNS
 *      
 * Inputs:
 *      void
 * Outputs:
 *      void
 *---------------------------------------------------------------------------*/
void App_StartupADKDemo(void)
{
    ATLIBGS_MSG_ID_E r;

   // DisplayLCD(LCD_LINE3, "Limited AP");
   // DisplayLCD(LCD_LINE4, ATLIBGS_LIMITED_AP_SSID);   
   // VirginCheck();   
#if 1                     
    DisplayLCD(LCD_LINE3, (const uint8_t *) "192.168.240.");
    DisplayLCD(LCD_LINE4, (const uint8_t *) "1/rdk.html");  
#else   
    DisplayLCD(LCD_LINE3, (const uint8_t *) "192.168.1.1/");
    DisplayLCD(LCD_LINE4, (const uint8_t *) "rdk.html"); 
#endif
    
#ifdef ATLIBGS_DEBUG_ENABLE
    ConsolePrintf("Starting Limited AP: %s\n", ATLIBGS_LIMITED_AP_SSID);
#endif

    /* Try to disassociate if not already associated */
    AtLibGs_DisAssoc();
    while (1) {
        DisplayLCD(LCD_LINE6, " Setting up");

        r =AtLibGs_EnableRadio(1);                       // enable radio
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad Mode!");
            MSTimerDelay(2000);
            continue;
        }  
#if 0
        r = AtLibGs_ConfigAntenna(1);
         if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Configure Antenna Fail!");
            MSTimerDelay(2000);
            continue;
        }
#endif
        r = AtLibGs_Mode(ATLIBGS_STATIONMODE_LIMITED_AP);
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad Mode!");
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_IPSet(ATLIBGS_ADK_IP, ATLIBGS_ADK_MASK,
                ATLIBGS_ADK_GATEWAY);
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad IP!");
            MSTimerDelay(2000);
            continue;
        }
        AtLibGs_DisableDHCPServer();
        r = AtLibGs_EnableDHCPServer();
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad DHCPSrv!");
            MSTimerDelay(2000);
            continue;
        }
 #if 0
        r = AtLibGs_SetRegulatoryDomain(ATLIBGS_REGDOMAIN_TELEC);
         if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Set Domain Fail");
            MSTimerDelay(2000);
            continue;
        }
#endif
         r = AtLibGs_GetMAC(WiFiMAC);
         if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Get MAC Failed!");
            MSTimerDelay(2000);
            continue;
        } 

        if(r == ATLIBGS_MSG_ID_OK)
           AtLibGs_ParseGetMacResponse(WiFiMACStr);

        strcpy(str_config_ssid, (char const*)ATLIBGS_ADK_SSID); 
        strcat(str_config_ssid, &WiFiMACStr[6]);                     // concatenate last 6 digis of MAC as SSID                          
        DisplayLCD(LCD_LINE1, (const uint8_t *)str_config_ssid);
        r = AtLibGs_Assoc(str_config_ssid /*ATLIBGS_ADK_SSID*/, 0,
                ATLIBGS_ADK_CHANNEL);
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "AP Failed!");
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_WebServer(1, "", "", "", "");
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Server Failed!");
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_SetXMLParse(1);;
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "XML Failed!");
            MSTimerDelay(2000);
            continue;
        }
#if 1 // mDNS_ENABLED
        // now start mNDS service 
        r = AtLibGs_StartMDNS();
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "MDNS1 Failed!");
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_RegisterMDNSHost("xyz","local");
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "MDNS2 Failed!");
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_RegisterMDNSService(ATLIBGS_ADK_MDNS_SERVER,"","_http","_tcp","local","80","path=/gainspan/profile/mcu");
      //  r = AtLibGs_RegisterMDNSService(ATLIBGS_ADK_MDNS_SERVER,"","_http","_tcp","local","80","path=/rdk.html");
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "MDNS3 Failed!");
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_AnnounceMDNS();
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "MDNS4 Failed!");
            MSTimerDelay(2000);
            continue;
        }
#endif
        break;
    }
    DisplayLCD(LCD_LINE6, "");
    MSTimerDelay(2000);
    AtLibGs_FlushIncomingMessage();
#ifdef ATLIBGS_DEBUG_ENABLE
    ConsolePrintf("ADK Demo Started\n");
#endif
}
Ejemplo n.º 12
0
int  main(void)
{
    AppMode_T AppMode; APP_STATE_E state=UPDATE_TEMPERATURE; 
    char LCDString[30], temp_char[2]; uint16_t temp; float ftemp;
  
    HardwareSetup();

    /************************initializa LCD module********************************/
    SPI2_Init();
    InitialiseLCD();
    led_init();
    MSTimerInit();

    /* Default app mode */
    AppMode = GAINSPAN_DEMO;
    
    /* If the CIK is exist, auto into the Exosite mode */
    NVSettingsLoad(&GNV_Setting);
    
    /* Determine if SW1 & SW3 is pressed at power up to enter programming mode */
    if (Switch1IsPressed() && Switch3IsPressed()) {
         AppMode = PROGRAM_MODE;
    }
    else if(Switch3IsPressed() && Switch2IsPressed())
    {
         AppMode = EXOSITE_ERASE;
    }
    else if(Switch1IsPressed())
    {
        AppMode = RUN_EXOSITE;
    }
    else if(Switch2IsPressed())
    {
        AppMode = RUN_PROVISIONING;
    }
    else if(Switch3IsPressed())
    {
        AppMode = RUN_OVER_AIR_DOWNLOAD;
    }
    
    if(AppMode == GAINSPAN_DEMO) {
        LCDDisplayLogo();
        LCDSelectFont(FONT_SMALL);
        DisplayLCD(LCD_LINE3, "RL78G14 RDK    V2.0");
        DisplayLCD(LCD_LINE4, "   Wi-Fi & Cloud   ");
        DisplayLCD(LCD_LINE5, "     demos by:     ");
        DisplayLCD(LCD_LINE6, "Gainspan           ");
        DisplayLCD(LCD_LINE7, "Exosite            ");
        DisplayLCD(LCD_LINE8, "Future Designs, Inc");
        MSTimerDelay(3500);
        ClearLCD();
        DisplayLCD(LCD_LINE1, "Demo Modes:        ");
        DisplayLCD(LCD_LINE2, "-RST no key:       ");
        DisplayLCD(LCD_LINE3, "   GS Web Server   ");
        DisplayLCD(LCD_LINE4, "-RST + SW1:        ");
        DisplayLCD(LCD_LINE5, "   Exosite Cloud   ");
        DisplayLCD(LCD_LINE6, "-RST + SW2:        ");
        DisplayLCD(LCD_LINE7, "   AP Provisioning ");
        DisplayLCD(LCD_LINE8, "-RST + SW3: OTA    ");
        MSTimerDelay(3000);
        ClearLCD();
        
        LCDSelectFont(FONT_LARGE);
        if(Exosite_GetCIK(NULL))
        {
          AppMode = RUN_EXOSITE;
        }
    }
    
    DisplayLCD(LCD_LINE1, "Starting..."); 
    /*****************************************************************************/  
    SPI_Init(GAINSPAN_SPI_RATE);  
   /* Setup LCD SPI channel for Chip Select P10, active low, active per byte  */
    SPI_ChannelSetup(GAINSPAN_SPI_CHANNEL, false, true);
    GainSpan_SPI_Start();

    PM15 &= ~(1 << 2);
    P15 &= ~(1 << 2);
    
    if(AppMode == PROGRAM_MODE) {
        App_ProgramMode();
    }
    else if (AppMode == RUN_EXOSITE)
    {          
        DisplayLCD(LCD_LINE1, " CLOUD DEMO ");
        Temperature_Init();
        Potentiometer_Init();  
        App_Exosite();
    }
    else if(AppMode == RUN_PROVISIONING)
    {
      App_WebProvisioning();
    }
     else if(AppMode == RUN_OVER_AIR_DOWNLOAD)
    {
       App_OverTheAirProgrammingPushMetheod();
    }
    else if (AppMode == EXOSITE_ERASE)
    {
       ClearLCD();
       LCDSelectFont(FONT_SMALL);
       DisplayLCD(LCD_LINE3, "EEPROM ERASING ... ");
       MSTimerDelay(2000);
       Exosite_Init("renesas", "rl78g14", IF_WIFI, 1);
       DisplayLCD(LCD_LINE3, "                   ");
       DisplayLCD(LCD_LINE4, "Please reset device");
       while(1);
    }
    else{
        UART0_Start(GAINSPAN_CONSOLE_BAUD);
       // UART2_Start(GAINSPAN_UART_BAUD);
 
        Temperature_Init();
        Potentiometer_Init();
    
       // sprintf(LCDString, "RDK Demo %s", VERSION_TEXT);
       // DisplayLCD(LCD_LINE1, (const uint8_t *)LCDString);
   
        /* Before doing any tests or apps, startup the module */
        /* and nonvolatile stettings */
        App_Startup();
        // Now connect to the system
        //App_Connect(&G_nvsettings.webprov);
     
       //  App_PassThroughSPI();
         
         /******************Start Processing Sensor data******************/
         
         uint32_t start = MSTimerGet();  uint8_t c;
         Accelerometer_Init();
         while(1) 
         { 
          // if (GainSpan_SPI_ReceiveByte(GAINSPAN_SPI_CHANNEL, &c)) 
           if(App_Read(&c, 1, 0)) 
             AtLibGs_ReceiveDataProcess(c);
                   
        /* Timeout? */
           if (MSTimerDelta(start) >= 100)     // every 100 ms, read sensor data
           {  
              led_task();
              switch(state)
              {              
                case UPDATE_TEMPERATURE:         
                // Temperature sensor reading
                  temp = Temperature_Get();
#if 0                 
                   // Get the temperature and show it on the LCD
                  temp_char[0] = (int16_t)temp / 16;
                  temp_char[1] = (int16_t)((temp & 0x000F) * 10) / 16;
#endif 
                  temp_char[1] = (temp & 0xFF00)>>8;
                  temp_char[0] = temp & 0xFF;
                  
                  ftemp = *(uint16_t *)temp_char;
                  
                  gTemp_F = ((ftemp/5)*9)/128 + 22;
              
                  // Display the contents of lcd_buffer onto the debug LCD 
                  //sprintf((char *)LCDString, "TEMP: %d.%d C", temp_char[0], temp_char[1]);
                  sprintf((char *)LCDString, "TEMP: %.1fF", gTemp_F);
                  DisplayLCD(LCD_LINE6, (const uint8_t *)LCDString);  
                  state = UPDATE_LIGHT;
                break;
                
                case UPDATE_LIGHT:
                 // Light sensor reading
                  gAmbientLight = LightSensor_Get();
                    // Display the contents of lcd_buffer onto the debug LCD 
                  sprintf((char *)LCDString, "Light: %d ", gAmbientLight);
                  DisplayLCD(LCD_LINE7, (const uint8_t *)LCDString);
                  state = UPDATE_ACCELEROMETER;
                break;
                
                case UPDATE_ACCELEROMETER: 
                 // 3-axis accelerometer reading
                  Accelerometer_Get();
                  sprintf((char *)LCDString, "x%2d y%2d z%2d", gAccData[0], gAccData[1], gAccData[2]);
                  DisplayLCD(LCD_LINE8, (const uint8_t *)LCDString); 
                  state = UPDATE_TEMPERATURE;
                break;
              }
              start = MSTimerGet();
           }
         }          
    }    
Ejemplo n.º 13
0
/*---------------------------------------------------------------------------*/
void AppTCPSetIPMenu(ATLIBGS_NetworkStatus *pNetStatus)
{
    uint8_t ipString[13] = "    001     ";
    uint8_t ipAddressStr[15];
    uint8_t ipByte;
    uint8_t ipNums[3] = {0, 0, 1};
    uint8_t placeSel = 0;
    uint8_t blink = 0;
    
    // Build string to display for first three IP bytes (etc. "192.168.0.")
    sprintf((char*)ipAddressStr, "%d.%d.%d.",
            pNetStatus->addr.ipv4[0],
            pNetStatus->addr.ipv4[1],
            pNetStatus->addr.ipv4[2]);
    
    // Make sure SW2 has been released from AppMenu
    while(Switch2IsPressed())
        {}
    
    // Get previous fourth IP byte from NVsettings and format it into ipNums array
    ipByte = G_nvsettings.webprov.tcpIPClientHostIP;
    ipNums[0] = (ipByte/100);
    ipNums[1] = (ipByte%100)/10;
    ipNums[2] = (ipByte%10);
    
    // Display Remote IP Settings Menu
    DisplayLCD(LCD_LINE3, "Remote IP:  ");
    DisplayLCD(LCD_LINE4, ipAddressStr);
    DisplayLCD(LCD_LINE6, "SW1: Add 1  ");
    DisplayLCD(LCD_LINE7, "SW2: Next # ");
    DisplayLCD(LCD_LINE8, "SW3: Accept ");
    
    while(1)
    {
        // Update IP string based on ipNums
        ipString[4] = ipNums[0]+48;
        ipString[5] = ipNums[1]+48;
        ipString[6] = ipNums[2]+48;
        
        // Monitor Switches
        if(Switch1IsPressed()){
            // SW1 is pressed, increment the selected digit.
            ipNums[placeSel]++;
            if(ipNums[0]>2)
                ipNums[0] = 0;
            if(ipNums[1]>9)
                ipNums[1] = 0;
            if(ipNums[2]>9)
                ipNums[2] = 0;
            if(ipNums[0] == 2){
                if(ipNums[1] > 5)
                    ipNums[1] = 0;
                if((ipNums[1] == 5) && (ipNums[2] > 5))
                    ipNums[2] = 0;
            }
            while(Switch1IsPressed())
                {}
        }
        else if(Switch2IsPressed()){
            // SW2 is pressed, change the selected digit.
            placeSel++;
            if(placeSel > 2)
                placeSel = 0;
            while(Switch2IsPressed())
                {}
        }
        else if(Switch3IsPressed()){
            // SW3 is pressed. We're done, break out of loop.
            break;
        }
        
        if(blink > 5){
            
            ipString[placeSel+4] = ' ';
            if(blink > 10)
              blink = 0;
        }
        
        DisplayLCD(LCD_LINE5, ipString);
        MSTimerDelay(50);
        
        blink++;
    }
    
    // Clear menu and display ip address.
    DisplayLCD(LCD_LINE3, "");
    DisplayLCD(LCD_LINE4, "");
    DisplayLCD(LCD_LINE5, ipAddressStr);
    DisplayLCD(LCD_LINE6, ipString);
    DisplayLCD(LCD_LINE7, "");
    DisplayLCD(LCD_LINE8, "");
    
    // Save remote ip (fourth byte)
    G_nvsettings.webprov.tcpIPClientHostIP = (ipNums[0]*100) + (ipNums[1]*10) + ipNums[2];
    NVSettingsSave(&G_nvsettings);
}
Ejemplo n.º 14
0
void App_WhiskerGW()
{
    char pubTopic[100];
    char pubMsg[250];
    unsigned char msgType;
    int counter=0;
    char cntStr[20];
    char commandBuffer[64];
    int commandBufferPointer=0;
    
    led_all_off();
    // Give the unit a little time to start up
    // (300 ms for GS1011 and 1000 ms for GS1500)
    MSTimerDelay(1000);

    NVSettingsLoad(&GNV_Setting);
    led_on(4);
    WIFI_init(1);  // Show MAC address and Version
    led_on(5);
    WIFI_Associate();
    led_on(6);
    DisplayLCD(LCD_LINE8, "Demo starting.");
    DisplayLCD(LCD_LINE3, (const uint8_t *)WifiMAC);
    
    
    
    // UART
    if(spiUartInitialize()!=0)
    {
        DisplayLCD(LCD_LINE7, "!! SPIUART_ERROR !!");
        while(1)
        {
              led_all_on();
              MSTimerDelay(250);
              led_all_off();
              MSTimerDelay(250);
        }
    }
    
    while (1) 
    {
        // Do we need to connect to the AP?
        if (!AtLibGs_IsNodeAssociated())
        {
            led_off(6);
            WIFI_Associate();
            led_on(6);
        }
        else
        {    
            if(mqttConnected==0)
                App_ConnectMqtt();
            int charCount = spiUartRxBytesAvailable();
            while(charCount>0)
            {
                commandBuffer[commandBufferPointer++] = spiUartGetByte();
                charCount--;
                if(charCount==0)
                  commandBufferPointer=0;
                if(commandBufferPointer>4)
                {
                  if(strstr(commandBuffer,"RMPU")==commandBuffer)
                  {
                    if(commandBufferPointer>24)
                    {
                      // process response
                      char macStr[9];
                      char lenStr[5];
                      memcpy(macStr,&commandBuffer[6],8);
                      macStr[8] = 0;
                      memcpy(lenStr,&commandBuffer[4],2);
                      lenStr[2]=0;
                      int len = (int)strtol(lenStr,0,16);
                      unsigned long mac = strtoul(macStr,NULL,16);
                      WhiskerModule *wm = findModule(mac);
                      if(wm!=0)
                      {
                          if(commandBufferPointer>len+16)
                          {
                            char rssiStr[3];
                            memcpy(rssiStr,&commandBuffer[commandBufferPointer-3],2);
                            rssiStr[2]=0;
                            int rssi = (int)strtol(rssiStr,0,16);
                            if((rssi & 0x80) == 0x80)
                              rssi-=256;
                            int puMsgPointer=14;
                            mqtt_initJsonMsg(pubMsg);
                            mqtt_addStringValToMsg("Name",wm->Name,pubMsg,0);
                            mqtt_addStringValToMsg("Mac",macStr,pubMsg,1);
                            char rstr[8];
                            sprintf(rstr,"%d dbm",rssi);
                            mqtt_addStringValToMsg("Rssi",rstr,pubMsg,1);
                            sprintf(pubMsg+strlen(pubMsg),",\"Values\":{");
                            puMsgPointer=14;
                            int comma=0;
                            while(puMsgPointer < (commandBufferPointer-3))
                            {
                              char cidStr[3];
                              memcpy(cidStr,&commandBuffer[puMsgPointer],2);
                              puMsgPointer+=2;
                              cidStr[2]=0;
                              unsigned char cid=(unsigned char)strtol(cidStr,0,16);
                              unsigned char channel = cid & 0x1f;
                              char valStr[9];
                              long valInt;
                              switch(cid)
                              {
                              case 0x21:
                                //digital input
                                memcpy(valStr,&commandBuffer[puMsgPointer],2);
                                valStr[2]=0;
                                puMsgPointer+=2;
                                valInt = (int)strtol(valStr,0,16);
                                if(valInt)
                                    mqtt_addStringValToMsg("DIN1","True",pubMsg,comma);
                                else
                                    mqtt_addStringValToMsg("DIN1","False",pubMsg,comma);
                                break;
                              case 0x22:
                                //digital input
                                memcpy(valStr,&commandBuffer[puMsgPointer],2);
                                valStr[2]=0;
                                puMsgPointer+=2;
                                valInt = (int)strtol(valStr,0,16);
                                if(valInt)
                                    mqtt_addStringValToMsg("DIN2","True",pubMsg,comma);
                                else
                                    mqtt_addStringValToMsg("DIN2","False",pubMsg,comma);
                                break;                              
                              case 0x43:
                                //battery analog in
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("Battery",valInt,pubMsg,comma);
                                break;          
                              case 0x44:
                                //battery analog in
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("Temperature",valInt,pubMsg,comma);
                                break;          
                              case 0x45:
                                //battery analog in
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("RH",valInt,pubMsg,comma);
                                break;  
                              case 0x5d:
                                //internal temperature
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("IntTemp",valInt,pubMsg,comma);
                                break;
                              case 0x57:                                
                                //air quality
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("AirQual",valInt,pubMsg,comma);
                                break;
                              case 0x58:
                                //air quality
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("AirQual",valInt,pubMsg,comma);
                                break;
                                
                              case 0x61:
                                // digital counter input
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("Count1",valInt,pubMsg,comma);
                                break;
                                
                              case 0x62:
                                // digital counter input
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("Count2",valInt,pubMsg,comma);
                                break;
                              }                              
                              comma=1;
                            }                            
                            sprintf(pubMsg+strlen(pubMsg),"}");
                            mqtt_finishJsonMsg(pubMsg);
                            sprintf(pubTopic, "%s/%s", WIO_DOMAIN, macStr);
                            int res=mqtt_publish(&broker, pubTopic, pubMsg,0)<0;
                            if(res<0)
                              mqttConnected=0;
                            led_on(8);
                            //spiUartResetFIFO();
                          }
                      }
                    }
                  }
                }
            }
            // Send data if
            RSSIReading();
            AtLibGs_WaitForTCPMessage(1000);
            led_off(7);
            led_off(8);
            if(G_receivedCount>0)
            {
                AtLibGs_ParseTCPData(G_received,G_receivedCount,&rxm);
                msgType = MQTTParseMessageType(rxm.message);
                switch(msgType)
                {
                case MQTT_MSG_SUBACK:
                  // todo: display subscription acknowledgement
                  break;
                case MQTT_MSG_PUBLISH:
                  App_MQTTMsgPublished();
                  break;
                case MQTT_MSG_PUBACK:
                  // todo: display publish acknowledgement
                  break;
                default:
                  break;
                }
            }
            counter++;
            sprintf(cntStr,"Counter=%d",counter);
            DisplayLCD(LCD_LINE6,cntStr);
            if(counter>30)
            {
                counter=0;
                sprintf(pubTopic, "%s/%s", WIO_DOMAIN, WifiMAC);
                mqtt_initJsonMsg(pubMsg);
                mqtt_addStringValToMsg("msg","status ok",pubMsg,0);
                mqtt_finishJsonMsg(pubMsg);
                int res1=mqtt_publish(&broker, pubTopic, pubMsg,0)<0;
                if(res1<0)
                    mqttConnected=0;
                led_on(7);
            }
        }       
    // Send data if END
    }
}
Ejemplo n.º 15
0
ATLIBGS_MSG_ID_E WIFI_init(int16_t showMessage)
{
  ATLIBGS_MSG_ID_E rxMsgId = ATLIBGS_MSG_ID_NONE;

 // Check the link
#ifdef HOST_APP_DEBUG_ENABLE
    ConsolePrintf("Checking link\r\n");
#endif

  AtLibGs_Init();
  // Wait for the banner
  MSTimerDelay(500);

  /* Send command to check */
  do {
    AtLibGs_FlushIncomingMessage();
    DisplayLCD(LCD_LINE4, "wl_check..  ");
    rxMsgId = AtLibGs_Check();
  } while (ATLIBGS_MSG_ID_OK != rxMsgId);
   
  do {   
       rxMsgId = AtLibGs_SetEcho(0);               // disable Echo
  }while (ATLIBGS_MSG_ID_OK != rxMsgId);
  
  do {                                               
       rxMsgId = AtLibGs_Version();                // check the GS version
    }while (ATLIBGS_MSG_ID_OK != rxMsgId);
#if 0  
  if(strstr((const char *)MRBuffer, "2.3."))       // still debug why receive 2 extra bytes: ESC S
  {
    G_Extra2B = 2;
  }
#endif
  
  do{  
       rxMsgId = AtLibGs_EnableRadio(1);                       // enable radio
  }while(rxMsgId != ATLIBGS_MSG_ID_OK);
  
  /* Get MAC Address & Show */
  rxMsgId = AtLibGs_GetMAC(WiFiMAC);    
  if (rxMsgId == ATLIBGS_MSG_ID_OK)
    AtLibGs_ParseGetMacResponse(WifiMAC);
  if (showMessage > 0) {   
    DisplayLCD(LCD_LINE3, (const uint8_t *)WifiMAC);
    MSTimerDelay(2000);
  }
  
  do {
    AtLibGs_FlushIncomingMessage();
    DisplayLCD(LCD_LINE4, "wl_disass.. ");
    rxMsgId = AtLibGs_DisAssoc();
  } while (ATLIBGS_MSG_ID_OK != rxMsgId);
    
    // Enable DHCP
  do { 
    DisplayLCD(LCD_LINE4, "wl_dhcpon.. ");
    rxMsgId = AtLibGs_DHCPSet(1);
  } while (ATLIBGS_MSG_ID_OK != rxMsgId);
 
  if(strlen(GNV_Setting.webprov.ssid) > 0)
  { 

    if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WEP)
    {
        do {
          DisplayLCD(LCD_LINE4, "wl_setwep.. ");
          rxMsgId = AtLibGs_SetWEP1((int8_t*)GNV_Setting.webprov.password);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId); 
        DisplayLCD(LCD_LINE4, "wl_wepset.. ");      
    }
    else if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WPA_PER)
    {
        do {
          DisplayLCD(LCD_LINE4, "wl_setpsk.. ");
          rxMsgId = AtLibGs_CalcNStorePSK(GNV_Setting.webprov.ssid, GNV_Setting.webprov.password);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId); 
        DisplayLCD(LCD_LINE4, "wl_pskset.. ");
    }
    else if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WPA_ENT)
    {
     /* Set AT+WAUTH=0 for WPA or WPA2  */
         do {
           DisplayLCD(LCD_LINE4, "       " );
           rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_NONE_WPA);
         } while (ATLIBGS_MSG_ID_OK != rxMsgId);
       /* Security Configuration */
         do {
           DisplayLCD(LCD_LINE4, "wl_setsec.. ");
           rxMsgId = AtLibGs_SetSecurity(ATLIBGS_SMAUTO);
         } while (ATLIBGS_MSG_ID_OK != rxMsgId);  
     }
   }
   else
   {
#ifdef HOST_APP_SEC_WEP
        // Set AT+WAUTH=2 for WEP
        do {
          DisplayLCD(LCD_LINE4, "wl_wepauth.." );
          rxMsgId = AtLibGs_SetAuthentictionMode(2);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
        // Set WEP
        do {
          rxMsgId = AtLibGs_SetWEP1(HOST_APP_AP_SEC_WEP);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
          /* Security Configuration */
        do {
          rxMsgId = AtLibGs_SetSecurity(2);        // WEP
          } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif
    
#ifdef HOST_APP_SEC_PSK
        /* Store the PSK value. This call takes might take few seconds to return */
        do {
          DisplayLCD(LCD_LINE4, "wl_setpsk.. ");
          rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif

#ifdef HOST_APP_SEC_OPEN
        /* Store the PSK value. This call takes might take few seconds to return */
        do {
          DisplayLCD(LCD_LINE4, "wl_nosec..  " );
          rxMsgId = AtLibGs_SetAuthentictionMode(1);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif

#ifdef HOST_APP_WPA
        // Set AT+WAUTH=0 for WPA or WPA2
        do {
          DisplayLCD(LCD_LINE4, "wl_wpa..   " );
          rxMsgId = AtLibGs_SetAuthentictionMode(0);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
      
        /* Store the PSK value. This call takes might take few seconds to return */
        do {
          DisplayLCD(LCD_LINE4, "wl_setpsk.. ");
          rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);   
      
        /* Security Configuration */
        do {
          DisplayLCD(LCD_LINE4, "wl_wpa..    ");
          rxMsgId = AtLibGs_SetSecurity(4);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif

#ifdef HOST_APP_WPA2
        // Set AT+WAUTH=0 for WPA or WPA2
        do {
          DisplayLCD(LCD_LINE4, "wl_wpa2..   " );
          rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_NONE_WPA);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
          
        /* Store the PSK value. This call takes might take few seconds to return */
        do {
          DisplayLCD(LCD_LINE4, "wl_setpsk.. ");
          rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);   

        /* Security Configuration */
        do {
          DisplayLCD(LCD_LINE4, "wl_setwpa..  ");
          rxMsgId = AtLibGs_SetSecurity(ATLIBGS_SMWPA2PSK);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif
      }
  
  return rxMsgId;
}
Ejemplo n.º 16
0
// Gets the Novatel modem in a known reset state
// Does not return until modem is responsive.
void NovatelModemInit()
{
    uint8_t exit = 0;

    // shut echo off
    AtModem_Write((unsigned char *)"ate0\r", 5);

    MSTimerDelay(500);
    // clear ate0 response
    UART0_ResetBuffers();

    //flushUart0RxBuffer(1000);
    // while modem is not responding to 'at'
    while ((AT_REPLY_OK != AtModem_OnCheck()) && (exit != 1))
    {
        // try to get modem out of data mode '+++'
        AtModem_Write("+++\r", 4);

        // Let's also try and power the modem on
        ADPC = 0x09U;   //DEFAULT is all AINx pins are Analog, change 8-15 to
                        // digital
        P15 &= ~(1<<MODEM_PHON_PIN); //SET LOW
        PM15 &= ~(1<<MODEM_PHON_PIN); //SET AS OUTPUT
        P15 |= (1<<MODEM_PHON_PIN);  //SET HIGH
        MSTimerDelay(500); //pulse
        P15 &= ~(1<<MODEM_PHON_PIN); //SET LOW
        PM15 |= (1<<MODEM_PHON_PIN); //SET AS INPUT

        // need to wait ~30 seconds for the disconnect to occurr.
        MSTimerDelay(30000);

        // shut echo off
        AtModem_Write((unsigned char *)"ate0\r", 5);

        MSTimerDelay(1000);

        // clear ate0 response
        UART0_ResetBuffers();

        if(AT_REPLY_OK != AtModem_OnCheck())
        {
            // If still no response,
            // power off modem through gpio

            P8 &= ~(1<<POWER_OFF_PIN); //SET LOW
            PM8 &= ~(1<<POWER_OFF_PIN); //SET AS OUTPUT
            P8 |= (1<<POWER_OFF_PIN);  //SET HIGH
            MSTimerDelay(500); //pulse
            P8 &= ~(1<<POWER_OFF_PIN); //SET LOW


            // wait 1 seconds
            MSTimerDelay(1000);

            // Let's also try and power the modem on
            ADPC = 0x09U;   //DEFAULT is all AINx pins are Analog, change 8-15
                            // to digital
            P15 &= ~(1<<MODEM_PHON_PIN); //SET LOW
            PM15 &= ~(1<<MODEM_PHON_PIN); //SET AS OUTPUT
            P15 |= (1<<MODEM_PHON_PIN);  //SET HIGH
            MSTimerDelay(500); //pulse
            P15 &= ~(1<<MODEM_PHON_PIN); //SET LOW
            PM15 |= (1<<MODEM_PHON_PIN); //SET AS INPUT

            MSTimerDelay(5000);

            // shut echo off
            AtModem_Write((unsigned char *)"ate0\r", 5);


            MSTimerDelay(1000);

            UART0_ResetBuffers();
        }
        else
        {
            // successful reply, exit out
            exit = 1;
        }
        // start over
    }
    // response is valid, modem is in command mode and availble
}
Ejemplo n.º 17
0
int main(void)
{
    AppMode_T AppMode;
    WDTIMK = 0U;	/* enable INTWDTI interrupt */
   
    
    HardwareSetup();
    MSTimerInit();
    
    /************************initializa LCD module********************************/
    SPI2_Init();
    InitialiseLCD();
    led_init();
    
    /* Default app mode */
    AppMode = RUN_EXOSITE;

    /* Determine if SW1 & SW3 is pressed at power up to enter nvm erase mode */
    if (Switch1IsPressed() && Switch3IsPressed())
    {

        DisplayLCD(LCD_LINE1, "*NVM ERASED*");
        DisplayLCD(LCD_LINE2, "Reboot      ");
        DisplayLCD(LCD_LINE3, "  Device    ");
        while(1)
        {
            // wait here
        }
    }
    else if(Switch1IsPressed())
    {
        AppMode = ACTIVATE_MODEM;
    }
    
    DisplayLCD(LCD_LINE1, "Initializing");
    DisplayLCD(LCD_LINE2, "  Novatel   ");
    DisplayLCD(LCD_LINE3, "   Modem    ");
        
    // reset the modem
    P8 &= ~(1<<POWER_OFF_PIN); //SET LOW
    PM8 &= ~(1<<POWER_OFF_PIN); //SET AS OUTPUT
    P8 |= (1<<POWER_OFF_PIN);  //SET HIGH
    MSTimerDelay(500); //pulse
    P8 &= ~(1<<POWER_OFF_PIN); //SET LOW


    // pulse the phone pin as well
    ADPC = 0x09U;   //DEFAULT is all AINx pins are Analog, change 8-15
                    // to digital
    P15 &= ~(1<<MODEM_PHON_PIN); //SET LOW
    PM15 &= ~(1<<MODEM_PHON_PIN); //SET AS OUTPUT
    P15 |= (1<<MODEM_PHON_PIN);  //SET HIGH
    MSTimerDelay(500); //pulse
    P15 &= ~(1<<MODEM_PHON_PIN); //SET LOW
    PM15 |= (1<<MODEM_PHON_PIN); //SET AS INPUT
    
    // wait for modem to power up
    DisplayLCD(LCD_LINE1, "Waiting for ");
    DisplayLCD(LCD_LINE2, "  Modem to  ");
    DisplayLCD(LCD_LINE3, " Initialize ");
    DisplayLCD(LCD_LINE4, "      3     ");
    MSTimerDelay(1000);
    DisplayLCD(LCD_LINE4, "      2     ");
    MSTimerDelay(1000);
    DisplayLCD(LCD_LINE4, "      1     ");
    MSTimerDelay(1000);
    DisplayLCD(LCD_LINE4, "");
    // Start UART0 for Novatel modem
    UART0_Start(NOVATEL_UART_BAUD_RATE);

   

    /* If the CIK is exist, auto into the Exosite mode */
    NVSettingsLoad(&GNV_Setting);
    
    
   

    if(AppMode == RUN_EXOSITE)
    {
        LCDDisplayLogo();
        LCDSelectFont(FONT_SMALL);
        DisplayLCD(LCD_LINE3, "RL78G14 RDK    V2.0");
        DisplayLCD(LCD_LINE4, "   Cellular        ");
        DisplayLCD(LCD_LINE5, "     demos by:     ");
        DisplayLCD(LCD_LINE6, "Novatel            ");
        DisplayLCD(LCD_LINE7, "Exosite            ");
        MSTimerDelay(3500);
        ClearLCD();
        DisplayLCD(LCD_LINE1, "Demo Modes:        ");
        DisplayLCD(LCD_LINE2, "-RST no key:       ");
        DisplayLCD(LCD_LINE3, "   ExoSite App     ");
        DisplayLCD(LCD_LINE4, "-RST + SW1 & SW3:  ");
        DisplayLCD(LCD_LINE5, "   Reset NVM       ");
        DisplayLCD(LCD_LINE6, "-RST + SW1:        ");
        DisplayLCD(LCD_LINE7, "   Cell Activate   ");
        MSTimerDelay(3000);
        ClearLCD();

        LCDSelectFont(FONT_LARGE);
        DisplayLCD(LCD_LINE1, "Exosite DEMO");
        
        Temperature_Init();
        Potentiometer_Init();
        
        App_Exosite();
    }
    else if (AppMode == ACTIVATE_MODEM)
    {
        ATModem_CellActivate();
    }

   

    return 0;
}
Ejemplo n.º 18
0
int ATModem_CellActivate(void)
{
    // disable loopback on modem
    AtModem_Write((unsigned char *)"ate\r", 4);
    // eat up responses
    AtModem_response_check(1000, "ate", "\r");
    AtModem_response_check(1000, "OK", "\r\n");
    
    
    AtModem_Write((unsigned char *)"at$OTASP?\r", 10);
    if(AtModem_response_check(1000, "$OTASP: 1, 0", "\r\n")==AT_REPLY_OK)
    {
        DisplayLCD(LCD_LINE1, "Device      ");
        DisplayLCD(LCD_LINE2, "Appears     ");
        DisplayLCD(LCD_LINE3, "Activated.  ");
        DisplayLCD(LCD_LINE4, "            ");
        DisplayLCD(LCD_LINE5, "Trying to   ");
        DisplayLCD(LCD_LINE6, "activate    ");
        DisplayLCD(LCD_LINE7, "again       ");
        MSTimerDelay(4000);
    }
    DisplayLCD(LCD_LINE1, "Sending     ");
    DisplayLCD(LCD_LINE2, "activation  ");
    DisplayLCD(LCD_LINE3, "cmd to VZW  ");
    DisplayLCD(LCD_LINE4, "network.    ");
    DisplayLCD(LCD_LINE5, "");
    DisplayLCD(LCD_LINE6, "");
    DisplayLCD(LCD_LINE7, "");
    AtModem_Write((unsigned char *)"at+cdv*22899\r", 13);
    MSTimerDelay(4000);
    
    DisplayLCD(LCD_LINE1, "Activation  ");
    DisplayLCD(LCD_LINE2, "cmd sent.   ");
    DisplayLCD(LCD_LINE3, "Awaiting    ");
    DisplayLCD(LCD_LINE4, "Response    ");
    
    uint8_t progressInd = 0;
    while(1)
    {
        if(AtModem_response_check(1000, "$OTASP: 8", "\r\n")==AT_REPLY_OK)
        {
            DisplayLCD(LCD_LINE1, "Network     ");
            DisplayLCD(LCD_LINE2, "Activation  ");
            DisplayLCD(LCD_LINE3, "Successful. ");
            DisplayLCD(LCD_LINE4, "            ");
            DisplayLCD(LCD_LINE5, "Restart     ");
            DisplayLCD(LCD_LINE6, "the RL78G14 ");
            DisplayLCD(LCD_LINE7, "dev board   ");
            
            while(1)
            {
            }
        }
        else
        {
            // toggle the '.' to show user that we're doing something.
            if (progressInd)
            {
                DisplayLCD(LCD_LINE3, "Awaiting    ");
                DisplayLCD(LCD_LINE4, "Response.   ");
            }
            else
            {
                DisplayLCD(LCD_LINE3, "Awaiting    ");
                DisplayLCD(LCD_LINE4, "Response    ");
            }
            // toggle indicator
            progressInd ^= 1;
        }
        MSTimerDelay(2000);
    }
}
Ejemplo n.º 19
0
/*****************************************************************************
*
*  App_Exosite
*
*  \param  None
*
*  \return None
*
*  \brief  Takse a reading of temperature and potentiometer and sends to
*          Exosite cloud using a TCP connection
*
*****************************************************************************/
void App_Exosite(void)
{
  int loop_time = 1000;
  unsigned char loopCount = 0;
  int wifi_init = 0;
  int badcik = 1;
  static const uint8_t geoCert[] = { 0x30, 0x82, 0x03, 0x54, 0x30, 0x82, 0x02, 0x3c, 0xa0, 0x03,
                                     0x02, 0x01, 0x02, 0x02, 0x03, 0x02, 0x34, 0x56, 0x30, 0x0d,
                                     0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
                                     0x05, 0x05, 0x00, 0x30, 0x42, 0x31, 0x0b, 0x30, 0x09, 0x06,
                                     0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x16,
                                     0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0d, 0x47,
                                     0x65, 0x6f, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x49, 0x6e,
                                     0x63, 0x2e, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04,
                                     0x03, 0x13, 0x12, 0x47, 0x65, 0x6f, 0x54, 0x72, 0x75, 0x73,
                                     0x74, 0x20, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x20, 0x43,
                                     0x41, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x32, 0x30, 0x35, 0x32,
                                     0x31, 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x17, 0x0d,
                                     0x32, 0x32, 0x30, 0x35, 0x32, 0x31, 0x30, 0x34, 0x30, 0x30,
                                     0x30, 0x30, 0x5a, 0x30, 0x42, 0x31, 0x0b, 0x30, 0x09, 0x06,
                                     0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x16,
                                     0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0d, 0x47,
                                     0x65, 0x6f, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x49, 0x6e,
                                     0x63, 0x2e, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04,
                                     0x03, 0x13, 0x12, 0x47, 0x65, 0x6f, 0x54, 0x72, 0x75, 0x73,
                                     0x74, 0x20, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x20, 0x43,
                                     0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a,
                                     0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00,
                                     0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02,
                                     0x82, 0x01, 0x01, 0x00, 0xda, 0xcc, 0x18, 0x63, 0x30, 0xfd,
                                     0xf4, 0x17, 0x23, 0x1a, 0x56, 0x7e, 0x5b, 0xdf, 0x3c, 0x6c,
                                     0x38, 0xe4, 0x71, 0xb7, 0x78, 0x91, 0xd4, 0xbc, 0xa1, 0xd8,
                                     0x4c, 0xf8, 0xa8, 0x43, 0xb6, 0x03, 0xe9, 0x4d, 0x21, 0x07,
                                     0x08, 0x88, 0xda, 0x58, 0x2f, 0x66, 0x39, 0x29, 0xbd, 0x05,
                                     0x78, 0x8b, 0x9d, 0x38, 0xe8, 0x05, 0xb7, 0x6a, 0x7e, 0x71,
                                     0xa4, 0xe6, 0xc4, 0x60, 0xa6, 0xb0, 0xef, 0x80, 0xe4, 0x89,
                                     0x28, 0x0f, 0x9e, 0x25, 0xd6, 0xed, 0x83, 0xf3, 0xad, 0xa6,
                                     0x91, 0xc7, 0x98, 0xc9, 0x42, 0x18, 0x35, 0x14, 0x9d, 0xad,
                                     0x98, 0x46, 0x92, 0x2e, 0x4f, 0xca, 0xf1, 0x87, 0x43, 0xc1,
                                     0x16, 0x95, 0x57, 0x2d, 0x50, 0xef, 0x89, 0x2d, 0x80, 0x7a,
                                     0x57, 0xad, 0xf2, 0xee, 0x5f, 0x6b, 0xd2, 0x00, 0x8d, 0xb9,
                                     0x14, 0xf8, 0x14, 0x15, 0x35, 0xd9, 0xc0, 0x46, 0xa3, 0x7b,
                                     0x72, 0xc8, 0x91, 0xbf, 0xc9, 0x55, 0x2b, 0xcd, 0xd0, 0x97,
                                     0x3e, 0x9c, 0x26, 0x64, 0xcc, 0xdf, 0xce, 0x83, 0x19, 0x71,
                                     0xca, 0x4e, 0xe6, 0xd4, 0xd5, 0x7b, 0xa9, 0x19, 0xcd, 0x55,
                                     0xde, 0xc8, 0xec, 0xd2, 0x5e, 0x38, 0x53, 0xe5, 0x5c, 0x4f,
                                     0x8c, 0x2d, 0xfe, 0x50, 0x23, 0x36, 0xfc, 0x66, 0xe6, 0xcb,
                                     0x8e, 0xa4, 0x39, 0x19, 0x00, 0xb7, 0x95, 0x02, 0x39, 0x91,
                                     0x0b, 0x0e, 0xfe, 0x38, 0x2e, 0xd1, 0x1d, 0x05, 0x9a, 0xf6,
                                     0x4d, 0x3e, 0x6f, 0x0f, 0x07, 0x1d, 0xaf, 0x2c, 0x1e, 0x8f,
                                     0x60, 0x39, 0xe2, 0xfa, 0x36, 0x53, 0x13, 0x39, 0xd4, 0x5e,
                                     0x26, 0x2b, 0xdb, 0x3d, 0xa8, 0x14, 0xbd, 0x32, 0xeb, 0x18,
                                     0x03, 0x28, 0x52, 0x04, 0x71, 0xe5, 0xab, 0x33, 0x3d, 0xe1,
                                     0x38, 0xbb, 0x07, 0x36, 0x84, 0x62, 0x9c, 0x79, 0xea, 0x16,
                                     0x30, 0xf4, 0x5f, 0xc0, 0x2b, 0xe8, 0x71, 0x6b, 0xe4, 0xf9,
                                     0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x53, 0x30, 0x51, 0x30,
                                     0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04,
                                     0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03,
                                     0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xc0, 0x7a, 0x98,
                                     0x68, 0x8d, 0x89, 0xfb, 0xab, 0x05, 0x64, 0x0c, 0x11, 0x7d,
                                     0xaa, 0x7d, 0x65, 0xb8, 0xca, 0xcc, 0x4e, 0x30, 0x1f, 0x06,
                                     0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14,
                                     0xc0, 0x7a, 0x98, 0x68, 0x8d, 0x89, 0xfb, 0xab, 0x05, 0x64,
                                     0x0c, 0x11, 0x7d, 0xaa, 0x7d, 0x65, 0xb8, 0xca, 0xcc, 0x4e,
                                     0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
                                     0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00,
                                     0x35, 0xe3, 0x29, 0x6a, 0xe5, 0x2f, 0x5d, 0x54, 0x8e, 0x29,
                                     0x50, 0x94, 0x9f, 0x99, 0x1a, 0x14, 0xe4, 0x8f, 0x78, 0x2a,
                                     0x62, 0x94, 0xa2, 0x27, 0x67, 0x9e, 0xd0, 0xcf, 0x1a, 0x5e,
                                     0x47, 0xe9, 0xc1, 0xb2, 0xa4, 0xcf, 0xdd, 0x41, 0x1a, 0x05,
                                     0x4e, 0x9b, 0x4b, 0xee, 0x4a, 0x6f, 0x55, 0x52, 0xb3, 0x24,
                                     0xa1, 0x37, 0x0a, 0xeb, 0x64, 0x76, 0x2a, 0x2e, 0x2c, 0xf3,
                                     0xfd, 0x3b, 0x75, 0x90, 0xbf, 0xfa, 0x71, 0xd8, 0xc7, 0x3d,
                                     0x37, 0xd2, 0xb5, 0x05, 0x95, 0x62, 0xb9, 0xa6, 0xde, 0x89,
                                     0x3d, 0x36, 0x7b, 0x38, 0x77, 0x48, 0x97, 0xac, 0xa6, 0x20,
                                     0x8f, 0x2e, 0xa6, 0xc9, 0x0c, 0xc2, 0xb2, 0x99, 0x45, 0x00,
                                     0xc7, 0xce, 0x11, 0x51, 0x22, 0x22, 0xe0, 0xa5, 0xea, 0xb6,
                                     0x15, 0x48, 0x09, 0x64, 0xea, 0x5e, 0x4f, 0x74, 0xf7, 0x05,
                                     0x3e, 0xc7, 0x8a, 0x52, 0x0c, 0xdb, 0x15, 0xb4, 0xbd, 0x6d,
                                     0x9b, 0xe5, 0xc6, 0xb1, 0x54, 0x68, 0xa9, 0xe3, 0x69, 0x90,
                                     0xb6, 0x9a, 0xa5, 0x0f, 0xb8, 0xb9, 0x3f, 0x20, 0x7d, 0xae,
                                     0x4a, 0xb5, 0xb8, 0x9c, 0xe4, 0x1d, 0xb6, 0xab, 0xe6, 0x94,
                                     0xa5, 0xc1, 0xc7, 0x83, 0xad, 0xdb, 0xf5, 0x27, 0x87, 0x0e,
                                     0x04, 0x6c, 0xd5, 0xff, 0xdd, 0xa0, 0x5d, 0xed, 0x87, 0x52,
                                     0xb7, 0x2b, 0x15, 0x02, 0xae, 0x39, 0xa6, 0x6a, 0x74, 0xe9,
                                     0xda, 0xc4, 0xe7, 0xbc, 0x4d, 0x34, 0x1e, 0xa9, 0x5c, 0x4d,
                                     0x33, 0x5f, 0x92, 0x09, 0x2f, 0x88, 0x66, 0x5d, 0x77, 0x97,
                                     0xc7, 0x1d, 0x76, 0x13, 0xa9, 0xd5, 0xe5, 0xf1, 0x16, 0x09,
                                     0x11, 0x35, 0xd5, 0xac, 0xdb, 0x24, 0x71, 0x70, 0x2c, 0x98,
                                     0x56, 0x0b, 0xd9, 0x17, 0xb4, 0xd1, 0xe3, 0x51, 0x2b, 0x5e,
                                     0x75, 0xe8, 0xd5, 0xd0, 0xdc, 0x4f, 0x34, 0xed, 0xc2, 0x05,
                                     0x66, 0x80, 0xa1, 0xcb, 0xe6, 0x33};

  bool isTimeSync = false;

  // wait 1 sec for LCD messages display
  MSTimerDelay(1000);
  NVSettingsLoad(&GNV_Setting);

#ifdef SHOW_VERSION
  DisplayLCD(LCD_LINE2, (const uint8_t *)ExositeAppVersion);
#endif

  // must initialize one time for mac address prepare..
  WIFI_init(1);
  if (!Exosite_Init("renesas", "rl78g14", IF_WIFI, 0))
  {
    show_status();
    while(1);
  }

  while(AtLibGs_AddCert(  EXOSITE_CA_NAME,
                          true,
                          geoCert,
                          sizeof(geoCert)) != ATLIBGS_MSG_ID_OK)
  {
    DisplayLCD(LCD_LINE4, "Add CA FAILED");
  }

  while (1)
  {
    if (!checkWiFiConnected(wifi_init))
    {
      wifi_init = 0;
    }
    else
    {
      if(!isTimeSync)
      {
        if(Exosite_SyncTime() == 0)
          isTimeSync = true;
      }
      
      UpdateReadings();

      int code = Exosite_StatusCode();
      if (code == EXO_STATUS_OK)
      {
        badcik = 0;
        wifi_init = 1;

        ReadCloudCommands();

        if (loopCount++ >= WRITE_INTERVAL) 
        {
          // POST the Sensor and templature values
          ReportReadings();
          loopCount = 0;
        }
        loop_time = 500; //delay 0.5 seconds before next turn..
      }
      else if (1 == badcik || EXO_STATUS_BAD_CIK == code || EXO_STATUS_NOAUTH == code)
      {
        DisplayLCD(LCD_LINE6, "  Exosite  ");
        DisplayLCD(LCD_LINE7, " Connecting");
        DisplayLCD(LCD_LINE8, "           ");

        if (!Exosite_Activate())
        {
          badcik = 1;
          loop_time = 3000; // delay 3 seconds
        }
        else
        {
          DisplayLCD(LCD_LINE7, " Connected ");
        }
      }
      show_status();
    }

    MSTimerDelay(loop_time);  //delay before looping again
  }
}
Ejemplo n.º 20
0
/*---------------------------------------------------------------------------*
 * Routine:  App_WebProvisioning
 *---------------------------------------------------------------------------*
 * Description:
 *      Put the unit into web provisioning mode and wait for the user to
 *      connect with a web browser, change the settings, and click Save.
 *      The settings will then be parsed by the AtLibGs library and
 *      get saved into the nv settings.
 * Inputs:
 *      void
 * Outputs:
 *      void
 *---------------------------------------------------------------------------*/
void App_WebProvisioning(void)
{
    ATLIBGS_MSG_ID_E r;

    /* At power up, load up the default settings */
    if(NVSettingsLoad(&G_nvsettings))
       NVSettingsSave(&G_nvsettings);
    
    App_InitModule();
    while(1)
    {
       r = AtLibGs_GetMAC(WiFiMAC);
       if(r != ATLIBGS_MSG_ID_OK) 
       {
          DisplayLCD(LCD_LINE6, "Get MAC Failed!");
          MSTimerDelay(2000);
          continue;
       } 
       break;
    }; 
    
    if(r == ATLIBGS_MSG_ID_OK)
      AtLibGs_ParseGetMacResponse(WiFiMACStr);    
    strcpy(str_config_ssid, (char const*)ATLIBGS_ADK_SSID); 
    strcat(str_config_ssid, &WiFiMACStr[6]);                     // concatenate last 6 digis of MAC as SSID  
    
    App_StartupLimitedAP(str_config_ssid);
    
    /* Before going into web provisioning, provide DNS to give a link. */
    /* The user can then go to http://webprov.gainspan.com/gsclient.html to get */
    /* access to the web provisioning screen. */
    while (1) {
#if 0
        AtLibGs_DisableDNSServer();
        r = AtLibGs_EnableDNSServer("webprov.gainspan.com");
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad DNS!");
            MSTimerDelay(2000);
            continue;
        }
#endif
        r = AtLibGs_WebProv(",", ",");
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad WebProv!");
            MSTimerDelay(2000);
            continue;
        }
        break;
    }
    DisplayLCD(LCD_LINE6, "WebProv ON");
    DisplayLCD(LCD_LINE7, (const uint8_t *) "192.168.240.");
    DisplayLCD(LCD_LINE8, (const uint8_t *) "1/prov.html");
#if 0
    do {
        DisplayLCD(LCD_LINE7, "IP: ???.???.");
        DisplayLCD(LCD_LINE8, "    ???.???");
        r = AtLibGs_GetNetworkStatus(&network_status);
    } while (ATLIBGS_MSG_ID_OK != r);

    sprintf(text, "IP: " _F8_ "." _F8_ ".",
            network_status.addr.ipv4[0], network_status.addr.ipv4[1]);
    DisplayLCD(LCD_LINE7, (uint8_t *)text);
    sprintf(text, "    " _F8_ "." _F8_, network_status.addr.ipv4[2],
            network_status.addr.ipv4[3]);
    DisplayLCD(LCD_LINE8, (uint8_t *)text);
#endif
#ifdef ATLIBGS_DEBUG_ENABLE
    ConsolePrintf("Web Provisioning ON\n");
#endif

    /* Now wait for a list of responses until we get a blank line */
#ifdef ATLIBGS_DEBUG_ENABLE
    ConsolePrintf("Waiting for web provisioning response...\n");
#endif
    AtLibGs_GetWebProvSettings(&G_nvsettings.webprov, 0);

    /* Save the above settings */
    NVSettingsSave(&G_nvsettings);
#ifdef ATLIBGS_DEBUG_ENABLE
    ConsolePrintf("Web provisioning complete.\n");
#endif

    DisplayLCD(LCD_LINE6, "WebProv Done");
    DisplayLCD(LCD_LINE7, "");
    DisplayLCD(LCD_LINE8, "Press RESET");
    while (1)
        {}
}
Ejemplo n.º 21
0
/*---------------------------------------------------------------------------*
 * Routine:  WIFI_init
 *---------------------------------------------------------------------------*
 * Description:
 *      Initial setting + DHCP and show status on the LCD.
 *
 * Inputs:
 *      void
 * Outputs:
 *      ATLIBGS_MSG_ID_E
 *---------------------------------------------------------------------------*/
ATLIBGS_MSG_ID_E WIFI_init(int16_t showMessage)
{
  ATLIBGS_MSG_ID_E rxMsgId = ATLIBGS_MSG_ID_NONE;
  char wifi_mac[20];

  // Check the link
#ifdef HOST_APP_DEBUG_ENABLE
  ConsolePrintf("Checking link\r\n");
#endif

  AtLibGs_Init();
  // Wait for the banner
  MSTimerDelay(500);

  // Send command to check
  do {
    AtLibGs_FlushIncomingMessage();
    DisplayLCD(LCD_LINE8, "Checking...");
    rxMsgId = AtLibGs_Check();
  } while (ATLIBGS_MSG_ID_OK != rxMsgId);

  do {
    rxMsgId = AtLibGs_SetEcho(0);               // disable Echo
  }while (ATLIBGS_MSG_ID_OK != rxMsgId);

  do {
    rxMsgId = AtLibGs_Version();                // check the GS version
  }while (ATLIBGS_MSG_ID_OK != rxMsgId);

  // Get MAC Address & Show
  rxMsgId = AtLibGs_GetMAC(wifi_mac);
  if (rxMsgId == ATLIBGS_MSG_ID_OK)
    AtLibGs_ParseGetMacResponse(wifi_mac);
  memset(&wifi_mac[12], 0, 7);
  if (showMessage > 0) {
    DisplayLCD(LCD_LINE5, "MAC ADDRESS");
    DisplayLCD(LCD_LINE6, (const uint8_t *)wifi_mac);
    DisplayLCD(LCD_LINE2, (const uint8_t *)AppVersion);
    MSTimerDelay(2000);
    DisplayLCD(LCD_LINE2, "            ");
  }

  do {
    AtLibGs_FlushIncomingMessage();
    DisplayLCD(LCD_LINE8, "Disassociate");
    rxMsgId = AtLibGs_DisAssoc();
  } while (ATLIBGS_MSG_ID_OK != rxMsgId);

  // Enable DHCP
  do {
    DisplayLCD(LCD_LINE8, "DHCP On...");
    rxMsgId = AtLibGs_DHCPSet(1);
  } while (ATLIBGS_MSG_ID_OK != rxMsgId);

  if(strlen(GNV_Setting.webprov.ssid) > 0)
  {
    if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WEP)
    {
      do {
        DisplayLCD(LCD_LINE8, " Setting WEP");
        rxMsgId = AtLibGs_SetWEP1((int8_t*)GNV_Setting.webprov.password);
      } while (ATLIBGS_MSG_ID_OK != rxMsgId);
      DisplayLCD(LCD_LINE8, " WEP Set");
    }
    else if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WPA_PER)
    {
      do {
        DisplayLCD(LCD_LINE8, " Setting PSK");
        rxMsgId = AtLibGs_CalcNStorePSK(GNV_Setting.webprov.ssid, GNV_Setting.webprov.password);
      } while (ATLIBGS_MSG_ID_OK != rxMsgId); 
      DisplayLCD(LCD_LINE8, " PSK Set");
    }
    else if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WPA_ENT)
    {
      // Set AT+WAUTH=0 for WPA or WPA2
      do {
        DisplayLCD(LCD_LINE8, "       " );
        rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_NONE_WPA);
      } while (ATLIBGS_MSG_ID_OK != rxMsgId);
      // Security Configuration
      do {
        DisplayLCD(LCD_LINE8, "Set Security");
        rxMsgId = AtLibGs_SetSecurity(ATLIBGS_SMAUTO);
      } while (ATLIBGS_MSG_ID_OK != rxMsgId);  
    }
  }
  else
  {
#ifdef HOST_APP_SEC_WEP
    // Set AT+WAUTH=2 for WEP
    do {
      DisplayLCD(LCD_LINE8, " WEP AUTH " );
      rxMsgId = AtLibGs_SetAuthentictionMode(2);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);
    // Set WEP
    do {
      rxMsgId = AtLibGs_SetWEP1(HOST_APP_AP_SEC_WEP);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);
    // Security Configuration
    do {
      rxMsgId = AtLibGs_SetSecurity(2);        // WEP
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif

#ifdef HOST_APP_SEC_PSK
    // Store the PSK value. This call takes might take few seconds to return
    do {
      DisplayLCD(LCD_LINE8, "Setting PSK");
      rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif

#ifdef HOST_APP_SEC_OPEN
    // Store the PSK value. This call takes might take few seconds to return
    do {
      DisplayLCD(LCD_LINE8, "No Security" );
      rxMsgId = AtLibGs_SetAuthentictionMode(1);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif

#ifdef HOST_APP_WPA
    // Set AT+WAUTH=0 for WPA or WPA2
    do {
      DisplayLCD(LCD_LINE8, "   WPA   " );
      rxMsgId = AtLibGs_SetAuthentictionMode(0);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);

    // Store the PSK value. This call takes might take few seconds to return
    do {
      DisplayLCD(LCD_LINE8, "Setting PSK");
      rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);

    // Security Configuration
    do {
      DisplayLCD(LCD_LINE8, "   WPA   ");
      rxMsgId = AtLibGs_SetSecurity(4);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif

#ifdef HOST_APP_WPA2
    // Set AT+WAUTH=0 for WPA or WPA2
    do {
      DisplayLCD(LCD_LINE8, "  WPA2   " );
      rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_NONE_WPA);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);

    // Store the PSK value. This call takes might take few seconds to return
    do {
      DisplayLCD(LCD_LINE8, "Setting PSK");
      rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);

    // Security Configuration
    do {
      DisplayLCD(LCD_LINE8, "  Set WPA  ");
      rxMsgId = AtLibGs_SetSecurity(ATLIBGS_SMWPA2PSK);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif
  }
  // Clear MAC Address and show WIFI
  DisplayLCD(LCD_LINE6, "    WIFI   ");
  DisplayLCD(LCD_LINE5, "           ");

  return rxMsgId;
}
Ejemplo n.º 22
0
/*****************************************************************************
*
*  GPRS_Init
*
*  \param  none
*
*  \return -1:Failure, other: Success
*
*  \brief  Initializes GPRS communications.  Ran at startup.
*
*****************************************************************************/
int AtModem_Init(void)
{
    unsigned char response = AT_REPLY_OK;
    unsigned char retryCount = 0;
    modemstate = MODEM_STATE_AT_CHECK;
    char errorMsg[12] = {'\0'};
    //char LCDString[30];

    DisplayLCD(LCD_LINE8, "Modem Init");

    // disable loopback on modem
    AtModem_Write((unsigned char *)"ate\r", 4);
    // eat up responses
    AtModem_response_check(1000, "ate", "\r");
    AtModem_response_check(1000, "OK", "\r\n");

    ConsolePrintf("Init Novatel Modem Interface\r\n");

    while(modemstate < MODEM_STATE_AT_SD)
    {
        if (response != AT_REPLY_OK)
        {
            sprintf(errorMsg, "C-Error: %d", response);
            DisplayLCD(LCD_LINE7, errorMsg);
            MSTimerDelay(5000); // hold message long enough to view 
            return -1;
        }
        switch (modemstate)
        {
        case MODEM_STATE_AT_CHECK:
            ConsolePrintf("Modem Check\r\n");
            DisplayLCD(LCD_LINE7, "MODEM: CHECK");
            response = AtModem_OnCheck();
            break;
        case MODEM_STATE_AT_INIT:
            ConsolePrintf("Modem Init Params\r\n");
            DisplayLCD(LCD_LINE7, "MODEM: INIT ");
            response = modem_SetParams();
            break;
        case MODEM_STATE_AT_CREG:
            //sprintf((char *)LCDString, "TEMP: %.1fF", gTemp_F);
            //DisplayLCD(LCD_LINE4, (const uint8_t *)LCDString);
            ConsolePrintf("Check Network Registration\r\n");
            DisplayLCD(LCD_LINE7, "MODEM: REG ?");
            response = AtModem_NetworkCheck();
            if(response ==AT_REPLY_OK)
                DisplayLCD(LCD_LINE7, "MODEM: REG 1");
            else
                DisplayLCD(LCD_LINE7, "MODEM: REG 0");
            break;
        case MODEM_STATE_AT_PADS_SET:
            ConsolePrintf("Set PADS Context\r\n");
            response = send_AT_PADS();
            break;
        }

        if (response == AT_REPLY_OK)
        {
            //WriteUILine("AT Response: OK", LCD_DEBUG_LINE);
            ConsolePrintf("AT Response: OK\r\n");
            if (modemstate == MODEM_STATE_AT_PADS_SET)
                modemstate = MODEM_STATE_AT_SD;
            else
                modemstate++;
        }
        else //error == AT_REPLY_ERROR  or AT_REPLY_TIMED_OUT, retry
        {
            if (modemstate == MODEM_STATE_AT_CREG)
            {
                //WriteUILine("AT Response: No Network Yet", LCD_DEBUG_LINE);
                ConsolePrintf("AT Response: No Network Yet\r\n");
            }
            else
            {
                //WriteUILine("AT Response: ERROR", LCD_DEBUG_LINE);
                ConsolePrintf("AT Response: ERROR\r\n");
            }
            if(retryCount < MODEM_RETRY_MAX)
            {
                retryCount++;
            }
            else
            {
                retryCount = 0;
                modemstate = MODEM_STATE_AT_CHECK; //start over
                AtModem_SocketClose(0);
                //WriteUILine("AT: Init Start Over", LCD_DEBUG_LINE);
                ConsolePrintf("AT: Init Start Over\r\n");
            }
            MSTimerDelay(MODEM_RETRY_INTERVAL);
        }
    }
    //WriteUILine("MODEM Initialized", LCD_DEBUG_LINE);
    ConsolePrintf("MODEM Initialized\r\n");
    return 1;
}