ACKme Logo WiConnect Host Library- API Reference Guide
 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
example.cpp
1 
17 /******************************************************************************
18  * Example Variables
19  */
20 
21 // This is the name of your WiFi network
22 // Look for this name in your WiFi settings
23 // (e.g. your phone's list of WiFi networks in the WiFi settings menu)
24 // tip: add double-quotes around SSID to add spaces to name
25 #define NETWORK_SSID "\"<YOUR NETWORK NAME HERE>\""
26 
27 // This is the password of your WiFi network
28 // Leave as empty string (e.g "") to connect to OPEN network
29 #define NETWORK_PASSWORD "\"<YOUR NETWORK PASSWORD HERE>\""
30 
31 
32 
33 
34 /******************************************************************************
35  * Includes
36  */
37 
38 // include C library headers
39 #include <stdio.h> // needed for printf
40 
41 // include target specific defines
42 #include "target_config.h"
43 // include the Wiconnect Host Library API header
44 #include "Wiconnect.h"
45 
46 
47 
48 /******************************************************************************
49  * Global Defines
50  */
51 
52 
53 // Serial used for printfs to terminal (i.e. NOT used for WiConnect)
54 static Serial consoleSerial(STDIO_UART_TX, STDIO_UART_RX);
55 
56 
57 
58 
59 /******************************************************************************
60  * Starting point of application
61  */
62 int main(int argc, char **argv)
63 {
64  consoleSerial.baud(115200); // console terminal to 115200 baud
65 
66  //-------------------------------------------------------------------------
67  // STEP 1: Instantiate WiConnect Library
68  //-------------------------------------------------------------------------
69 
70  // Setup wiconnect serial interface configuration
71  // Here we only specify the rx buffer size and not rx buffer pointer, this means
72  // The serial RX buffer will be dynamically allocated
73  SerialConfig serialConfig(WICONNECT_RX_PIN, WICONNECT_TX_PIN, 256, NULL);
74 
75  // Instantiate the Wiconnect library
76  // Here we only specify the buffer size and not buffer pointer, this means
77  // The internal buffer will be dynamically allocated
78  Wiconnect wiconnect(serialConfig, 256, NULL, WICONNECT_RESET_PIN);
79 
80 
81  //-------------------------------------------------------------------------
82  // STEP 2: Initiate Communication with WiFi Module
83  //-------------------------------------------------------------------------
84 
85  printf("Initializing WiConnect Library...\r\n");
86 
87  // Initialize communication with WiFi module
88  if(wiconnect.init(true) != WICONNECT_SUCCESS)
89  {
90  printf("Failed to initialize communication with WiFi module!\r\n"
91  "Make sure the wires are connected correctly\r\n");
92  for(;;); // infinite loop
93  }
94 
95 
96  //-------------------------------------------------------------------------
97  // STEP 3: Join a network using the specified parameters
98  //-------------------------------------------------------------------------
99 
100  printf("Joining network: %s....\r\n", NETWORK_SSID);
101 
102  if(wiconnect.join(NETWORK_SSID, NETWORK_PASSWORD) != WICONNECT_SUCCESS)
103  {
104  printf("Failed to send join command\r\n");
105  for(;;); // infinite loop
106  }
107 
108  //-------------------------------------------------------------------------
109  // STEP 4: Done!
110  //-------------------------------------------------------------------------
111 
112  printf("IP Address: %s\r\n", wiconnect.getIpAddress());
113  printf("Network join example has completed!\r\n");
114 
115  while(true){} // infinite loop
116 }
117 
Host<->Wiconnect Module serial configuration.
Definition: sdk.h:140
Command successfully completed.
The root WiConnect library class. This class inheriets all WiConnect functionality.