ACKme Logo WiConnect Host Library- API Reference Guide
 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
main.cpp
1 
2 #include "Wiconnect.h"
3 #include "target_config.h"
4 
5 #define NETWORK_SSID "<YOUR NETWORK SSID HERE>"
6 #define NETWORK_PASSWORD "<YOUR NETWORK PASSWORD HERE>"
7 
8 #define ECHO_SERVER_ADDRESS "192.168.1.110"
9 #define ECHO_SERVER_PORT 7
10 
11 
12 static Serial consoleSerial(STDIO_UART_TX, STDIO_UART_RX);
13 
14 static char in_buffer[256];
15 
16 int main()
17 {
18  WiconnectResult result;
19  SerialConfig serialConfig(WICONNECT_RX_PIN, WICONNECT_TX_PIN, 256);
20  Wiconnect wiconnect(serialConfig, 256, NULL, WICONNECT_RESET_PIN);
21 
22  consoleSerial.baud(115200);
23 
24  if(WICONNECT_FAILED(result, wiconnect.init(true)))
25  {
26  printf("Failed to initialize Wiconnect: %s\r\n", Wiconnect::getWiconnectResultStr(result));
27  if(result == WICONNECT_FIRMWARE_OUTDATED)
28  {
29  printf("The WiFi firmware is not supported. Run the ota example to update the firmware:\r\n");
30  printf("https://developer.mbed.org/teams/ACKme/code/wiconnect-ota_example");
31  }
32  for(;;);
33  }
34  else if(WICONNECT_FAILED(result, wiconnect.join(NETWORK_SSID, NETWORK_PASSWORD)))
35  {
36  printf("Failed to join network: %s\r\n", Wiconnect::getWiconnectResultStr(result));
37  for(;;);
38  }
39 
40 
41  UDPSocket sock;
42  sock.init();
43 
44  Endpoint echo_server;
45  echo_server.set_address(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
46 
47 
48  char out_buffer[] = "Hello World\n";
49  if(sock.sendTo(echo_server, out_buffer, sizeof(out_buffer)) == -1)
50  {
51  printf("Failed to send data\r\n");
52  for(;;);
53  }
54 
55 
56  int n = sock.receiveFrom(echo_server, in_buffer, sizeof(in_buffer));
57  if(n == -1)
58  {
59  printf("Failed to receive data\r\n");
60  for(;;);
61  }
62  in_buffer[n] = '\0';
63  printf("%s", in_buffer);
64 
65 
66  sock.close();
67  wiconnect.deinit();
68 
69  printf("Finished!");
70  while(true) {}
71 }
WiconnectResult
API Result code.
Host<->Wiconnect Module serial configuration.
Definition: sdk.h:148
The WiFi module's firmware is out-dated. See updateFirmware() to update the firmware.
The root WiConnect library class. This class inheriets all WiConnect functionality.
#define WICONNECT_FAILED(result, func)
Populates result with return value from func, returns TRUE if return value contains error...