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 your WiFi 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 NETWORK_SSID "\"<YOUR NETWORK NAME HERE>\""
27 #define NETWORK_SSID "ASUS"
28 
29 // This is the password of your WiFi network
30 // Leave as empty string (e.g "") to connect to OPEN network
31 //#define NETWORK_PASSWORD "\"<YOUR NETWORK PASSWORD HERE>\""
32 #define NETWORK_PASSWORD "Y@nkee123"
33 
34 
35 
36 /******************************************************************************
37  * Includes
38  */
39 
40 // include C library headers
41 #include <stdio.h> // needed for printf
42 
43 // include target specific defines
44 #include "target_config.h"
45 // include the Wiconnect Host Library API header
46 #include "Wiconnect.h"
47 
48 
49 
50 /******************************************************************************
51  * Global Defines
52  */
53 
54 
55 // Serial used for printfs to terminal (i.e. NOT used for WiConnect)
56 static Serial consoleSerial(STDIO_UART_TX, STDIO_UART_RX);
57 
58 
59 
60 
61 /******************************************************************************
62  * Starting point of application
63  */
64 int main(int argc, char **argv)
65 {
66  consoleSerial.baud(115200); // console terminal to 115200 baud
67 
68  //-------------------------------------------------------------------------
69  // STEP 1: Instantiate WiConnect Library
70  //-------------------------------------------------------------------------
71 
72  // Setup wiconnect serial interface configuration
73  // Here we only specify the rx buffer size and not rx buffer pointer, this means
74  // The serial RX buffer will be dynamically allocated
75  SerialConfig serialConfig(WICONNECT_RX_PIN, WICONNECT_TX_PIN, 256, NULL);
76 
77  // Instantiate the Wiconnect library
78  // Here we only specify the buffer size and not buffer pointer, this means
79  // The internal buffer will be dynamically allocated
80  Wiconnect wiconnect(serialConfig, 256, NULL, WICONNECT_RESET_PIN);
81 
82 
83  //-------------------------------------------------------------------------
84  // STEP 2: Initiate Communication with WiFi Module
85  //-------------------------------------------------------------------------
86 
87  printf("Initializing WiConnect Library...\r\n");
88 
89  // Initialize communication with WiFi module
90  if(wiconnect.init(true) != WICONNECT_SUCCESS)
91  {
92  printf("Failed to initialize communication with WiFi module!\r\n"
93  "Make sure the wires are connected correctly\r\n");
94  for(;;); // infinite loop
95  }
96 
97 
98  //-------------------------------------------------------------------------
99  // STEP 3: Join a network using the specified parameters
100  //-------------------------------------------------------------------------
101 
102  printf("Joining network: %s....\r\n", NETWORK_SSID);
103 
104  if(wiconnect.join(NETWORK_SSID, NETWORK_PASSWORD) != WICONNECT_SUCCESS)
105  {
106  printf("Failed to send join command\r\n");
107  for(;;); // infinite loop
108  }
109 
110  //-------------------------------------------------------------------------
111  // STEP 4: Update the module's firmware, this takes about 60s
112  //-------------------------------------------------------------------------
113 
114  printf("Updating WiFi module's internal firmware to latest...\r\n");
115 
116  if(wiconnect.updateFirmware() != WICONNECT_SUCCESS)
117  {
118  printf("Failed to update the module's firmware\r\n");
119  for(;;); // infinite loop
120  }
121 
122  //-------------------------------------------------------------------------
123  // STEP 5: Done!
124  //-------------------------------------------------------------------------
125 
126  wiconnect.getVersion();
127  printf("Version: %s\r\n", wiconnect.getResponseBuffer());
128 
129  while(true){} // infinite loop
130 }
131 
Host<->Wiconnect Module serial configuration.
Definition: sdk.h:129
Command successfully completed.
The root WiConnect library class. This class inheriets all WiConnect functionality.