Other Parts Discussed in Thread: UNIFLASH
Dear Team,
I'm attempting to get a CC3200 to connect to a WPA2 enterprise WiFi network.
Upon installation, I'm not able to connect to the network, please check the network logs bellow.
->Once device is connected, below log type should reflect
If the image is not clear please go through the link: https://imgur.com/a/Yd8hUm7
->But I'm getting incorrect network log as shown below,
If the image is not clear please go through the link: https://imgur.com/a/W8o04qo
Below I have also attached the detailed network logs
1: CC3200 module :
Network Policy Server denied access to a user.
Contact the Network Policy Server administrator for more information.
User:
Security ID: XX1\xxx15838
Account Name: uix15838
Account Domain: XX1
Fully Qualified Account Name: XX1\xxx15838
Client Machine:
Security ID: NULL SID
Account Name: -
Fully Qualified Account Name: -
Called Station Identifier: 4c-xx-xx-xx-xx-20:XX-X7
Calling Station Identifier: d8-xx-xx-xx-43-b7
NAS:
NAS IPv4 Address: 10.95.182.51
NAS IPv6 Address: -
NAS Identifier: PE-XX01-XXX01
NAS Port-Type: Wireless - IEEE 802.11
NAS Port: 8
RADIUS Client:
Client Friendly Name: PE-XX01-XXX01
Client IP Address: 10.95.182.51
Authentication Details:
Connection Request Policy Name: Secure Wireless Connection
Network Policy Name: Access for XX-X7
Authentication Provider: Windows
Authentication Server: xyz008.xx1.xyz.com
Authentication Type: EAP
EAP Type: -
Account Session Identifier: 36313636653261372F64383A61393A38623A37303A34333A62372F313835393533
Logging Results: Accounting information was written to the local log file.
Reason Code: 22
Reason: The client could not be authenticated because the Extensible Authentication Protocol (EAP) Type cannot be processed by the server.
2: Esp32 Module:
Network Policy Server granted access to a user.
User:
Security ID: XX1\xxxx9345
Account Name: xxxx9345@xx1
Account Domain: XX1
Fully Qualified Account Name: XX1\xxxx9345
Client Machine:
Security ID: NULL SID
Account Name: -
Fully Qualified Account Name: -
Called Station Identifier: 10-xx-xx-xx-xx-80:XX-X7
Calling Station Identifier: 94-xx-xx-xx-xx-0f
NAS:
NAS IPv4 Address: 10.95.182.51
NAS IPv6 Address: -
NAS Identifier: PE-XX01-XXX01
NAS Port-Type: Wireless - IEEE 802.11
NAS Port: 8
RADIUS Client:
Client Friendly Name: PE-XX01-XXX01
Client IP Address: 10.95.182.51
Authentication Details:
Connection Request Policy Name: Secure Wireless Connection
Network Policy Name: Access for XX-X7
Authentication Provider: Windows
Authentication Server: xyz008.xx1.xyz.com
Authentication Type: PEAP
EAP Type: Microsoft: Secured password (EAP-MSCHAP v2)
Account Session Identifier: 36313636653336352F39343A66623A32393A34303A32643A30662F313835393534
Logging Results: Accounting information was written to the local log file.
Below are the screenshots for each CC3200 devices, we can see the MAC address & EAP type highlighted:
1. CC3200 device 1 Screenshot
2. CC3200 device 2 Screenshot
In the above 2 screenshots the MAC address are different and EAP type is 3 what does it specify. can you please clear the doubts.
I would appreciate your efforts in going through my code just to check if I'm not missing any part which might affect the functionality. Please find the attached code below:
******************************************************************************/ #include "EMSGateway.h" //***************************************************************************** // GLOBAL VARIABLES -- Start //***************************************************************************** #ifdef USE_FREERTOS #if defined(ewarm) extern uVectorEntry __vector_table; #endif #if defined(ccs) extern void (* const g_pfnVectors[])(void); #endif #endif #define SLOW_CLK_FREQ (32*1024) #define MAX_BUFFER_SIZE 3 //60 samples can be stored. bool boolBrokerDisconnected = false; bool bool_EMData = false; bool boolDataCollected = false; //status of data collected const char g_acSNTPserver[30] = "time-a.nist.gov"; //Add any one of the above servers int g_uiSimplelinkRole = ROLE_INVALID; unsigned int g_uiDeviceModeConfig = ROLE_STA; //default is STA mode volatile unsigned char g_ucConnectTimeout =0; bool boolRestart=false,boolSmartConfig=false,boolButtonPress=false; unsigned short g_usTimerInts; uint8_t ui8TimeCounter=0; unsigned long g_ulPingPacketsRecv = 0; //Number of Ping Packets received static volatile unsigned long g_ulBase; uint16_t ui16ResetCounter = 0; uint32_t ui32ResetCounter = 0; /* AP Security Parameters */ SlSecParams_t SecurityParams = {0}; /*Message Queue*/ OsiMsgQ_t g_PBQueue; /* connection configuration */ connect_config usr_connect_config[] = { { { { SL_MQTT_NETCONN_URL, SERVER_ADDRESS, PORT_NUMBER, 0, 0, 0, NULL }, SERVER_MODE, true, }, NULL, "00062", //This is client ID. It should be different for different gateways NULL, // USN, NULL, // USN_PASSWORD, true, KEEP_ALIVE_TIMER, {Mqtt_Recv, sl_MqttEvt, sl_MqttDisconnect}, TOPIC_COUNT, {TOPIC1, TOPIC2, TOPIC3}, {QOS2, QOS2, QOS2}, {WILL_TOPIC,WILL_MSG,WILL_QOS,WILL_RETAIN}, false } }; /* library configuration */ SlMqttClientLibCfg_t Mqtt_Client={ 0, TASK_PRIORITY, 30, false, (long(*)(const char *, ...))UART_PRINT }; /*Publishing topics and messages*/ const char *pub_topic = PUB_TOPIC; char *data_sw3="\0"; char HeaderDataBuffer[1000]; char MainDataBuffer[800]; char FooterDataBuffer[10]; //char cTxPendingBuffer[MAX_BUFFER_SIZE][500]; //char cTxBufferCount = 0; char cReconnectCntr = 0; uint8_t ui8UartCount=0,ui8SampleCount=0,ui8TimerValue=0; void *app_hndl = (void*)usr_connect_config; //mqtt client variables declared globally int iCount = 0; connect_config *local_con_conf; char c_modbus_count = 7; int iStringLength = 0; int iSamplingRate = 1; // Min 1 minute & Max 60 minutes short g_usCurrentSamplingTime = 0; uint8_t ucCharBuffer[100],cCharacter; char uint8SlaveID = SLAVE_ID_2; //char uint8RishSlaveID3 = SLAVE_ID_3; //char uint8RishSlaveID4 = SLAVE_ID_4; //uint32_t GatewayID = 12345; char GatewayID[5] = "00062"; uint32_t ui32_tempGWID = 0; uint32_t uint32Temporary_data; // variables to store read parameters uint32_t ui32_RegAddr, ui32_RegData; //struct_gateway gateway; // Flags bool declaration. bool ParametersReady = false; // set when all the parameters are read from the uart. // default is false bool NewBufferData = false; // set when buffer is filled with the new data // default is false //***************************************************************************** // GLOBAL VARIABLES -- End //***************************************************************************** /*************************************************************************************************** * EXTERNAL VARIABLES ***************************************************************************************************/ extern unsigned long g_ulGatewayIP; //Network Gateway IP address extern volatile unsigned long g_ulStatus; //SimpleLink Status extern unsigned long g_ulGatewayIP; //Network Gateway IP address //extern struct_em_reg em_register[MAX_REGISTERS] = {}; //registers structure //extern struct_ems_meter ems_meters[MAX_METERS] = {}; //meters structure //extern struct_gateway gateway = {}; //gateway and device structure extern struct_em_reg em_register[MAX_REGISTERS]; //registers structure extern struct_ems_meter ems_meters[MAX_METERS]; //meters structure extern struct_gateway gateway; //gateway and device structure extern bool boolSamplingIntervalSetFlag; /*********************************************************************************************** * TYPEDEFS, ENUMS AND STRUCTURES **********************************************************************************************/ // Application specific status/error codes typedef enum{ // Choosing -0x7D0 to avoid overlap w/ host-driver's error codes LAN_CONNECTION_FAILED = -0x7D0, INTERNET_CONNECTION_FAILED = LAN_CONNECTION_FAILED - 1, DEVICE_NOT_IN_STATION_MODE = INTERNET_CONNECTION_FAILED - 1, STATUS_CODE_MAX = -0xBB8, }e_AppStatusCodes; //**************************************************************************** // //! Push Button Handler1(GPIOS2). Press push button2 (GPIOSW2) Whenever user //! wants to publish a message. Write message into message queue signaling the //! event publish messages //! //! \param none //! //! return none // //**************************************************************************** //void pushButtonInterruptHandler2() void pushButtonInterruptHandler3() { } //**************************************************************************** // //! Push Button Handler3(GPIOS3). Press push button3 (GPIOSW3) Whenever user //! wants to publish a message. Write message into message queue signaling the //! event publish messages //! //! \param none //! //! return none // //**************************************************************************** //void pushButtonInterruptHandler3() void pushButtonInterruptHandler2() { boolButtonPress = !boolButtonPress; if(boolButtonPress) { Timer_IF_Start(TIMERA0_BASE,TIMER_A,500); } else { Timer_IF_Stop(TIMERA0_BASE,TIMER_A); if(ui8TimeCounter > FORCE_SMART_CONFIG) boolSmartConfig = true; ui8TimeCounter = 0; MAP_GPIOPinWrite(GPIOA3_BASE, GPIO_PIN_4, 0); //Yellow LED OFF } Button_IF_EnableInterrupt(SW2); } void TimerPeriodicIntHandler(void) { unsigned long ulInts; // Clear all pending interrupts from the timer we are currently using. ulInts = MAP_TimerIntStatus(TIMERA0_BASE, true); MAP_TimerIntClear(TIMERA0_BASE, ulInts); if(boolButtonPress) ui8TimeCounter++; // Increment our interrupt counter. g_usTimerInts++; if(!(g_usTimerInts & 0x1)) { // Off Led MAP_GPIOPinWrite(GPIOA3_BASE, GPIO_PIN_4, 0); //Yellow LED OFF } else { // On Led MAP_GPIOPinWrite(GPIOA3_BASE, GPIO_PIN_4, GPIO_PIN_4); //Yellow LED ON } } /****************************************************************************** CPU Periodic Timer Interrupt Handler \param None \return None ******************************************************************************/ void CPUTimerPeriodicIntHandler(void) { unsigned long ulInts; // Clear all pending interrupts from the timer we are // currently using. ulInts = MAP_TimerIntStatus(TIMERA2_BASE, true); MAP_TimerIntClear(TIMERA2_BASE, ulInts); // Decrement our interrupt counter. g_usCurrentSamplingTime --; if ( g_usCurrentSamplingTime <= 0 ) { bool_EMData = true; // g_usCurrentSamplingTime = (short) iSamplingRate * 60; //resetting the CPU timer } } /***************************************************************************** Function to configure and start sampling timer \param none return none *****************************************************************************/ void CPUTimerConfigNStart() { // Configure Timer for blinking the LED for IP acquisition Timer_IF_Init(PRCM_TIMERA2,TIMERA2_BASE,TIMER_CFG_PERIODIC,TIMER_A,0); Timer_IF_IntSetup(TIMERA2_BASE,TIMER_A,CPUTimerPeriodicIntHandler); Timer_IF_Start(TIMERA2_BASE,TIMER_A,1000); } //***************************************************************************** // //! \brief This function handles ping report events //! //! \param[in] pPingReport - Ping report statistics //! //! \return None //! //***************************************************************************** void SimpleLinkPingReport(SlPingReport_t *pPingReport) { SET_STATUS_BIT(g_ulStatus, STATUS_BIT_PING_DONE); g_ulPingPacketsRecv = pPingReport->PacketsReceived; } //***************************************************************************** //! \brief This function checks the internet connection by pinging //! the external-host (HOST_NAME) //! //! \param None //! //! \return 0 on success, negative error-code on error //! //***************************************************************************** static long CheckInternetConnection() { SlPingStartCommand_t pingParams = {0}; SlPingReport_t pingReport = {0}; unsigned long ulIpAddr = 0; long lRetVal = -1; CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_PING_DONE); g_ulPingPacketsRecv = 0; // Set the ping parameters pingParams.PingIntervalTime = PING_INTERVAL; pingParams.PingSize = PING_PKT_SIZE; pingParams.PingRequestTimeout = PING_TIMEOUT; pingParams.TotalNumberOfAttempts = NO_OF_ATTEMPTS; pingParams.Flags = 0; pingParams.Ip = g_ulGatewayIP; // Get external host IP address lRetVal = sl_NetAppDnsGetHostByName((signed char*)HOST_NAME, sizeof(HOST_NAME), &ulIpAddr, SL_AF_INET); ASSERT_ON_ERROR(lRetVal); // Replace the ping address to match HOST_NAME's IP address pingParams.Ip = ulIpAddr; // Try to ping HOST_NAME lRetVal = sl_NetAppPingStart((SlPingStartCommand_t*)&pingParams, SL_AF_INET, (SlPingReport_t*)&pingReport, SimpleLinkPingReport); ASSERT_ON_ERROR(lRetVal); // Wait while(!IS_PING_DONE(g_ulStatus)) { // Wait for Ping Event #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } if (0 == g_ulPingPacketsRecv) { // Problem with internet connection ASSERT_ON_ERROR(INTERNET_CONNECTION_FAILED); } // Internet connection is successful return SUCCESS; } /***************************************************************************** * @name PowerCycleDevice() * * @brief function which puts the device in hibernation and then Resets * * @param None * * @ret None */ void PowerCycleDevice() { sl_Stop(0); MAP_PRCMHibernateIntervalSet(330); MAP_PRCMHibernateWakeupSourceEnable(PRCM_HIB_SLOW_CLK_CTR); MAP_PRCMHibernateEnter(); } //***************************************************************************** // //! Outputs a character string to the MOD_BUS_UART console //! //! \param str is the pointer to the string to be printed //! //! This function //! 1. prints the input string character by character on to the MOD_BUS_UART console. //! //! \return none // //***************************************************************************** void modbus_uartsend(const char *str) { #ifndef NOTERM if(str != NULL) { // while(*str!='\0') while(c_modbus_count--) { MAP_UARTCharPut(MOD_BUS_UART,*str++); } } #endif } /******************************************************************************* * @Name UARTIntHandler * * @brief UART 1 Receive Interrupt Handler, * * @param None * * @return None ******************************************************************************/ static void UARTIntHandler() { unsigned long ulStatus; ulStatus = MAP_UARTIntStatus(MOD_BUS_UART, 1); //if char received on UART pin while(MAP_UARTCharsAvail(MOD_BUS_UART) == false) { UtilsDelay(10000); } cCharacter = MAP_UARTCharGetNonBlocking(MOD_BUS_UART); ucCharBuffer[iStringLength] = cCharacter; iStringLength++; if(iStringLength > 8) NewBufferData = true; //Clear UART interrupt MAP_UARTIntClear(MOD_BUS_UART, ulStatus); } //***************************************************************************** // //! Board Initialization & Configuration //! //! \param None //! //! \return None // //***************************************************************************** void BoardInit(void) { /* In case of TI-RTOS vector table is initialize by OS itself */ #ifndef USE_TIRTOS // Set vector table base #if defined(ccs) IntVTableBaseSet((unsigned long)&g_pfnVectors[0]); #endif #if defined(ewarm) IntVTableBaseSet((unsigned long)&__vector_table); #endif #endif // Enable Processor MAP_IntMasterEnable(); MAP_IntEnable(FAULT_SYSTICK); PRCMCC3200MCUInit(); } extern volatile unsigned long g_ulStatus; //SMARTCOFIG //********************************************************************************* long ResetNwp() { long lRetVal = -1; /* Restart Network processor */ lRetVal = sl_Stop(SL_STOP_TIMEOUT); lRetVal = sl_Start(NULL,NULL,NULL); ASSERT_ON_ERROR(lRetVal); return lRetVal; } //**************************************************************************** // //! \brief Configuring the Connection Policy //! //! This function configures different Connection Policy such as FAST,AUTO,OPEN //! //! \param[in] None //! //! \return 0 on success else error code //! //! \note // //**************************************************************************** static long SetConnectionPolicy() { unsigned char policyVal; long lRetVal = -1; /* Clear all stored profiles and reset the policies */ lRetVal = sl_WlanProfileDel(0xFF); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(0,0,0,0,0), 0, 0); ASSERT_ON_ERROR(lRetVal); // Disconnect from AP lRetVal = sl_WlanDisconnect(); if(0 == lRetVal) { // Wait while(IS_CONNECTED(g_ulStatus)) { #ifdef SL_PLATFORM_MULTI_THREADED osi_Sleep(10); #endif } } //delete profiles lRetVal = sl_WlanProfileDel(0xFF); ASSERT_ON_ERROR(lRetVal); //set Auto SmartConfig policy lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,1), &policyVal,0); ASSERT_ON_ERROR(lRetVal); // reset the NWP lRetVal = ResetNwp(); ASSERT_ON_ERROR(lRetVal); // wait for smart config to complete and device to connect to an AP //wait until IP is acquired while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))) { // _SlNonOsMainLoopTask(); osi_Sleep(10); } CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION); CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED); //remove all policies lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(0,0,0,0,0), &policyVal,0); ASSERT_ON_ERROR(lRetVal); return SUCCESS; } //**************************************************************************** // //! \brief Collection of Energy Meter Data //! //! This function collects the data from all the registers of each energy meter and publish it over MQTT //! //! \param[in] None //! //! \return 0 on success else error code //! //! \note // //**************************************************************************** void CollectEMData() { char ems_meter_index, ems_reg_index = 0; char ucDeviceID,ucRegLen; short unsigned int sui16RegAddr; uint32_t uint32Result = 0; // ui32_tempGWID = atoi( GatewayID ); if(ui32_tempGWID == gateway.ui32DeviceId) { // g_usCurrentSamplingTime = (short) iSamplingRate * 60; //resetting the CPU timer g_usCurrentSamplingTime = (short) gateway.ui8SamplingInterval * 60; //resetting the CPU timer for ( ems_meter_index = 0; ems_meter_index < MAX_METERS; ems_meter_index++ ) { if (gateway.ems_meters[ems_meter_index].ui8SlaveId != 0) { for( ems_reg_index = 0; ems_reg_index < MAX_REGISTERS;ems_reg_index ++ ) { if (gateway.ems_meters[ems_meter_index].em_register[ems_reg_index].ui32Reg_Addr != 0) { ucDeviceID = gateway.ems_meters[ems_meter_index].ui8SlaveId; sui16RegAddr = gateway.ems_meters[ems_meter_index].em_register[ems_reg_index].ui32Reg_Addr; ucRegLen = gateway.ems_meters[ems_meter_index].em_register[ems_reg_index].ui32Reg_Size; uint32Result = ReadHoldingRegister ( ucDeviceID,sui16RegAddr,ucRegLen ); gateway.ems_meters[ems_meter_index].em_register[ems_reg_index].ui32Reg_Data = uint32Result; } } ParametersReady = true; // set flag indicating ready to send data over MQTT if (ParametersReady) { // GatewayID = gateway.ui32DeviceId; uint8SlaveID = gateway.ems_meters[ems_meter_index].ui8SlaveId; memset(HeaderDataBuffer, 0, sizeof(HeaderDataBuffer)); memset(MainDataBuffer, 0, sizeof(MainDataBuffer)); memset(FooterDataBuffer, 0, sizeof(FooterDataBuffer)); sprintf(HeaderDataBuffer,"{\"GID\": \"%s\", \"DID\": \"%03d\",",GatewayID,uint8SlaveID); for( ems_reg_index = 0; ems_reg_index < MAX_REGISTERS; ems_reg_index++ ) { if (gateway.ems_meters[ems_meter_index].em_register[ems_reg_index].ui32Reg_Addr != 0) { ui32_RegAddr = gateway.ems_meters[ems_meter_index].em_register[ems_reg_index].ui32Reg_Addr; ui32_RegData = gateway.ems_meters[ems_meter_index].em_register[ems_reg_index].ui32Reg_Data; sprintf(MainDataBuffer,"\"%d\": \"%x\",",ui32_RegAddr,ui32_RegData); strcat(HeaderDataBuffer, MainDataBuffer); } } sprintf(FooterDataBuffer,"}"); strcat(HeaderDataBuffer, FooterDataBuffer); boolDataCollected = true; // publish current data sl_ExtLib_MqttClientSend((void*)local_con_conf[iCount].clt_ctx, //MQTT Send Function pub_topic,(char *)HeaderDataBuffer,strlen(HeaderDataBuffer),QOS2,RETAIN); /* // Start of store and forward data section. if( local_con_conf->is_connected ) // internet is connected { //check if data in buffer (old data) if(cTxBufferCount > 0) { char i; for(i = 0; i < cTxBufferCount; i++) { //publish stored data sl_ExtLib_MqttClientSend((void*)local_con_conf[iCount].clt_ctx, //MQTT Send Function pub_topic,(char *)cTxPendingBuffer[i],strlen(cTxPendingBuffer[i]),QOS2,RETAIN); } cTxBufferCount = 0; } // publish current data sl_ExtLib_MqttClientSend((void*)local_con_conf[iCount].clt_ctx, //MQTT Send Function pub_topic,(char *)HeaderDataBuffer,strlen(HeaderDataBuffer),QOS2,RETAIN); boolDataCollected = false; //false after data is transmitted } else { if (boolDataCollected == true) { // store data into buffer memset(cTxPendingBuffer[cTxBufferCount], 0, sizeof(cTxPendingBuffer[cTxBufferCount])); strcpy(cTxPendingBuffer[cTxBufferCount],HeaderDataBuffer); cTxBufferCount++; // increment store buffer data count boolDataCollected = false; //set data collected flag to false if(cTxBufferCount >= MAX_BUFFER_SIZE) //reset store buffer data counter cTxBufferCount = 0; } } // End of store and forward data section. */ ParametersReady = false; } } } } // bool_EMData = false; } //***************************************************************************** // //! Task implementing MQTT client communication to other web client through //! a broker //! //! \param none //! //! This function //! 1. Initializes network driver and connects to the default AP //! 2. Initializes the mqtt library and set up MQTT connection configurations //! 3. set up the button events and their callbacks(for publishing) //! 4. handles the callback signals //! //! \return None //! //***************************************************************************** void MqttClient(void *pvParameters) { long lRetVal = -1; int iCount = 0; int iNumBroker = 0; int iConnBroker = 0; unsigned char policyVal; SlSecParamsExt_t eapParams; SlSecParams_t g_SecParams; // long lRetVal = -1; unsigned char pValues = 0; // connect_config *local_con_conf = (connect_config *)app_hndl; local_con_conf = (connect_config *)app_hndl; // connect_to_broker: // Reset The state of the machine Network_IF_ResetMCUStateMachine(); // Start the driver lRetVal = Network_IF_InitDriver(ROLE_STA); if(lRetVal < 0) { LOOP_FOREVER(); } //Write Data to Flash // WriteFileToDevice(&ulToken, &lFileHandle); // switch on Yellow LED to indicate Simplelink is properly up MAP_GPIOPinWrite(GPIOA3_BASE, GPIO_PIN_4, GPIO_PIN_4); //Yellow LED ON // Start Timer to blink Red LED till AP connection LedTimerConfigNStart(); /* // Initialize AP security params SecurityParams.Key = (signed char *)SECURITY_KEY; SecurityParams.KeyLen = strlen(SECURITY_KEY); SecurityParams.Type = SECURITY_TYPE; // // Connect to the Access Point // lRetVal = Network_IF_ConnectAP(SSID_NAME, SecurityParams); if(lRetVal < 0) { UART_PRINT("Connection to an AP failed\n\r"); LOOP_FOREVER(); } lRetVal = sl_WlanProfileAdd(SSID_NAME,strlen(SSID_NAME),0,&SecurityParams,0,1,0); */ // //set AUTO policy // lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, // SL_CONNECTION_POLICY(1,0,0,0,0), // &policyVal, 1 /*PolicyValLen*/); // // // //set AUTO policy // lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, // SL_CONNECTION_POLICY(1,1,0,0,0), // &policyVal, 1 /*PolicyValLen*/); //SL_CONNECTION_POLICY is set to auto and fast config connection mode. CLR_STATUS_BIT_ALL(g_ulStatus); //Start simplelink g_uiSimplelinkRole = sl_Start(NULL,NULL,NULL); //start ent wlan connection // eapParams.EapMethod = SL_ENT_EAP_METHOD_PEAP1_MSCHAPv2; eapParams.EapMethod = SL_ENT_EAP_METHOD_PEAP0_MSCHAPv2; eapParams.User = USER_NAME; eapParams.UserLen = strlen((const char *)eapParams.User); eapParams.AnonUserLen = 0; g_SecParams.Key = PASSWORD; g_SecParams.KeyLen = strlen((const char *)g_SecParams.Key); g_SecParams.Type = SL_SEC_TYPE_WPA_ENT; // 0 - Disable the server authnetication | 1 - Enable (this is the deafult) pValues = 0; sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, 19, 1 , &pValues); lRetVal = sl_WlanConnect(ENT_NAME,strlen(ENT_NAME),NULL,&g_SecParams, \ &eapParams); // ASSERT_ON_ERROR(lRetVal); if(lRetVal < 0) { UART_PRINT("Connection to an AP failed\n\r"); LOOP_FOREVER(); } //End ent wlan connection //waiting for the device to Auto Connect while ( (!IS_IP_ACQUIRED(g_ulStatus))&& g_ucConnectTimeout < AUTO_CONNECTION_TIMEOUT_COUNT) { //Turn RED LED On MAP_GPIOPinWrite(GPIOA3_BASE, GPIO_PIN_4, GPIO_PIN_4); //Yellow LED ON osi_Sleep(50); //Turn RED LED Off MAP_GPIOPinWrite(GPIOA3_BASE, GPIO_PIN_4, 0); //Yellow LED OFF osi_Sleep(50); g_ucConnectTimeout++; } lRetVal = sl_WlanProfileAdd(ENT_NAME,strlen(ENT_NAME),0,&g_SecParams,0,1,0); //set AUTO policy lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,0), &policyVal, 1 /*PolicyValLen*/); // lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(1,0,0,0,0),NULL,0); /* // start smart config section if AP is not found // Start Timer to blink Yellow LED till AP connection LedTimerConfigNStart(); if (g_ucConnectTimeout >= AUTO_CONNECTION_TIMEOUT_COUNT) { SetConnectionPolicy(); //set connection policy to smart config and wait for connection } // end smart config section if AP is not found */ // Disable the LED blinking Timer as Device is connected to AP LedTimerDeinitStop(); //Read Data from Flash ReadFileFromDevice(ulToken, lFileHandle); if(ui32_tempGWID == gateway.ui32DeviceId ) iSamplingRate = gateway.ui8SamplingInterval; // Switch ON Yellow LED to indicate that Device acquired an IP MAP_GPIOPinWrite(GPIOA3_BASE, GPIO_PIN_4, GPIO_PIN_4); //Yellow LED ON UtilsDelay(20000000); MAP_GPIOPinWrite(GPIOA3_BASE, GPIO_PIN_4, 0); //Yellow LED OFF // Register Push Button Handlers Button_IF_Init(pushButtonInterruptHandler2,pushButtonInterruptHandler3); ReconnectNow: if(boolRestart) { // sl_ExtLib_MqttClientDisconnect((void*)local_con_conf[iCount].clt_ctx); /* Clear all stored profiles and reset the policies */ lRetVal = sl_WlanProfileDel(0xFF); // ASSERT_ON_ERROR(lRetVal); sl_WlanDisconnect(); MAP_GPIOPinWrite(GPIOA3_BASE, GPIO_PIN_4, GPIO_PIN_4); //Yellow LED ON UtilsDelay(100000); MAP_GPIOPinWrite(GPIOA3_BASE, GPIO_PIN_4, 0); //Yellow LED OFF UtilsDelay(100000); MAP_GPIOPinWrite(GPIOA3_BASE, GPIO_PIN_4, GPIO_PIN_4); //Yellow LED ON // Start Timer to blink Red LED till AP connection LedTimerConfigNStart(); SetConnectionPolicy(); // Disable the LED blinking Timer as Device is connected to AP LedTimerDeinitStop(); MAP_GPIOPinWrite(GPIOA3_BASE, GPIO_PIN_4, 0); //Yellow LED OFF boolRestart = false; } connect_to_broker: // Initialze MQTT client lib lRetVal = sl_ExtLib_MqttClientInit(&Mqtt_Client); if(lRetVal != 0) { // lib initialization failed LOOP_FOREVER(); } /******************* connection to the broker ***************************/ iNumBroker = sizeof(usr_connect_config)/sizeof(connect_config); if(iNumBroker > MAX_BROKER_CONN) { LOOP_FOREVER(); } // connect_to_broker: while(iCount < iNumBroker) { //create client context local_con_conf[iCount].clt_ctx = sl_ExtLib_MqttClientCtxCreate(&local_con_conf[iCount].broker_config, &local_con_conf[iCount].CallBAcks, &(local_con_conf[iCount])); // Set Client ID sl_ExtLib_MqttClientSet((void*)local_con_conf[iCount].clt_ctx, SL_MQTT_PARAM_CLIENT_ID, local_con_conf[iCount].client_id, strlen((char*)(local_con_conf[iCount].client_id))); // Set will Params if(local_con_conf[iCount].will_params.will_topic != NULL) { sl_ExtLib_MqttClientSet((void*)local_con_conf[iCount].clt_ctx, SL_MQTT_PARAM_WILL_PARAM, &(local_con_conf[iCount].will_params), sizeof(SlMqttWill_t)); } // setting username and password if(local_con_conf[iCount].usr_name != NULL) { sl_ExtLib_MqttClientSet((void*)local_con_conf[iCount].clt_ctx, SL_MQTT_PARAM_USER_NAME, local_con_conf[iCount].usr_name, strlen((char*)local_con_conf[iCount].usr_name)); if(local_con_conf[iCount].usr_pwd != NULL) { sl_ExtLib_MqttClientSet((void*)local_con_conf[iCount].clt_ctx, SL_MQTT_PARAM_PASS_WORD, local_con_conf[iCount].usr_pwd, strlen((char*)local_con_conf[iCount].usr_pwd)); } } // connectin to the broker if((sl_ExtLib_MqttClientConnect((void*)local_con_conf[iCount].clt_ctx, local_con_conf[iCount].is_clean, local_con_conf[iCount].keep_alive_time) & 0xFF) != 0) { //delete the context for this connection sl_ExtLib_MqttClientCtxDelete(local_con_conf[iCount].clt_ctx); break; } else { local_con_conf[iCount].is_connected = true; iConnBroker++; } // Subscribe to topics if(sl_ExtLib_MqttClientSub((void*)local_con_conf[iCount].clt_ctx, local_con_conf[iCount].topic, local_con_conf[iCount].qos, TOPIC_COUNT) < 0) { sl_ExtLib_MqttClientDisconnect(local_con_conf[iCount].clt_ctx); local_con_conf[iCount].is_connected = false; //delete the context for this connection sl_ExtLib_MqttClientCtxDelete(local_con_conf[iCount].clt_ctx); iConnBroker--; break; } else { int iSub; for(iSub = 0; iSub < local_con_conf[iCount].num_topics; iSub++) { } } iCount++; } if(iConnBroker < 1) { // no succesful connection to broker goto end; } iCount = 0; CPUTimerConfigNStart(); // start the timer for(;;) { if(boolSamplingIntervalSetFlag) { CollectEMData(); boolSamplingIntervalSetFlag = false; } if(boolSmartConfig) //Conditional entry check for Force Smart Configuration { boolRestart=true; boolSmartConfig = false; goto ReconnectNow; } //Check If AP is disconnected if(boolBrokerDisconnected) { //Jumps to Reconnection Wait state goto end; } // collect_data: if (bool_EMData) //collecting data after timer interval is over { CollectEMData(); bool_EMData = false; } } end: lRetVal = CheckInternetConnection(); //Wait Untill AP/Internet connection is established // while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))) while(lRetVal < 0) { IS_IP_ACQUIRED(g_ulStatus); IS_CONNECTED(g_ulStatus); lRetVal = CheckInternetConnection(); MAP_GPIOPinWrite(GPIOA3_BASE, GPIO_PIN_4, GPIO_PIN_4); //Yellow LED ON osi_Sleep(12000); MAP_GPIOPinWrite(GPIOA3_BASE, GPIO_PIN_4, 0); //Yellow LED OFF osi_Sleep(3000); cReconnectCntr++; //Count no of attempts of reconnection if(boolSmartConfig) { lRetVal = 1; lRetVal = sl_WlanProfileDel(0xFF); sl_WlanDisconnect(); boolRestart=true; boolSmartConfig = false; goto ReconnectNow; } if( cReconnectCntr > 8 ) // 1 count = 15 secs therefore 4 count = 1 mins { cReconnectCntr = 0; PowerCycleDevice(); // soft resets the device - data is lost } /* // start of timer interrupt condition when in disconnection state if (bool_EMData) //is data to be collected? { //Jumps to Collect the data from the energy meter // goto collect_data; CollectEMData(); // collection of EM data. bool_EMData = false; } // End of timer interrupt condition when in disconnection state */ } MAP_GPIOPinWrite(GPIOA3_BASE, GPIO_PIN_4, 0); //Yellow LED OFF local_con_conf->is_connected = true; boolBrokerDisconnected = false; /* //If AP connection is sucessfull jump to reintiate MQTT broker Connection PowerCycleDevice(); // soft resets the device - data is lost */ // ResetNwp(); //restart the network processor goto connect_to_broker; } //**************************************************************************** // //! Function to configure and start timer to blink the LED while device is //! trying to connect to an AP //! //! \param none //! //! return none // //**************************************************************************** void LedTimerConfigNStart() { // Configure Timer for blinking the LED for IP acquisition Timer_IF_Init(PRCM_TIMERA0,TIMERA0_BASE,TIMER_CFG_PERIODIC,TIMER_A,0); Timer_IF_IntSetup(TIMERA0_BASE,TIMER_A,TimerPeriodicIntHandler); Timer_IF_Start(TIMERA0_BASE,TIMER_A,250); } //***************************************************************************** //! Main //! //! \param none //! //! This function //! 1. Invokes the SLHost task //! 2. Invokes the MqttClient //! //! \return None //***************************************************************************** void main() { long lRetVal = -1; //initiualize structures with 0 ui32_tempGWID = atoi( GatewayID ); // hardcoded data END // Initialize the board configurations BoardInit(); // Pinmux for UART PinMuxConfig(); // Enable the SPI module clock MAP_PRCMPeripheralClkEnable(PRCM_GSPI,PRCM_RUN_MODE_CLK); // Configuring UART InitTerm(); // register the uart interrupt MAP_UARTIntRegister(MOD_BUS_UART,UARTIntHandler); // enable the uart interrupt MAP_UARTIntEnable(MOD_BUS_UART,UART_INT_RX); // // Clearing the Terminal. // ClearTerm(); // disable the uart FIFO MAP_UARTFIFODisable(MOD_BUS_UART); //Initializing the timers InitTimers(); boolSamplingIntervalSetFlag = true; //upon reset set SamplingInterval flag for 1st time data read and publish. // CPUTimerConfigNStart(); // start the timer // g_usCurrentSamplingTime = (short) iSamplingRate * 60; //converting minutes to secs // Start the SimpleLink Host lRetVal = VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY); if(lRetVal < 0) { ERR_PRINT(lRetVal); LOOP_FOREVER(); } gateway.ui8SamplingInterval = (short) iSamplingRate; //Read Data from Flash ReadFileFromDevice(ulToken, lFileHandle); if(ui32_tempGWID == gateway.ui32DeviceId ) iSamplingRate = gateway.ui8SamplingInterval; g_usCurrentSamplingTime = (short) iSamplingRate * 60; //converting minutes to secs // Start the MQTT Client task osi_MsgQCreate(&g_PBQueue,"PBQueue",sizeof(event_msg),10); lRetVal = osi_TaskCreate(MqttClient, (const signed char *)"Mqtt Client App", OSI_STACK_SIZE, NULL, 2, NULL ); if(lRetVal < 0) { ERR_PRINT(lRetVal); LOOP_FOREVER(); } // Start the task scheduler osi_start(); }
Looking forward for a swift response!
Sincerely,
Shivaprasad