ACKme Logo WiConnect Host Library- API Reference Guide
 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
example.cpp
1 
18 /******************************************************************************
19  * Example Variables
20  */
21 
22 // This is the name of the WebSetup network
23 // Look for this name in your WiFi settings
24 // (e.g. your phone's list of WiFi networks in the WiFi settings menu)
25 // tip: add double-quotes around SSID to add spaces to name
26 #define WEB_SETUP_SSID "\"WiConnect WebSetup Example\""
27 
28 // This is the password for the WebSetup network
29 // Leave as empty string (e.g "") to create OPEN network
30 #define WEB_SETUP_PASSWORD "password"
31 
32 
33 
34 
35 /******************************************************************************
36  * Includes
37  */
38 
39 // include C library headers
40 #include <stdio.h> // needed for printf
41 
42 // include target specific defines
43 #include "target_config.h"
44 // include the Wiconnect Host Library API header
45 #include "Wiconnect.h"
46 
47 
48 
49 /******************************************************************************
50  * Local Functions
51  */
52 static void webSetupCompleteCallback(WiconnectResult result, void *arg1, void *arg2);
53 
54 
55 /******************************************************************************
56  * Global Defines
57  */
58 
59 
60 // Serial used for printfs to terminal (i.e. NOT used for WiConnect)
61 static Serial consoleSerial(STDIO_UART_TX, STDIO_UART_RX);
62 
63 // Buffer used internally by WiConnect library, note that this is optional
64 static uint8_t wiconnectInternalBuffer[256];
65 
66 // Flag that indicate websetup has completed
67 static volatile bool webSetupCompleteFlag = false;
68 
69 
70 /******************************************************************************
71  * Starting point of application
72  */
73 int main(int argc, char **argv)
74 {
75  consoleSerial.baud(115200); // console terminal to 115200 baud
76 
77  //-------------------------------------------------------------------------
78  // STEP 1: Instantiate WiConnect Library
79  //-------------------------------------------------------------------------
80 
81  // Setup wiconnect serial interface configuration
82  // Here we only specify the rx buffer size and not rx buffer pointer, this means
83  // The serial RX buffer will be dynamically allocated
84  SerialConfig serialConfig(WICONNECT_RX_PIN, WICONNECT_TX_PIN, 256, NULL);
85 
86  // Instantiate the Wiconnect library
87  // Here we specify the buffer size AND buffer pointer, this means we're using static allocation
88  Wiconnect wiconnect(serialConfig, sizeof(wiconnectInternalBuffer), wiconnectInternalBuffer, WICONNECT_RESET_PIN);
89 
90 
91  //-------------------------------------------------------------------------
92  // STEP 2: Initiate Communication with WiFi Module
93  //-------------------------------------------------------------------------
94 
95  printf("Initializing WiConnect Library...\r\n");
96 
97  // Initialize communication with WiFi module
98  if(wiconnect.init(true) != WICONNECT_SUCCESS)
99  {
100  printf("Failed to initialize communication with WiFi module!\r\n"
101  "Make sure the wires are connected correctly\r\n");
102  for(;;); // infinite loop
103  }
104 
105 
106  //-------------------------------------------------------------------------
107  // STEP 3: Start WebSetup with specified parameters
108  //-------------------------------------------------------------------------
109 
110  printf("Starting Websetup...\r\n");
111 
112  // Start web setup
113  if(wiconnect.startWebSetup(WEB_SETUP_SSID, WEB_SETUP_PASSWORD, Callback(webSetupCompleteCallback)) != WICONNECT_SUCCESS)
114  {
115  printf("Failed to start web setup\r\n");
116  for(;;); // infinite loop
117  }
118 
119  //-------------------------------------------------------------------------
120  // STEP 4: Wait for web setup webpage to complete
121  //-------------------------------------------------------------------------
122 
123  printf("Web setup has started.\r\n\r\n");
124  printf("1. Using your phone (or PC, Mac, Linux, etc.)\r\n connect to the WiFi network: %s\r\n", WEB_SETUP_SSID);
125  printf("2. The password is: %s\r\n", WEB_SETUP_PASSWORD);
126  printf("3. Once connected, open your browser and enter the URL: http://setup.com\r\n");
127  printf("4. This will bringup a setup page, enter your router's credentials.\r\n");
128  printf("5. Click the 'Save & Exit' button at the bottom of the webpage\r\n\r\n");
129 
130  while(!webSetupCompleteFlag)
131  {
132  // do nothing while we wait
133  // When the user exits web setup from the webpage
134  // webSetupCompleteCallback() will execute and set webSetupCompleteFlag TRUE
135  }
136 
137  //-------------------------------------------------------------------------
138  // STEP 5: Done!
139  //-------------------------------------------------------------------------
140 
141  printf("IP Address: %s\r\n", wiconnect.getIpAddress());
142  printf("Web setup example has completed!\r\n");
143 
144  while(true){} // infinite loop
145 }
146 
147 
148 // this function is called when web setup completes
149 // it is called in the background
150 static void webSetupCompleteCallback(WiconnectResult result, void *arg1, void *arg2)
151 {
152  webSetupCompleteFlag = true;
153 }
WiconnectResult
API Result code.
Generic callback function.
Definition: Callback.h:49
Host<->Wiconnect Module serial configuration.
Definition: sdk.h:140
Command successfully completed.
The root WiConnect library class. This class inheriets all WiConnect functionality.