int main0(void){ // "Embedded Systems: Real Time Interfacing to ARM Cortex M Microcontrollers", // ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2014, Volume 2, Program 11.2 UINT8 IsDHCP = 0; _NetCfgIpV4Args_t ipV4; SlSockAddrIn_t Addr; UINT16 AddrSize = 0; INT16 SockID = 0; UINT32 data; unsigned char len = sizeof(_NetCfgIpV4Args_t); initClk(); // PLL 50 MHz, ADC needs PPL active 15 ADC0_InitSWTriggerSeq3(7); // Ain7 is on PD0 16 sl_Start(0, 0, 0); // Initializing the CC3100 device 17 WlanConnect(); // connect to AP 18 sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len, // 19 (unsigned char *)&ipV4); // 20 Addr.sin_family = SL_AF_INET; // 21 Addr.sin_port = sl_Htons((UINT16)PORT_NUM); // 22 Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR); // 23 AddrSize = sizeof(SlSockAddrIn_t); // 24 SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); // 25 while(1){ uBuf[0] = ATYPE; // analog data type 26 uBuf[1] = '='; // 27 data = ADC0_InSeq3(); // 0 to 4095, Ain7 is on PD0 28 Int2Str(data,(char*)&uBuf[2]); // 6 digit number 29 sl_SendTo(SockID, uBuf, BUF_SIZE, 0, // 30 (SlSockAddr_t *)&Addr, AddrSize); // 31 ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25); // 40ms 32 } }
static void Init() { long lRetVal = -1; BoardInit(); UDMAInit(); PinMuxConfig(); InitTerm(); InitializeAppVariables(); // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its default state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // lRetVal = ConfigureSimpleLinkToDefaultState(); if (lRetVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == lRetVal) UART_PRINT( "Failed to configure the device in its default state \n\r"); LOOP_FOREVER() ; } // // Asumption is that the device is configured in station mode already // and it is in its default state // lRetVal = sl_Start(0, 0, 0); if (lRetVal < 0) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER() ; } UART_PRINT("Connecting to AP: '%s'...\r\n", SSID_NAME); // Connecting to WLAN AP - Set with static parameters defined at common.h // After this call we will be connected and have IP address lRetVal = WlanConnect(); if (lRetVal < 0) { UART_PRINT("Connection to AP failed \n\r"); LOOP_FOREVER() ; } UART_PRINT("Connected to AP: '%s' \n\r", SSID_NAME); #ifdef NEW_ID iobeam_Reset(); #endif }
//**************************************************************************** // //! \brief Start simplelink, connect to the ap and run the ping test //! //! This function starts the simplelink, connect to the ap and start the ping //! test on the default gateway for the ap //! //! \param[in] pvParameters - Pointer to the list of parameters that //! can bepassed to the task while creating it //! //! \return None // //**************************************************************************** void WlanStationMode( void *pvParameters ) { long lRetVal = -1; InitializeAppVariables(); // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its default state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // lRetVal = ConfigureSimpleLinkToDefaultState(); if(lRetVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == lRetVal) { UART_PRINT("Failed to configure the device in its default state\n\r"); } LOOP_FOREVER(); } UART_PRINT("Device is configured in default state \n\r"); // // Assumption is that the device is configured in station mode already // and it is in its default state // lRetVal = sl_Start(0, 0, 0); if (lRetVal < 0 || ROLE_STA != lRetVal) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(); } UART_PRINT("Device started as STATION \n\r"); // //Connecting to WLAN AP // lRetVal = WlanConnect(); if(lRetVal < 0) { UART_PRINT("Failed to establish connection w/ an AP \n\r"); LOOP_FOREVER(); } UART_PRINT("Connection established w/ AP and IP is aquired \n\r"); gizwits_main(); }
static void WlanConnect_test(void) { DWORD ret; WLAN_CONNECTION_PARAMETERS pConnectParams; /* invalid pReserved */ ret = WlanConnect((HANDLE) -1, &InterfaceGuid, &pConnectParams, (PVOID) 1); ok(ret == ERROR_INVALID_PARAMETER, "expected failure\n"); /* invalid InterfaceGuid */ ret = WlanConnect((HANDLE) -1, NULL, &pConnectParams, NULL); ok(ret == ERROR_INVALID_PARAMETER, "expected failure\n"); /* invalid hClientHandle */ ret = WlanConnect(NULL, &InterfaceGuid, &pConnectParams, NULL); ok(ret == ERROR_INVALID_PARAMETER, "expected failure\n"); /* invalid connection parameters */ ret = WlanConnect((HANDLE) -1, &InterfaceGuid, NULL, NULL); ok(ret == ERROR_INVALID_PARAMETER, "expected failure\n"); }
// "Embedded Systems: Real Time Interfacing to ARM Cortex M Microcontrollers", // ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2014, Volume 2, Program 11.3 int main3(void){ UINT8 IsDHCP = 0; _NetCfgIpV4Args_t ipV4; SlSockAddrIn_t Addr, LocalAddr; UINT16 AddrSize = 0; INT16 SockID = 0; INT16 Status = 1; // ok UINT32 data; unsigned char len = sizeof(_NetCfgIpV4Args_t); initClk(); // PLL 50 MHz, ADC needs PPL active 16 ST7735_InitR(INITR_REDTAB); // Initialize 17 ST7735_OutString("Internet of Things\n"); // 18 ST7735_OutString("Embedded Systems\n"); // 19 ST7735_OutString("Vol. 2, Valvano"); // 20 ST7735_PlotClear(0,4095); // range from 0 to 4095 21 sl_Start(0, 0, 0); // Initializing the CC3100 device 22 WlanConnect(); // connect to AP 23 sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len, // 24 (unsigned char *)&ipV4); // 25 LocalAddr.sin_family = SL_AF_INET; // 26 LocalAddr.sin_port = sl_Htons((UINT16)PORT_NUM); // 27 LocalAddr.sin_addr.s_addr = 0; // 28 AddrSize = sizeof(SlSockAddrIn_t); // 29 while(1){ SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); // 31 Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, // 32 AddrSize); // 33 Status = sl_RecvFrom(SockID, uBuf, BUF_SIZE, 0, // 34 (SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize );// 35 if((uBuf[0]==ATYPE)&&(uBuf[1]== '=')){ // 36 int i,bOk; uint32_t place; // 37 data = 0; bOk = 1; // 38 i=4; // ignore possible negative sign 39 for(place = 1000; place; place = place/10){ // 40 if((uBuf[i]&0xF0)==0x30){ // ignore spaces 41 data += place*(uBuf[i]-0x30); // 42 }else{ // 43 if((uBuf[i]&0xF0)!= ' '){ // 44 bOk = 0; // 45 } // 46 } // 47 i++; // 48 } // 49 if(bOk){ // 50 ST7735_PlotLine(data); // 51 ST7735_PlotNextErase(); // 51 } } } }
void wififriend_connect_to_unsecure_network(GtkWidget* Widget, gpointer Data) { t_wifi Unsecure; DWORD Error = ERROR_SUCCESS; WLAN_CONNECTION_PARAMETERS Connect; Unsecure = wififriend_create_handle(); Unsecure = wififriend_retrieve_config(Unsecure); memset(&Connect, 0, sizeof(WLAN_CONNECTION_PARAMETERS)); Connect.wlanConnectionMode = wlan_connection_mode_discovery_unsecure; Connect.strProfile = NULL; Connect.pDot11Ssid = NULL; Connect.pDesiredBssidList = 0; Connect.dot11BssType = dot11_BSS_type_infrastructure; Connect.dwFlags = WLAN_CONNECTION_IGNORE_PRIVACY_BIT; if((Error = WlanConnect(Unsecure.MyHandle, &Unsecure.MyGuid, &Connect, NULL)) != ERROR_SUCCESS) error_unauthorized_connect(0); WlanCloseHandle(Unsecure.MyHandle, NULL); }
int wififriend_connect_secure_network(HANDLE Handle, const GUID *Id, char *Strxml) { DWORD Error = ERROR_SUCCESS; WLAN_CONNECTION_PARAMETERS Connect; int Size; BSTR UnicodeStr; memset(&Connect, 0, sizeof(WLAN_CONNECTION_PARAMETERS)); Connect.wlanConnectionMode = wlan_connection_mode_profile; Size = lstrlenA(Strxml); UnicodeStr = SysAllocStringLen(NULL, Size); MultiByteToWideChar(CP_ACP, 0, Strxml, Size, UnicodeStr, Size); Connect.strProfile = UnicodeStr; Connect.pDot11Ssid = NULL; Connect.pDesiredBssidList = NULL; Connect.dot11BssType = dot11_BSS_type_any; Connect.dwFlags = 0; if ((Error = WlanConnect(Handle, Id, &Connect, NULL)) != ERROR_SUCCESS) switch(Error) { case ERROR_INVALID_HANDLE: error_invalid_handle(0); break; case ERROR_ACCESS_DENIED: error_unauthorized_connect(0); break; case ERROR_INVALID_PARAMETER: error_parameters_connect(0); break; default: error_connect_unknow(0); } else error_connect_success(0, (char *)UnicodeStr); WlanCloseHandle(Handle, NULL); return (0); }
//**************************************************************************** // MAIN FUNCTION //**************************************************************************** int main(void) { long lRetVal; char cCmdBuff[20]; signed char cCmd = APP_SLEEP; SlSockAddrIn_t sAddr; SlSockAddrIn_t sLocalAddr; SlSockAddrIn_t sBrdAddr; int iCounter; int iAddrSize; int iSockID; int iStatus; long lLoopCount = 0; short sTestBufLen; struct SlTimeval_t timeVal; // // Board Initialization // BoardInit(); // // uDMA Initialization // UDMAInit(); // // Configure the pinmux settings for the peripherals exercised // Note: pinmux has been modified after the output from pin mux tools // to enable sleep clk for the peripherals exercised // PinMuxConfig(); // // Initialize the platform // platform_init(); // // Initialise the UART terminal // InitTerm(); // // Display banner // DisplayBanner(); // // starting the simplelink // lRetVal = sl_Start(NULL, NULL, NULL); if (lRetVal < 0) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(); } // // Swtich to STA mode if device is not // SwitchToStaMode(lRetVal); // // set connection policy // sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(0, 0, 0, 0, 0), NULL, 0); // // Set the power management policy of NWP // lRetVal = sl_WlanPolicySet(SL_POLICY_PM, SL_NORMAL_POLICY, NULL, 0); UART_PRINT("Trying to Connect to AP: %s ...\r\n",SSID_NAME); // //Connecting to WLAN AP // lRetVal = WlanConnect(); if(lRetVal < 0) { UART_PRINT("Failed to establish connection w/ an AP \n\r"); LOOP_FOREVER(); } // filling the buffer for (iCounter=0 ; iCounter<BUF_SIZE ; iCounter++) { g_cBsdBuf[iCounter] = (char)(iCounter % 10); } sTestBufLen = BUF_SIZE; //filling the UDP server socket address sLocalAddr.sin_family = SL_AF_INET; sLocalAddr.sin_port = sl_Htons((unsigned short)PORT_NUM); sLocalAddr.sin_addr.s_addr = 0; //filling the UDP server socket address sBrdAddr.sin_family = SL_AF_INET; sBrdAddr.sin_port = sl_Htons((unsigned short)PORT_NUM); sBrdAddr.sin_addr.s_addr = sl_Htonl((unsigned int)g_ulDestinationIp); iAddrSize = sizeof(SlSockAddrIn_t); // creating a UDP socket iSockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); /* setting time out for socket recv */ timeVal.tv_sec = 5; // Seconds timeVal.tv_usec = 0; // Microseconds. 10000 microseconds resolution sl_SetSockOpt(iSockID,SL_SOL_SOCKET,SL_SO_RCVTIMEO, (_u8 *)&timeVal, sizeof(timeVal)); // binding the UDP socket to the UDP server address iStatus = sl_Bind(iSockID, (SlSockAddr_t *)&sLocalAddr, iAddrSize); if( iStatus < 0 ) { // error sl_Close(iSockID); ASSERT_ON_ERROR(iStatus); } // // setting Apps power policy // lp3p0_setup_power_policy(POWER_POLICY_STANDBY); UART_PRINT("enter one of the following command:\n\r"); UART_PRINT("sleep - for putting the system into LPDS mode\n\r"); UART_PRINT(" GPIO 13 and timer(5 sec) are the wk source configured\n\r"); UART_PRINT("recv - for receiving 1000 UDP packets\n\r"); UART_PRINT("send - for broadcasting 1000 UDP packets\n\r"); do{ UART_PRINT("cmd#"); // // get cmd over UART // GetCmd(cCmdBuff, 20); // // parse the command // ParseCmd(cCmdBuff, &cCmd); if(cCmd == APP_SLEEP) { // // set timer and gpio as wake src // set_rtc_as_wk_src(WK_LPDS, LPDS_DUR_SEC, false); set_gpio_as_wk_src(WK_LPDS, GPIO_SRC_WKUP, PRCM_LPDS_FALL_EDGE); cc_idle_task_pm(); } else if(cCmd == APP_RECV) { lLoopCount = 0; /// waits for 1000 packets from a UDP client while (lLoopCount < g_ulPacketCount) { iStatus = sl_RecvFrom(iSockID, g_cBsdBuf, sTestBufLen, 0, ( SlSockAddr_t *)&sAddr, (SlSocklen_t*)&iAddrSize ); if( iStatus < 0 ) { //error break; } lLoopCount++; } UART_PRINT("Recieved %u packets successfully \n\r",lLoopCount); if(lLoopCount != g_ulPacketCount) { if(iStatus == SL_EAGAIN) { UART_PRINT("timed out\n\r"); } else { UART_PRINT("recv error: %d\n\r", iStatus); } } } else if(cCmd == APP_SEND) { lLoopCount = 0; // sending 1000 packets to the UDP server while (lLoopCount < g_ulPacketCount) { // sending packet iStatus = sl_SendTo(iSockID, g_cBsdBuf, sTestBufLen, 0, (SlSockAddr_t *)&sBrdAddr, iAddrSize); if( iStatus <= 0 ) { // error UART_PRINT("send error\n\r"); break; } lLoopCount++; } UART_PRINT("Sent %u packets successfully\n\r",lLoopCount); } }while(FOREVER); }
//***************************************************************************** // //! Function to connect to server and download the requested file //! //! \param none //! //! \return Error-code or SUCCESS //! //***************************************************************************** static long ServerFileDownload() { long lRetVal = -1; struct sockaddr_in addr; HTTPCli_Struct cli; // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its desired state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // lRetVal = ConfigureSimpleLinkToDefaultState(); if(lRetVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == lRetVal) { UART_PRINT("Failed to configure the device in its default state, " "Error-code: %d\n\r", DEVICE_NOT_IN_STATION_MODE); } LOOP_FOREVER(); } UART_PRINT("Device is configured in default state \n\r"); // // Assumption is that the device is configured in station mode already // and it is in its default state // lRetVal = sl_Start(0, 0, 0); if (lRetVal < 0 || ROLE_STA != lRetVal) { ASSERT_ON_ERROR(DEVICE_START_FAILED); } UART_PRINT("Device started as STATION \n\r"); // Connecting to WLAN AP - Set with static parameters defined at the top // After this call we will be connected and have IP address lRetVal = WlanConnect(); UART_PRINT("Connected to the AP: %s\r\n", SSID_NAME); lRetVal = sl_NetAppDnsGetHostByName((signed char *)HOST_NAME, strlen((const char *)HOST_NAME), &g_ulDestinationIP,SL_AF_INET); if(lRetVal < 0) { ASSERT_ON_ERROR(GET_HOST_IP_FAILED); } // Set up the input parameters for HTTP Connection addr.sin_family = AF_INET; addr.sin_port = htons(HOST_PORT); addr.sin_addr.s_addr = sl_Htonl(g_ulDestinationIP); // Testing HTTPCli open call: handle, address params only HTTPCli_construct(&cli); lRetVal = HTTPCli_connect(&cli, (struct sockaddr *)&addr, 0, NULL); if (lRetVal < 0) { UART_PRINT("Connection to server failed\n\r"); ASSERT_ON_ERROR(SERVER_CONNECTION_FAILED); } else { UART_PRINT("Connection to server created successfully\r\n"); } // Download the file, verify the file and replace the exiting file lRetVal = GetData(&cli); if(lRetVal < 0) { UART_PRINT("Device couldn't download the file from the server\n\r"); } HTTPCli_destruct(&cli); return SUCCESS; }
//***************************************************************************** // //! \brief Task Created by main fucntion.This task starts simpleink, set NWP //! power policy, connects to an AP. Give Signal to the other task about //! the connection.wait for the message form the interrupt handlers and //! the other task. Accordingly print the wake up cause from the low //! power modes. //! //! \param pvParameters is a general void pointer (not used here). //! //! \return none // //***************************************************************************** void TimerGPIOTask(void *pvParameters) { cc_hndl tTimerHndl = NULL; cc_hndl tGPIOHndl = NULL; unsigned char ucQueueMsg = 0; unsigned char ucSyncMsg = 0; int iRetVal = 0; // // Displays the Application Banner // DisplayBanner(); // // creating the queue for signalling about connection events // iRetVal = osi_MsgQCreate(&g_tConnection, NULL, sizeof( unsigned char ), 3); if (iRetVal < 0) { UART_PRINT("unable to create the msg queue\n\r"); LOOP_FOREVER(); } // // starting the simplelink // iRetVal = sl_Start(NULL, NULL, NULL); if (iRetVal < 0) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(); } // // Swtich to STA mode if device is not // SwitchToStaMode(iRetVal); // // Set the power management policy of NWP // iRetVal = sl_WlanPolicySet(SL_POLICY_PM, SL_NORMAL_POLICY, NULL, 0); if (iRetVal < 0) { UART_PRINT("unable to configure network power policy\n\r"); LOOP_FOREVER(); } // // connecting to the Access Point // if(-1 == WlanConnect()) { sl_Stop(SL_STOP_TIMEOUT); UART_PRINT("Connection to AP failed\n\r"); } else { UART_PRINT("Connected to AP\n\r"); // //signal the other task about the sl start and connection to the AP // iRetVal = osi_MsgQWrite(&g_tConnectionFlag, &ucSyncMsg, OSI_WAIT_FOREVER); if (iRetVal < 0) { UART_PRINT("unable to create the msg queue\n\r"); LOOP_FOREVER(); } } // // Queue management related configurations // iRetVal = osi_MsgQCreate(&g_tWkupSignalQueue, NULL, sizeof( unsigned char ), 10); if (iRetVal < 0) { UART_PRINT("unable to create the msg queue\n\r"); LOOP_FOREVER(); } // // setting Timer as one of the wakeup source // tTimerHndl = SetTimerAsWkUp(); // // setting some GPIO as one of the wakeup source // tGPIOHndl = SetGPIOAsWkUp(); /* handles, if required, can be used to stop the timer, but not used here*/ UNUSED(tTimerHndl); UNUSED(tGPIOHndl); // // setting Apps power policy // lp3p0_setup_power_policy(POWER_POLICY_STANDBY); while(FOREVER) { // // waits for the message from the various interrupt handlers(GPIO, // Timer) and the UDPServerTask. // osi_MsgQRead(&g_tWkupSignalQueue, &ucQueueMsg, OSI_WAIT_FOREVER); switch(ucQueueMsg){ case 1: UART_PRINT("timer\n\r"); break; case 2: UART_PRINT("GPIO\n\r"); break; case 3: UART_PRINT("host irq\n\r"); break; default: UART_PRINT("invalid msg\n\r"); break; } } }
int main2(void) { UINT8 IsDHCP = 0; int32_t i32CommandStatus; _NetCfgIpV4Args_t ipV4; unsigned char len = sizeof(_NetCfgIpV4Args_t); int Status = 0; /* Stop WDT */ stopWDT(); /* Initialize the system clock of MCU */ initClk(); Board_Init(); // initialize LaunchPad I/O and PD1 LED ConfigureUART(); // Initialize the UART. UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n"); UARTprintf("This application is configured to measure analog signals from Ain7=PD0\n"); UARTprintf(" and send UDP packets to IP: %d.%d.%d.%d Port: %d\n\n", SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM); /* Initializing the CC3100 device */ sl_Start(0, 0, 0); /* Connecting to WLAN AP - Set with static parameters defined at the top After this call we will be connected and have IP address */ WlanConnect(); /* Read the IP parameter */ sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len, (unsigned char *)&ipV4); //Print the IP UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0)); // // Loop forever waiting for commands from PC... // while(1) { // // Print prompt for user. // UARTprintf("\n>"); // // Peek to see if a full command is ready for processing. // while(UARTPeek('\r') == -1) { // // Approximately 1 millisecond delay. // ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3000); } // // A '\r' was detected so get the line of text from the receive buffer. // UARTgets(g_cInput,sizeof(g_cInput)); // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // i32CommandStatus = CmdLineProcess(g_cInput); // // Handle the case of bad command. // if(i32CommandStatus == CMDLINE_BAD_CMD) { UARTprintf(" Bad command. Try again.\n"); } // // Handle the case of too many arguments. // else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf(" Too many arguments for command. Try again.\n"); } // // Handle the case of too few arguments. // else if(i32CommandStatus == CMDLINE_TOO_FEW_ARGS) { UARTprintf(" Too few arguments for command. Try again.\n"); } // // Handle the case of too few arguments. // else if(i32CommandStatus == CMDLINE_INVALID_ARG) { UARTprintf(" Invalid command argument(s). Try again.\n"); } } }
int main() { long lRetVal = -1; // // Initialize Board configurations // BoardInit(); // // Pinmuxing for GPIO, UART // PinMuxConfig(); // // configure LEDs // GPIO_IF_LedConfigure(LED1|LED2|LED3); // off all LEDs GPIO_IF_LedOff(MCU_ALL_LED_IND); #ifndef NOTERM // // Configuring UART // InitTerm(); #endif // // Display the Application Banner // DisplayBanner(APP_NAME); UART_PRINT("Scan Wi-FI direct device in your handheld device\n\r"); // Initializing the CC3200 device lRetVal = StartDeviceInP2P(); if(lRetVal < 0) { UART_PRINT("Start Device in P2P mode failed \n\r"); LOOP_FOREVER(); } lRetVal = P2PConfiguration(); if(lRetVal < 0) { UART_PRINT("Setting P2P configuration failed\n\r"); LOOP_FOREVER(); } /* Connect to configure P2P device */ lRetVal = WlanConnect(); if(lRetVal == 0) { GPIO_IF_LedOn(MCU_IP_ALLOC_IND); } else { UART_PRINT("Reset the device and try again\n\r"); LOOP_FOREVER(); } if(DisplayIP() < 0) { UART_PRINT("Get IP address failed \n\r"); LOOP_FOREVER(); } UART_PRINT("Send TCP packets from your handheld device to CC3200's IP\n\r"); /*After calling this function, you can start sending data to CC3200 IP * address on PORT_NUM */ if(!(IS_CONNECT_FAILED(g_ulStatus))) { lRetVal = BsdTcpServer(PORT_NUM); if(lRetVal >= 0) { UART_PRINT("Received TCP packets successfully \n\r"); } else if(lRetVal == CLIENT_DISCONNECTED) { UART_PRINT("P2P Client disconnected \n\r"); } else { UART_PRINT("TCP packets receive failed \n\r"); } } if(lRetVal >=0) { UART_PRINT("Test passed, exiting application... \n\r"); } else { UART_PRINT("Test failed, exiting application... \n\r"); } // revert Device into STA mode and power off Network Processor lRetVal = sl_WlanSetMode(ROLE_STA); if(lRetVal < 0) { ERR_PRINT(lRetVal); LOOP_FOREVER(); } lRetVal = sl_Stop(SL_STOP_TIMEOUT); GPIO_IF_LedOff(MCU_IP_ALLOC_IND); while(1) { _SlNonOsMainLoopTask(); } }
//***************************************************************************** // //! NwpFilter - Function which Creates and Enables the Filter //! //! \param pvParameters //! //! \return 0 //! //***************************************************************************** static int NwpFilter(void *pvParameters) { long lRetVal = 0; InitializeAppVariables(); // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its default state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // lRetVal = ConfigureSimpleLinkToDefaultState(); if(lRetVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == lRetVal) { UART_PRINT("Failed to configure the device in its default state\n\r"); } LOOP_FOREVER(); } UART_PRINT("Device is configured in default state \n\r"); // // Assumption is that the device is configured in station mode already // and it is in its default state // lRetVal = sl_Start(0, 0, 0); if (lRetVal < 0 || ROLE_STA != lRetVal) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(); } UART_PRINT("Device started as STATION \n\r"); // // Reset policy settings // lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, \ SL_CONNECTION_POLICY(0,0,0,0,0), 0, 0); // // This function creates two different filters: // (1) Filter packets according to remote MAC // (2) Filter packets according to remote IP address // lRetVal=CreateFilters(); if (lRetVal < 0) { UART_PRINT("Filter creation failed\n\r"); LOOP_FOREVER(); } // // Activate pre-defined filters - The filters will be deleted upon reset // if(EnableAllFilters() < 0) { UART_PRINT("Unable to enable filter \n\r"); LOOP_FOREVER(); } // //Connecting to WLAN AP // lRetVal = WlanConnect(); if(lRetVal < 0) { UART_PRINT("Failed to establish connection w/ an AP \n\r"); LOOP_FOREVER(); } UART_PRINT("Connection established w/ AP and IP is aquired \n\r"); // // After calling this function, you can start sending data to CC3200 IP // address on PORT_NUM TCP connection will be refused if remote MAC/IP is of // the filtered. It's also possible to enable the filters after TCP // connection, resulting in TCP packets to not being received // lRetVal = BsdTcpServer(PORT_NUM); if(lRetVal < 0) { UART_PRINT("Failure in TCP server\n\r"); LOOP_FOREVER(); } // // Power off Network processor // lRetVal = sl_Stop(SL_STOP_TIMEOUT); return 0; }
int main(void) { UINT8 IsDHCP = 0; int32_t i32CommandStatus; _NetCfgIpV4Args_t ipV4; SlSockAddrIn_t Addr; UINT16 AddrSize = 0; INT16 SockID = 0; UINT32 data; long x = 0; //counter unsigned char len = sizeof(_NetCfgIpV4Args_t); int Status = 0; /* Stop WDT */ stopWDT(); /* Initialize the system clock of MCU */ initClk(); Board_Init(); // initialize LaunchPad I/O and PD1 LED ConfigureUART(); // Initialize the UART. UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n"); UARTprintf("This application is configured to generate text\n"); UARTprintf(" and send UDP packets to IP: %d.%d.%d.%d Port: %d\n\n", SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM); //added code from the powerpoint slide /* Initializing the CC3100 device */ sl_Start(0, 0, 0); /* Connecting to WLAN AP - Set with static parameters defined at the top After this call we will be connected and have IP address */ WlanConnect(); /* Read the IP parameter */ sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4); UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0)); Addr.sin_family = SL_AF_INET; Addr.sin_port = sl_Htons((UINT16)PORT_NUM); Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR); AddrSize = sizeof(SlSockAddrIn_t); SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); // Loop forever waiting for commands from PC... // while(1) { // Print prompt for user. UARTprintf("\n>"); // Peek to see if a full command is ready for processing. while(UARTPeek('\r') == -1) LED_On(); // Approximately 1 millisecond delay. ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3000); } // A '\r' was detected so get the line of text from the receive buffer. while(Status >= 0){ UARTprintf("\nSending a UDP packet ...\n"); UARTgets(g_cInput,sizeof(g_cInput)); //this function receives the input from the Putty and places it in a string //DO NOT CHANGE ANYTHING ABOVE THIS COMMENT //WHAT WE NEED TO DO: //work with the g_cInput to get the array of letters typed into the Putty //then send that Array using UARTprintf uBuf[0] = ATYPE; // defines this as an analog data type uBuf[1] = '='; data = 1000; Int2Str(data,(char*)&uBuf[2]); // [2] to [7] is 6 digit number UARTprintf(" %s ",uBuf); //this line sends a string to the receiver //the above 5 lines print out a = 1000; //everything below this is just error cases if( SockID < 0 ){ UARTprintf("SockIDerror "); Status = -1; // error }else{ LED_Toggle(); Status = sl_SendTo(SockID, uBuf, BUF_SIZE, 0, (SlSockAddr_t *)&Addr, AddrSize); if( Status <= 0 ){ sl_Close(SockID); UARTprintf("SockIDerror %d ",Status); }else{ UARTprintf("ok"); } } ROM_SysCtlDelay(ROM_SysCtlClockGet() / 100); // 10ms LED_Off(); } }
//**************************************************************************** // MAIN FUNCTION //**************************************************************************** void main() { long lRetVal = 0; char data[BUF_SIZE]; char sent_data[BUF_SIZE]; unsigned char highByte, lowByte; int i; unsigned long tempStartTimeStamp, tempStopTimeStamp; memset(sent_data, 0, 10); // Board Initialization BoardInit(); // Configure the pinmux settings for the peripherals exercised PinMuxConfig(); // Initialize the PWM outputs on the board InitServos(); // Initialize the sensor ADC InitSensorADC(); // Configuring UART InitTerm(); // Display banner DisplayBanner(APPLICATION_NAME); // Connect to WIFI using default info //WlanConnect(NULL, NULL, NULL); WlanConnect("Nagui's Network", "SL_SEC_TYPE_WPA", "19520605"); // Setup the TCP Server Socket BsdTcpServerSetup(PORT_NUM); // Recieve Data while (lRetVal >= 0) { lRetVal = BsdTcpServerReceive(data); //SysTickPeriodSet(800000000); // test //SysTickEnable(); // test Timer_IF_Init(PRCM_TIMERA0, TIMERA0_BASE, TIMER_CFG_PERIODIC, TIMER_A, 0); Timer_IF_Start(TIMERA0_BASE, TIMER_A, MILLISECONDS_TO_TICKS(2000)); //tempStartTimeStamp = SysTickValueGet(); // test tempStartTimeStamp = Timer_IF_GetCount(TIMERA0_BASE, TIMER_A); for (i = 0; i<NUM_SERVOS; i++) { MoveServo((unsigned char)data[i], (enum Servo_Joint_Type)i); UART_PRINT("%d", (unsigned int) data[i]); } for (i = 0; i< NUM_SENSORS; i++) { //UnsignedShort_to_UnsignedChar(GetSensorReading((enum Fingertip_Sensor_Type)i), &highByte, &lowByte); UnsignedShort_to_UnsignedChar(GetSensorReading(SENSOR_FINGER_INDEX), &highByte, &lowByte); sent_data[i*2] = (char)highByte; sent_data[i*2+1] = (char)lowByte; } //tempStopTimeStamp = SysTickValueGet(); // test tempStopTimeStamp = Timer_IF_GetCount(TIMERA0_BASE, TIMER_A); lRetVal = BsdTcpServerSend(sent_data, 10); UART_PRINT("timestamp start: %lu\n\r", tempStartTimeStamp); //test UART_PRINT("timestamp stop: %lu\n\r", tempStopTimeStamp); //test UART_PRINT("Sent 10 bytes to client.\n\r"); } UART_PRINT("Exiting Application ...\n\r"); // power of the Network processor lRetVal = sl_Stop(SL_STOP_TIMEOUT); }
//**************************************************************************** // //! \brief Start simplelink, connect to the ap and run the ping test //! //! This function starts the simplelink, connect to the ap and start the ping //! test on the default gateway for the ap //! //! \param[in] pvParameters - Pointer to the list of parameters that //! can bepassed to the task while creating it //! //! \return None // //**************************************************************************** void WlanStationMode( void *pvParameters ) { long lRetVal = -1; InitializeAppVariables(); // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its default state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // lRetVal = ConfigureSimpleLinkToDefaultState(); if(lRetVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == lRetVal) { UART_PRINT("Failed to configure the device in its default state\n\r"); } LOOP_FOREVER(); } UART_PRINT("Device is configured in default state \n\r"); // // Assumption is that the device is configured in station mode already // and it is in its default state // lRetVal = sl_Start(0, 0, 0); if (lRetVal < 0 || ROLE_STA != lRetVal) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(); } UART_PRINT("Device started as STATION \n\r"); // //Connecting to WLAN AP // lRetVal = WlanConnect(); if(lRetVal < 0) { UART_PRINT("Failed to establish connection w/ an AP \n\r"); LOOP_FOREVER(); } UART_PRINT("Connection established w/ AP and IP is aquired \n\r"); UART_PRINT("Pinging...! \n\r"); // // Checking the Lan connection by pinging to AP gateway // lRetVal = CheckLanConnection(); if(lRetVal < 0) { UART_PRINT("Device couldn't ping the gateway \n\r"); LOOP_FOREVER(); } // Turn on GREEN LED when device gets PING response from AP GPIO_IF_LedOn(MCU_EXECUTE_SUCCESS_IND); // // Checking the internet connection by pinging to external host // lRetVal = CheckInternetConnection(); if(lRetVal < 0) { UART_PRINT("Device couldn't ping the external host \n\r"); LOOP_FOREVER(); } // Turn on ORAGE LED when device gets PING response from AP GPIO_IF_LedOn(MCU_ORANGE_LED_GPIO); UART_PRINT("Device pinged both the gateway and the external host \n\r"); UART_PRINT("WLAN STATION example executed successfully \n\r"); // // power off the network processor // lRetVal = sl_Stop(SL_STOP_TIMEOUT); LOOP_FOREVER(); }
int main(void){ int32_t retVal = 0; char *pConfig = NULL; retVal = initializeAppVariables(); stopWDT(); // Stop WDT initClk(); // PLL 50 MHz LCD_Init(); LED_Init(); // initialize LaunchPad I/O // LCD_OutString("Weather App\n"); LCD_OutString("Lab 16 IoT\n"); /* * Following function configures the device to default state by cleaning * the persistent settings stored in NVMEM (viz. connection profiles & * policies, power policy etc) * * Applications may choose to skip this step if the developer is sure * that the device is in its default state at start of application * * Note that all profiles and persistent settings that were done on the * device will be lost */ retVal = configureSimpleLinkToDefaultState(pConfig); if(retVal < 0){ if(DEVICE_NOT_IN_STATION_MODE == retVal){ LCD_OutString(" Failed to configure the device in its default state \r\n"); Crash(4000000); } } /* * Assumption is that the device is configured in station mode already * and it is in its default state */ retVal = sl_Start(0, pConfig, 0); if((retVal < 0) || (ROLE_STA != retVal) ){ LCD_OutString(" Failed to start the device \r\n"); Crash(8000000); } WlanConnect(); LCD_OutString("Connected\n"); /* Get weather report */ while(1){ Nokia5110_SetCursor(0,2); // retVal = getWeather(); retVal = Lab16(); if(retVal == 0){ // valid LED_GreenOn(); UARTprintf("\r\n\r\n"); UARToutString(appData.Recvbuff); UARTprintf("\r\n"); // LCD_OutString(City); LCD_OutString("\n"); // LCD_OutString(Temperature); LCD_OutString(" C\n"); // LCD_OutString(Weather); LCD_OutString(Id); LCD_OutString("\n"); LCD_OutString(Score); LCD_OutString("\n"); LCD_OutString(Edxpost); } while(Board_Input()==0){}; // wait for touch LED_GreenOff(); } }
void ControlServer(void *pvParameters) { char ServerBuffer[CONFIG_SERVER_BUFFER]; char MsgBuffer[100]; char *pMsgBuffer; SlSockAddrIn_t sAddr; SlSockAddrIn_t sLocalAddr; int32_t i32SockID; int32_t i32NewSockID; int32_t i32DataSize; int32_t i32NonBlocking = 1; SlSocklen_t i32AddrSize; int32_t retval; pMsgBuffer = &MsgBuffer[0]; InitVariables(); retval = ResetSimpleLink(); if (retval < 0) while (1) ; WlanConnect(); sprintf(MsgBuffer, "Connectado a rede: %s\n\r" "IP: %d.%d.%d.%d\n\r" "Gateway: %d.%d.%d.%d\n\r", SL_IPV4_BYTE(g_sSLCon.DeviceIP, 3), SL_IPV4_BYTE(g_sSLCon.DeviceIP, 2), SL_IPV4_BYTE(g_sSLCon.DeviceIP, 1), SL_IPV4_BYTE(g_sSLCon.DeviceIP, 0), SL_IPV4_BYTE(g_sSLCon.GatewayIP, 3), SL_IPV4_BYTE(g_sSLCon.GatewayIP, 2), SL_IPV4_BYTE(g_sSLCon.GatewayIP, 1), SL_IPV4_BYTE(g_sSLCon.GatewayIP, 0)); osi_MsgQWrite(&g_sUartQuee, &pMsgBuffer, OSI_NO_WAIT); sLocalAddr.sin_family = SL_AF_INET; sLocalAddr.sin_port = sl_Htons((unsigned short) g_sSLCon.PortNumber); sLocalAddr.sin_addr.s_addr = 0; i32SockID = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, 0); sl_Bind(i32SockID, (SlSockAddr_t *) &sLocalAddr, sizeof(SlSockAddrIn_t)); sl_Listen(i32SockID, 0); sl_SetSockOpt(i32SockID, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &i32NonBlocking, sizeof(i32NonBlocking)); while (1) { i32NewSockID = SL_EAGAIN; while (i32NewSockID < 0) { i32NewSockID = sl_Accept(i32SockID, (struct SlSockAddr_t *) &sAddr, (SlSocklen_t*) &i32AddrSize); if (i32NewSockID == SL_EAGAIN) { osi_Sleep(100); } else if (i32NewSockID < 0) { while (1) { } } } i32DataSize = sl_Recv(i32NewSockID, ServerBuffer, CONFIG_SERVER_BUFFER, 0); if (strcmp(ServerBuffer, "Led On") == 0) { Led_Green(LED_ON); strcpy(ServerBuffer, "OK"); i32DataSize = 3; } else if (strcmp(ServerBuffer, "Led Off") == 0) { Led_Green(LED_OFF); strcpy(ServerBuffer, "OK"); i32DataSize = 3; } else if (strcmp(ServerBuffer, "Lamp On") == 0) { MAP_GPIOPinWrite(GPIOA0_BASE, GPIO_PIN_6, GPIO_PIN_6); strcpy(ServerBuffer, "OK"); i32DataSize = 3; } else if (strcmp(ServerBuffer, "Lamp Off") == 0) { MAP_GPIOPinWrite(GPIOA0_BASE, GPIO_PIN_6, 0); strcpy(ServerBuffer, "OK"); i32DataSize = 3; } sl_Send(i32NewSockID, ServerBuffer, i32DataSize, 0); sl_Close(i32NewSockID); } }
//**************************************************************************** // //! Task function implements the Antenna Selection functionality //! //! \param none //! //! This function //! 1. Starts Device in STA Mode //! 2. Scans, Sort and Stores all the AP with Antenna 1 //! 3. Scans, Sort and Stores all the AP with Antenna 2 //! 4. Switch to AP Mode and Wait for AP Configuration from Browser //! 5. Switch to STA Mode and Connect to Configured AP with Selected Antenna //! //! \return None. // //**************************************************************************** void AntennaSelection(void* pTaskParams) { int iDeviceMode = 0; unsigned char ucCountSSID; unsigned char ucCountSSIDAnt2; long lRetVal = -1; InitializeAppVariables(); // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its default state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // lRetVal = ConfigureSimpleLinkToDefaultState(); if(lRetVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == lRetVal) { UART_PRINT("Failed to configure the device in its default state\n\r"); } LOOP_FOREVER(__LINE__); } UART_PRINT("Device is configured in default state \n\r"); // // Assumption is that the device is configured in station mode already // and it is in its default state // lRetVal = sl_Start(0, 0, 0); if (lRetVal < 0 || ROLE_STA != lRetVal) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(__LINE__); } UART_PRINT("Device started as STATION \n\r"); // // Start the driver // iDeviceMode = InitDriver(); if (iDeviceMode == ROLE_AP) { //Device in AP Mode, Wait for Initialization to Complete while (g_ucIpObtained == 0) { MAP_UtilsDelay(100); } } sl_WlanSetMode(ROLE_STA); if (iDeviceMode == ROLE_AP) DeInitDriverAP(); else DeInitDriver(); g_ucIpObtained = 0; g_ucConnectionStatus = 0; InitDriver(); //Select Antenna 1 AntennaSelect(1); //Get Scan Result ucCountSSID = GetScanResult(&g_netEntries[0]); //Select Antenna 2 AntennaSelect(2); //Get Scan Result ucCountSSIDAnt2 = GetScanResult(&g_netEntriesAnt2[0]); //Sort Scan Result SortByRSSI(&g_netEntries[0],ucCountSSID); SortByRSSI(&g_netEntriesAnt2[0],ucCountSSIDAnt2); while(!g_ucAntSelectDone) { //Switch to AP Mode sl_WlanSetMode(ROLE_AP); DeInitDriver(); g_ucIpObtained = 0; g_ucConnectionStatus = 0; //Initialize the SLHost Driver InitDriver(); //Wait for Ip Acquired Event in AP Mode while (g_ucIpObtained == 0) { MAP_UtilsDelay(100); } // // Wait for AP Configuraiton, Open Browser and Configure AP // while (g_ucProfileAdded && !g_ucAntSelectDone) { MAP_UtilsDelay(100); } g_ucProfileAdded = 1; //Switch to STA Mode sl_WlanSetMode(ROLE_STA); //AP Configured, Restart in STA Mode DeInitDriverAP(); g_ucIpObtained = 0; g_ucConnectionStatus = 0; //MAP_UtilsDelay(10000000); InitDriver(); // // Connect to the Configured Access Point // WlanConnect(); g_ucConnectedToConfAP = g_ucConnectionStatus; sl_WlanDisconnect(); } while (1) { } }
int main1(void){ UINT8 IsDHCP = 0; _NetCfgIpV4Args_t ipV4; SlSockAddrIn_t Addr; UINT16 AddrSize = 0; INT16 SockID = 0; INT16 Status = 1; // ok UINT32 data; unsigned char len = sizeof(_NetCfgIpV4Args_t); stopWDT(); // Stop WDT initClk(); // PLL 50 MHz, ADC needs PPL active Board_Init(); // initialize LaunchPad I/O ConfigureUART(); // Initialize the UART. UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n"); #if ADC ADC0_InitSWTriggerSeq3(7); // Ain7 is on PD0 UARTprintf("This node is configured to measure signals from Ain7=PD0\n"); #endif #if EKG UARTprintf("This node is configured to generate simulated EKG data\n"); #endif UARTprintf(" and send UDP packets to IP: %d.%d.%d.%d Port: %d\n\n", SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM); while(1){ sl_Start(0, 0, 0);/* Initializing the CC3100 device */ /* Connecting to WLAN AP - Set with static parameters defined at the top After this call we will be connected and have IP address */ WlanConnect(); // connect to AP /* Read the IP parameter */ sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4); UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0)); while(Status > 0){ Addr.sin_family = SL_AF_INET; Addr.sin_port = sl_Htons((UINT16)PORT_NUM); Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR); AddrSize = sizeof(SlSockAddrIn_t); SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); if( SockID < 0 ){ UARTprintf("SockIDerror "); Status = -1; // error }else{ while(Status>0){ UARTprintf("\nSending a UDP packet ..."); uBuf[0] = ATYPE; // defines this as an analog data type uBuf[1] = '='; #if ADC data = ADC0_InSeq3(); // 0 to 4095, Ain7 is on PD0 #endif #if EKG data = EKGbuf[EKGindex]; EKGindex = (EKGindex+1)%EKGSIZE; // 100 Hz #endif Int2Str(data,(char*)&uBuf[2]); // [2] to [7] is 6 digit number UARTprintf(" %s ",uBuf); LED_Toggle(); Status = sl_SendTo(SockID, uBuf, BUF_SIZE, 0, (SlSockAddr_t *)&Addr, AddrSize); ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25); // 80ms if( Status <= 0 ){ UARTprintf("SockIDerror %d ",Status); }else{ UARTprintf("ok"); } } sl_Close(SockID); } } } }
//**************************************************************************** // MAIN FUNCTION //**************************************************************************** void main() { long lRetVal = -1; // // Board Initialization // BoardInit(); // // uDMA Initialization // UDMAInit(); // // Configure the pinmux settings for the peripherals exercised // PinMuxConfig(); // // Configuring UART // InitTerm(); // // Display banner // DisplayBanner(APPLICATION_NAME); InitializeAppVariables(); // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its desired state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // lRetVal = ConfigureSimpleLinkToDefaultState(); if(lRetVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == lRetVal) UART_PRINT("Failed to configure the device in its default state \n\r"); LOOP_FOREVER(); } UART_PRINT("Device is configured in default state \n\r"); // // Asumption is that the device is configured in station mode already // and it is in its default state // lRetVal = sl_Start(0, 0, 0); if (lRetVal < 0 || lRetVal != ROLE_STA) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(); } UART_PRINT("Device started as STATION \n\r"); UART_PRINT("Connecting to AP: %s ...\r\n",SSID_NAME); // //Connecting to WLAN AP // lRetVal = WlanConnect(); if(lRetVal < 0) { UART_PRINT("Failed to establish connection w/ an AP \n\r"); LOOP_FOREVER(); } UART_PRINT("Connected to AP: %s \n\r",SSID_NAME); UART_PRINT("Device IP: %d.%d.%d.%d\n\r\n\r", SL_IPV4_BYTE(g_ulIpAddr,3), SL_IPV4_BYTE(g_ulIpAddr,2), SL_IPV4_BYTE(g_ulIpAddr,1), SL_IPV4_BYTE(g_ulIpAddr,0)); #ifdef USER_INPUT_ENABLE lRetVal = UserInput(); if(lRetVal < 0) { ERR_PRINT(lRetVal); LOOP_FOREVER(); } #else lRetVal = BsdUdpClient(PORT_NUM); if(lRetVal < 0) { ERR_PRINT(lRetVal); LOOP_FOREVER(); } lRetVal = BsdUdpServer(PORT_NUM); if(lRetVal < 0) { ERR_PRINT(lRetVal); LOOP_FOREVER(); } #endif UART_PRINT("Exiting Application ...\n\r"); // // power off the network processor // lRetVal = sl_Stop(SL_STOP_TIMEOUT); while (1) { _SlNonOsMainLoopTask(); } }
int main(void){ UINT8 IsDHCP = 0; _NetCfgIpV4Args_t ipV4; SlSockAddrIn_t Addr; SlSockAddrIn_t LocalAddr; UINT16 AddrSize = 0; INT16 SockID = 0; INT16 Status = 1; // ok UINT32 data; unsigned char len = sizeof(_NetCfgIpV4Args_t); stopWDT(); // Stop WDT initClk(); // PLL 50 MHz, ADC needs PPL active Board_Init(); // initialize LaunchPad I/O ConfigureUART(); // Initialize the UART. UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n"); UARTprintf("This node is configured to receive UDP packets\n"); UARTprintf("This node should be at IP: %d.%d.%d.%d Port: %d\n\n", SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM); ST7735_InitR(INITR_REDTAB); ST7735_OutString("Internet of Things\n"); ST7735_OutString("Embedded Systems\n"); ST7735_OutString("Vol. 2, Valvano"); ST7735_PlotClear(0,4095); // range from 0 to 4095 while(1){ sl_Start(0, 0, 0); /* Initializing the CC3100 device */ /* Connecting to WLAN AP - Set with static parameters defined at the top After this call we will be connected and have IP address */ WlanConnect(); // connect to AP /* Read the IP parameter */ sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4); UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0)); while(Status > 0){ UARTprintf("\nReceiving a UDP packet ..."); LocalAddr.sin_family = SL_AF_INET; LocalAddr.sin_port = sl_Htons((UINT16)PORT_NUM); LocalAddr.sin_addr.s_addr = 0; AddrSize = sizeof(SlSockAddrIn_t); SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); if( SockID < 0 ){ UARTprintf("SockIDerror\n"); Status = -1; // error }else{ Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize); if( Status < 0 ){ sl_Close(SockID); UARTprintf("Sock Bind error\n"); }else{ Status = sl_RecvFrom(SockID, uBuf, BUF_SIZE, 0, (SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize ); if( Status <= 0 ){ sl_Close(SockID); UARTprintf("Receive error %d ",Status); }else{ LED_Toggle(); sl_Close(SockID); UARTprintf("ok %s ",uBuf); if((uBuf[0]==ATYPE)&&(uBuf[1]== '=')){ int i,bOk; uint32_t place; data = 0; bOk = 1; i=4; // ignore possible negative sign for(place = 1000; place; place = place/10){ if((uBuf[i]&0xF0)==0x30){ // ignore spaces data += place*(uBuf[i]-0x30); }else{ if((uBuf[i]&0xF0)!= ' '){ bOk = 0; } } i++; } if(bOk){ ST7735_PlotLine(data); ST7735_PlotNextErase(); } } } } } ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25); // 120ms } } }
int connectToAccessPoint(){ long lRetVal = -1; GPIO_IF_LedConfigure(LED1|LED3); GPIO_IF_LedOff(MCU_RED_LED_GPIO); GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); lRetVal = InitializeAppVariables(); ASSERT_ON_ERROR(lRetVal); // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its default state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // lRetVal = ConfigureSimpleLinkToDefaultState(); if(lRetVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == lRetVal) UART_PRINT("Failed to configure the device in its default state \n\r"); return lRetVal; } UART_PRINT("Device is configured in default state \n\r"); CLR_STATUS_BIT_ALL(g_ulStatus); /// // Assumption is that the device is configured in station mode already // and it is in its default state // lRetVal = sl_Start(0, 0, 0); if (lRetVal < 0 || ROLE_STA != lRetVal) { UART_PRINT("Failed to start the device \n\r"); return lRetVal; } UART_PRINT("Device started as STATION \n\r"); // //Connecting to WLAN AP // lRetVal = WlanConnect(); if(lRetVal < 0) { UART_PRINT("Failed to establish connection w/ an AP \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } UART_PRINT("Connection established w/ AP and IP is aquired \n\r"); return 0; }
int main() { unsigned char ucP2PParam[4]; long lRetVal = -1; // // Initialize Board configurations // BoardInit(); // // Pinmuxing for GPIO, UART // PinMuxConfig(); // // configure LEDs // GPIO_IF_LedConfigure(LED1|LED2|LED3); // off all LEDs GPIO_IF_LedOff(MCU_ALL_LED_IND); #ifndef NOTERM // // Configuring UART // InitTerm(); #endif // // Display the Application Banner // DisplayBanner(APP_NAME); UART_PRINT("Scan Wi-FI direct device in your handheld device\n\r"); // Initializing the CC3200 device lRetVal = StartDeviceInP2P(); if(lRetVal < 0) { LOOP_FOREVER(__LINE__); } // Set any p2p option (SL_CONNECTION_POLICY(0,0,0,any_p2p,0)) to connect to // first available p2p device sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(1,0,0,0,0),NULL,0); // Set the negotiation role (SL_P2P_ROLE_NEGOTIATE). // CC3200 will negotiate with remote device GO/client mode. // Other valid options are: // - SL_P2P_ROLE_GROUP_OWNER // - SL_P2P_ROLE_CLIENT sl_WlanPolicySet(SL_POLICY_P2P, SL_P2P_POLICY(SL_P2P_ROLE_NEGOTIATE, SL_P2P_NEG_INITIATOR_ACTIVE),NULL,0); // Set P2P Device name sl_NetAppSet(SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, strlen(P2P_DEVICE_NAME), (unsigned char *)P2P_DEVICE_NAME); // Set P2P device type sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, WLAN_P2P_OPT_DEV_TYPE, strlen(P2P_CONFIG_VALUE), (unsigned char*)P2P_CONFIG_VALUE); // setting P2P channel parameters ucP2PParam[0] = LISENING_CHANNEL; ucP2PParam[1] = REGULATORY_CLASS; ucP2PParam[2] = OPERATING_CHANNEL; ucP2PParam[3] = REGULATORY_CLASS; // Set P2P Device listen and open channel valid channels are 1/6/11 sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, WLAN_P2P_OPT_CHANNEL_N_REGS, sizeof(ucP2PParam), ucP2PParam); // Restart as P2P device sl_Stop(SL_STOP_TIMEOUT); lRetVal = sl_Start(NULL,NULL,NULL); if(lRetVal < 0 || lRetVal != ROLE_P2P) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(__LINE__); } else { UART_PRINT("Connect to %s \n\r",P2P_DEVICE_NAME); } /* Connect to configure P2P device */ lRetVal = WlanConnect(); if(lRetVal == 0) { GPIO_IF_LedOn(MCU_IP_ALLOC_IND); } else { UART_PRINT("Reset the device and try again\n\r"); LOOP_FOREVER(__LINE__); } DisplayIP(); UART_PRINT("Send TCP packets from your handheld device to CC3200's IP\n\r"); /*After calling this function, you can start sending data to CC3200 IP * address on PORT_NUM */ if(!(IS_CONNECT_FAILED(g_ulStatus))) BsdTcpServer(PORT_NUM); UART_PRINT("Received TCP packets successfully \n\r"); // revert Device into STA mode and power off Network Processor sl_WlanSetMode(ROLE_STA); sl_Stop(SL_STOP_TIMEOUT); UART_PRINT("Test passed, exiting application... \n\r"); while(1) { _SlNonOsMainLoopTask(); } }
//***************************************************************************** // //! Configure the device as xmpp client //! //! \param pvParameters pointer to parameters //! //! \return None // //***************************************************************************** static void XmppClient(void *pvParameters) { SlNetAppXmppOpt_t XmppOption; SlNetAppXmppUserName_t UserName; SlNetAppXmppPassword_t Password; SlNetAppXmppDomain_t Domain; SlNetAppXmppResource_t Resource; unsigned char pRemoteJid[REMOTE_USERID_LEN]; unsigned char pRecvMessage[RECV_MSG_LEN]; signed short Status = 0; long lRetVal = -1; InitializeAppVariables(); // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its default state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // lRetVal = ConfigureSimpleLinkToDefaultState(); if(lRetVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == lRetVal) { UART_PRINT("Failed to configure the device in its default state\n\r"); } LOOP_FOREVER(); } UART_PRINT("Device is configured in default state \n\r"); // // Assumption is that the device is configured in station mode already // and it is in its default state // lRetVal = sl_Start(0, 0, 0); if (lRetVal < 0 || ROLE_STA != lRetVal) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(); } UART_PRINT("Device started as STATION \n\r"); // Connecting to WLAN AP - Set with static parameters defined at the top // After this call we will be connected and have IP address lRetVal = WlanConnect(); if(lRetVal < 0) { UART_PRINT("Unable to connect wlan.\n\r"); LOOP_FOREVER(); } // Configuring different parameters which are required for XMPP connection XmppOption.Port = XMPP_DST_PORT; XmppOption.Family = SL_AF_INET; XmppOption.SecurityMethod = SO_SECMETHOD_SSLV3; XmppOption.SecurityCypher = SECURE_MASK_SSL_RSA_WITH_RC4_128_SHA; XmppOption.Ip = XMPP_IP_ADDR; //DNS query to get IP address of XMPP Server // lRetVal = sl_NetAppDnsGetHostByName(XMPP_DOMAIN_NAME, \ // strlen((const char *)XMPP_DOMAIN_NAME), \ // (unsigned long*)&XmppOption.Ip, SL_AF_INET); // // if(lRetVal < 0) // { // UART_PRINT("Device couldn't retrive the host name \n\r"); // GPIO_IF_LedOn(MCU_RED_LED_GPIO); // LOOP_FOREVER(); // } lRetVal = sl_NetAppXmppSet(SL_NET_APP_XMPP_ID, NETAPP_XMPP_ADVANCED_OPT, \ sizeof(SlNetAppXmppOpt_t), (unsigned char *)&XmppOption); if(lRetVal < 0) { UART_PRINT("Unable to connect wlan.\n\r"); LOOP_FOREVER(); } // Configure Client's user name memcpy(UserName.UserName, CLIENT_USER_NAME, strlen(CLIENT_USER_NAME)); UserName.Length = strlen(CLIENT_USER_NAME); lRetVal = sl_NetAppXmppSet(SL_NET_APP_XMPP_ID, NETAPP_XMPP_USER_NAME, \ UserName.Length, \ (unsigned char *)&UserName); if(lRetVal < 0) { UART_PRINT("Unable to set XMPP user id.\n\r"); LOOP_FOREVER(); } // Configure Client's password memcpy(Password.Password, CLIENT_PASSWORD, strlen(CLIENT_PASSWORD)); Password.Length = strlen(CLIENT_PASSWORD); lRetVal = sl_NetAppXmppSet(SL_NET_APP_XMPP_ID, NETAPP_XMPP_PASSWORD, \ Password.Length, \ (unsigned char *)&Password); if(lRetVal < 0) { UART_PRINT("Unable to set XMPP user password.\n\r"); LOOP_FOREVER(); } memcpy(Domain.DomainName, XMPP_DOMAIN_NAME, strlen(XMPP_DOMAIN_NAME)); Domain.Length = strlen(XMPP_DOMAIN_NAME); lRetVal = sl_NetAppXmppSet(SL_NET_APP_XMPP_ID, NETAPP_XMPP_DOMAIN, \ Domain.Length, \ (unsigned char *)&Domain); if(lRetVal < 0) { UART_PRINT("Unable to XMPP domain.\n\r"); LOOP_FOREVER(); } memcpy(Resource.Resource, XMPP_RESOURCE,strlen(XMPP_RESOURCE)); Resource.Length = strlen(XMPP_RESOURCE); lRetVal = sl_NetAppXmppSet(SL_NET_APP_XMPP_ID, NETAPP_XMPP_RESOURCE, \ Resource.Length, \ (unsigned char *)&Resource); if(lRetVal < 0) { UART_PRINT("Unable to set XMPP resources.\n\r"); LOOP_FOREVER(); } while(sl_NetAppXmppConnect() < 0) { MAP_UtilsDelay(10000); } Status = sl_NetAppXmppRecv(pRemoteJid, REMOTE_USERID_LEN, pRecvMessage, \ RECV_MSG_LEN ); while(1) { while ( Status < 0) { MAP_UtilsDelay(10000); Status = sl_NetAppXmppRecv(pRemoteJid, REMOTE_USERID_LEN, \ pRecvMessage, RECV_MSG_LEN ); } // // Toggle Orange LED to indicate if it gets some chat message // GPIO_IF_LedOn(MCU_ORANGE_LED_GPIO); MAP_UtilsDelay(800000); GPIO_IF_LedOff(MCU_ORANGE_LED_GPIO); Status = sl_NetAppXmppSend(pRemoteJid, strlen((char*)pRemoteJid), \ pRecvMessage, strlen((char*)pRecvMessage) ); } }
//**************************************************************************** // MAIN FUNCTION //**************************************************************************** void main() { long retVal = -1; unsigned long ulResetCause; unsigned long ulDestinationIP; // // Board Initialization // BoardInit(); // // Configure the pinmux settings for the peripherals exercised // PinMuxConfig(); // // Configuring UART // InitTerm(); // // Initialize WDT // WDT_IF_Init(NULL,80000000 * 10); // // Get the reset cause // ulResetCause = PRCMSysResetCauseGet(); // // If watchdog triggered reset request hibernate // to clean boot the system // if( ulResetCause == PRCM_WDT_RESET ) { HIBEntrePreamble(); MAP_PRCMOCRRegisterWrite(0,1); MAP_PRCMHibernateWakeupSourceEnable(PRCM_HIB_SLOW_CLK_CTR); MAP_PRCMHibernateIntervalSet(330); MAP_PRCMHibernateEnter(); } // // uDMA Initialization // UDMAInit(); // // Display banner // DisplayBanner(APPLICATION_NAME); if( ulResetCause == PRCM_HIB_EXIT && (MAP_PRCMOCRRegisterRead(0) & 1) == 1 ) { UART_PRINT("Reset Cause : Watchdog Reset\n\r"); } else { UART_PRINT("Reset Cause : Power On\n\r"); // // Initialize the variables. // InitializeAppVariables(); // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its desired state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // retVal = ConfigureSimpleLinkToDefaultState(); if(retVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == retVal) UART_PRINT("Failed to configure the device in its default" " state \n\r"); LOOP_FOREVER(); } } // // Set destination IP // ulDestinationIP = IP_ADDR; // // Asumption is that the device is configured in station mode already // and it is in its default state // retVal = sl_Start(0, 0, 0); // // Acknowledge the watchdog so that it doesn't resets // WatchdogAck(); if (retVal < 0 || retVal != ROLE_STA) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(); } // //Connecting to WLAN AP // retVal = WlanConnect(); // // Acknowledge the watchdog so that it doesn't resets // WatchdogAck(); if(retVal < 0) { UART_PRINT("Failed to establish connection w/ an AP \n\r"); LOOP_FOREVER(); } UART_PRINT("Connected to AP : %s \n\r",SSID_NAME); UART_PRINT("Device IP : %d.%d.%d.%d\n\r\n\r", SL_IPV4_BYTE(g_ulIpAddr,3), SL_IPV4_BYTE(g_ulIpAddr,2), SL_IPV4_BYTE(g_ulIpAddr,1), SL_IPV4_BYTE(g_ulIpAddr,0)); UART_PRINT("\nStarting UDP Client\n\n\r"); UART_PRINT("Source IP : %d.%d.%d.%d\n\r" "Destination IP : %d.%d.%d.%d\n\r" "PORT : %d\n\r", SL_IPV4_BYTE(g_ulIpAddr,3), SL_IPV4_BYTE(g_ulIpAddr,2), SL_IPV4_BYTE(g_ulIpAddr,1), SL_IPV4_BYTE(g_ulIpAddr,0), SL_IPV4_BYTE(ulDestinationIP,3), SL_IPV4_BYTE(ulDestinationIP,2), SL_IPV4_BYTE(ulDestinationIP,1), SL_IPV4_BYTE(ulDestinationIP,0), g_uiPortNum); // // Acknowledge the watchdog so that it doesn't resets // WatchdogAck(); // // Send packets // BsdUdpClient(PORT_NUM,ulDestinationIP); // // power off the network processor // sl_Stop(SL_STOP_TIMEOUT); while (1) { _SlNonOsMainLoopTask(); } }
void WlanStationMode( void *pvParameters ) { int iTestResult = 0; unsigned long ulIP = 0; unsigned long ulSubMask = 0; unsigned long ulDefaultGateway = 0; unsigned long ulDNSServer = 0; unsigned char ucDHCP = 0; char cMode; char* buff="hhhhhh\n\r"; unsigned char currentMacAddress[SL_MAC_ADDR_LEN]; //UART_PRINT(" in WlanStationMode \n\r"); /* for(int a = 0; a<5; ++a){ Z_DelayS(30); *buff=a+'0'; UART_PRINT(buff); } */ char deviceRole = ROLE_STA; deviceRole = sl_Start(NULL,NULL,InitCallback); /* deviceRole = sl_Start(NULL,NULL,NULL); if(deviceRole < 0 ){ UART_PRINT("sl_Start error \n\r"); return; } else if(deviceRole == ROLE_STA) UART_PRINT("in station mode \n\r"); else{ UART_PRINT("in wrong mode \n\r"); return; } */ /* if((cMode = sl_Start(NULL,NULL,NULL)) != ROLE_STA){ UART_PRINT("hellow \n\r"); *buff=cMode+'0'; UART_PRINT(buff); *buff=ROLE_STA+'0'; UART_PRINT(buff); // SL_WLAN_SET_MODE_STA(); } UART_PRINT("hellow i am in station mode now \n\r"); */ while(!g_uiSimplelinkstarted) { //looping till simplelink starts Z_DelayS(1); // ; UART_PRINT("i am starting now \n\r"); } UART_PRINT("i am started \n\r"); // Connecting to WLAN AP - Set with static parameters defined at the top // After this call we will be connected and have IP address */ WlanConnect(); UART_PRINT("i'm connected! \n\r"); //get mac addr from s-flash SL_MAC_ADDR_GET(currentMacAddress); Z_MACDispaly(currentMacAddress); SL_STA_IPV4_ADDR_GET(&ulIP,&ulSubMask,&ulDefaultGateway,&ulDNSServer, &ucDHCP); Z_IPDispaly(&ulIP); MyIP=ulIP; Z_IPDispaly(&ulSubMask); Z_IPDispaly(&ulDefaultGateway); /* UNUSED(ulIP); UNUSED(ulSubMask); UNUSED(ulDNSServer); UNUSED(ucDHCP); */ // iTestResult = PingTest(ulDefaultGateway); // UNUSED(iTestResult); //BsdTcpServer(PORT_NUM); //mqtt_pub(); UART_PRINT("WlanStationMode\r\n"); vTaskDelete(NULL); UART_PRINT("WlanStationMode\r\n"); return; }
//***************************************************************************** // //! This function demonstrates how certificate can be used with SSL. //! The procedure includes the following steps: //! 1) connect to an open AP //! 2) get the server name via a DNS request //! 3) define all socket options and point to the CA certificate //! 4) connect to the server via TCP //! //! \param None //! //! \return 0 on success else error code //! \return LED1 is turned solid in case of success //! LED2 is turned solid in case of failure //! //***************************************************************************** static long ssl() { SlSockAddrIn_t Addr; int iAddrSize; unsigned char ucMethod = SL_SO_SEC_METHOD_SSLV3; unsigned int uiIP,uiCipher = SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA; long lRetVal = -1; int iSockID; GPIO_IF_LedConfigure(LED1|LED3); GPIO_IF_LedOff(MCU_RED_LED_GPIO); GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); lRetVal = InitializeAppVariables(); ASSERT_ON_ERROR(lRetVal); // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its default state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // lRetVal = ConfigureSimpleLinkToDefaultState(); if(lRetVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == lRetVal) UART_PRINT("Failed to configure the device in its default state \n\r"); return lRetVal; } UART_PRINT("Device is configured in default state \n\r"); CLR_STATUS_BIT_ALL(g_ulStatus); /// // Assumption is that the device is configured in station mode already // and it is in its default state // lRetVal = sl_Start(0, 0, 0); if (lRetVal < 0 || ROLE_STA != lRetVal) { UART_PRINT("Failed to start the device \n\r"); return lRetVal; } UART_PRINT("Device started as STATION \n\r"); // //Connecting to WLAN AP // lRetVal = WlanConnect(); if(lRetVal < 0) { UART_PRINT("Failed to establish connection w/ an AP \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } UART_PRINT("Connection established w/ AP and IP is aquired \n\r"); //Set time of the device for certificate verification. lRetVal = set_time(); if(lRetVal < 0) { UART_PRINT("Unable to set time in the device"); return lRetVal; } lRetVal = sl_NetAppDnsGetHostByName(g_Host, strlen((const char *)g_Host), (unsigned long*)&uiIP, SL_AF_INET); if(lRetVal < 0) { UART_PRINT("Device couldn't retrive the host name \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } Addr.sin_family = SL_AF_INET; Addr.sin_port = sl_Htons(GOOGLE_DST_PORT); Addr.sin_addr.s_addr = sl_Htonl(uiIP); iAddrSize = sizeof(SlSockAddrIn_t); // // opens a secure socket // iSockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET); if( iSockID < 0 ) { UART_PRINT("Device unable to create secure socket \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } // // configure the socket as SSLV3.0 // lRetVal = sl_SetSockOpt(iSockID, SL_SOL_SOCKET, SL_SO_SECMETHOD, &ucMethod,\ sizeof(ucMethod)); if(lRetVal < 0) { UART_PRINT("Device couldn't set socket options \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } // //configure the socket as RSA with RC4 128 SHA // lRetVal = sl_SetSockOpt(iSockID, SL_SOL_SOCKET, SL_SO_SECURE_MASK, &uiCipher,\ sizeof(uiCipher)); if(lRetVal < 0) { UART_PRINT("Device couldn't set socket options \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } // //configure the socket with GOOGLE CA certificate - for server verification // lRetVal = sl_SetSockOpt(iSockID, SL_SOL_SOCKET, \ SL_SO_SECURE_FILES_CA_FILE_NAME, \ SL_SSL_CA_CERT_FILE_NAME, \ strlen(SL_SSL_CA_CERT_FILE_NAME)); if(lRetVal < 0) { UART_PRINT("Device couldn't set socket options \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } lRetVal = sl_SetSockOpt(iSockID, SL_SOL_SOCKET, \ SO_SECURE_DOMAIN_NAME_VERIFICATION, \ g_Host, strlen((const char *)g_Host)); if( lRetVal < 0 ) { UART_PRINT("Device couldn't set socket options \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } /* connect to the peer device - Google server */ lRetVal = sl_Connect(iSockID, ( SlSockAddr_t *)&Addr, iAddrSize); if(lRetVal < 0) { UART_PRINT("Device couldn't connect to Google server \n\r"); GPIO_IF_LedOn(MCU_RED_LED_GPIO); return lRetVal; } GPIO_IF_LedOff(MCU_RED_LED_GPIO); GPIO_IF_LedOn(MCU_GREEN_LED_GPIO); return SUCCESS; }
//***************************************************************************** // //! \brief Task Created by main fucntion. This task prints the wake up reason //! (from hibernate or from restart). start simplelink, set NWP power //! policy and connects to an AP. Creates UDP client and send UDP //! packets at around 1Mbit/sec for certain time. Disconnect form AP //! and stops the simplelink.Setup GPIO and Timer as wakeup source from //! low power modes. Go into HIBernate. //! //! \param pvParameters is a general void pointer (not used here). //! //! \return none // //***************************************************************************** void TimerGPIOTask(void *pvParameters) { cc_hndl tTimerHndl; cc_hndl tGPIOHndl; int iSockDesc = 0; int iRetVal = 0; int iCounter = 0; sockaddr_in sServerAddr; unsigned char *pcSendBuff; unsigned char cSyncMsg; // // creating the queue for signalling about connection events // iRetVal = osi_MsgQCreate(&g_tConnection, NULL, sizeof( unsigned char ), 3); if (iRetVal < 0) { UART_PRINT("unable to create the msg queue\n\r"); LOOP_FOREVER(); } // filling the buffer for (iCounter=0 ; iCounter<BUFF_SIZE ; iCounter++) { g_cBsdBuf[iCounter] = (char)(iCounter % 10); } pcSendBuff = g_cBsdBuf; if(MAP_PRCMSysResetCauseGet() == PRCM_POWER_ON) { // // Displays the Application Banner // DisplayBanner(); // // starting the simplelink // iRetVal = sl_Start(NULL, NULL, NULL); if (iRetVal < 0) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(); } // // Switch to STA mode if device is not in this mode // SwitchToStaMode(iRetVal); // // Set the power management policy of NWP // iRetVal = sl_WlanPolicySet(SL_POLICY_PM, SL_NORMAL_POLICY, NULL, 0); if (iRetVal < 0) { UART_PRINT("unable to configure network power policy\n\r"); LOOP_FOREVER(); } } else if(MAP_PRCMSysResetCauseGet() == PRCM_HIB_EXIT) { UART_PRINT("woken from hib\n\r"); // // starting the simplelink // iRetVal = sl_Start(NULL, NULL, NULL); if (iRetVal < 0) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(); } } else if(MAP_PRCMSysResetCauseGet() == PRCM_WDT_RESET) { UART_PRINT("woken from WDT Reset\n\r"); // // starting the simplelink // iRetVal = sl_Start(NULL, NULL, NULL); if (iRetVal < 0) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(); } } else { UART_PRINT("woken cause unknown\n\r"); } // // connecting to the Access Point // if(-1 == WlanConnect()) { UART_PRINT("Connection to AP failed\n\r"); goto no_network_connection; }else{ UART_PRINT("Connected to AP\n\r"); } // // creating a UDP socket // iSockDesc = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); if(iSockDesc < 0) { UART_PRINT("sock error\n\r"); LOOP_FOREVER(); } // // configure the UDP Server address // sServerAddr.sin_family = SL_AF_INET; sServerAddr.sin_port = sl_Htons(APP_UDP_PORT); sServerAddr.sin_addr.s_addr = sl_Htonl(SERVER_IP_ADDRESS); // // Set 5 sec timer allowing 5 sec of UDP Tx. // tTimerHndl = SetTimer(); g_ucTrafficEnable = 1; while(g_ucTrafficEnable == 1) { // // sending message // iRetVal = sendto(iSockDesc, pcSendBuff,BUFF_SIZE, 0, (struct sockaddr *)&sServerAddr,sizeof(sServerAddr)); if(iRetVal < 0) { UART_PRINT("send error\n\r"); LOOP_FOREVER(); } ManageDelay(128,BUFF_SIZE); } UART_PRINT("sent\n\r"); // // stop and delete the timer // cc_timer_stop(tTimerHndl); cc_timer_delete(tTimerHndl); // //close the socket // close(iSockDesc); if(iRetVal < 0) { UART_PRINT("could not close the socket\n\r"); } // // disconnect from the Access Point // WlanDisconnect(); no_network_connection: // // stop the simplelink with reqd. timeout value (30 ms) // sl_Stop(SL_STOP_TIMEOUT); // // setting Timer as one of the wakeup source // tTimerHndl = SetTimerAsWkUp(); // // setting some GPIO as one of the wakeup source // tGPIOHndl = SetGPIOAsWkUp(); /* handles, if required, can be used to stop the timer, but not used here*/ UNUSED(tTimerHndl); UNUSED(tGPIOHndl); // // Setting up HIBERNATE as the lowest power mode for the system. // lp3p0_setup_power_policy(POWER_POLICY_HIBERNATE); // // idle wait will push the system into the lowest power mode(HIBERNATE). // iRetVal = osi_MsgQCreate(&g_tWaitForHib, NULL, sizeof( unsigned char ), 1); if (iRetVal < 0) { UART_PRINT("unable to create the msg queue\n\r"); LOOP_FOREVER(); } osi_MsgQRead(&g_tWaitForHib, &cSyncMsg, OSI_WAIT_FOREVER); // // infinite loop (must not reach here) // LOOP_FOREVER(); }