
TCP echo client using the WiConnect library and mbed TCP Socket API.
Revision 0:447a1bbce2ca, committed 2014-08-23
- Comitter:
- dan_ackme
- Date:
- Sat Aug 23 13:08:08 2014 +0000
- Child:
- 1:df55971a70cb
- Commit message:
- Initial check-in
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Wiconnect.lib Sat Aug 23 13:08:08 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/ACKme/code/Wiconnect/#7b67c3f94de9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Aug 23 13:08:08 2014 +0000 @@ -0,0 +1,65 @@ + +#include "Wiconnect.h" +#include "target_config.h" + +#define NETWORK_SSID "<YOUR NETWORK SSID HERE>" +#define NETWORK_PASSWORD "<YOUR NETWORK PASSWORD HERE>" + +#define ECHO_SERVER_ADDRESS "<YOUR LOCAL IP ADDRESS HERE>" +#define ECHO_SERVER_PORT 7 + + +static Serial consoleSerial(STDIO_UART_TX, STDIO_UART_RX); +static char buf[256]; + + +int main() +{ + WiconnectResult result; + SerialConfig serialConfig(WICONNECT_RX_PIN, WICONNECT_TX_PIN, 256); + Wiconnect wiconnect(serialConfig, 256, NULL, WICONNECT_RESET_PIN); + + consoleSerial.baud(115200); + + if(WICONNECT_FAILED(result, wiconnect.init(true))) + { + printf("Failed to initialize Wiconnect: %s\r\n", Wiconnect::getWiconnectResultStr(result)); + for(;;); + } + else if(WICONNECT_FAILED(result, wiconnect.join(NETWORK_SSID, NETWORK_PASSWORD))) + { + printf("Failed to join network: %s\r\n", Wiconnect::getWiconnectResultStr(result)); + for(;;); + } + + printf("IP Address is %s\n", wiconnect.getIpAddress()); + + TCPSocketConnection socket; + while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0) + { + printf("Unable to connect to (%s) on port (%d)\r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); + wait(1); + } + + char hello[] = "Hello World\n"; + if(socket.send_all(hello, sizeof(hello) - 1) == -1) + { + printf("Failed to send data\r\n"); + for(;;); + } + + int n = socket.receive(buf, 256); + if(n == -1) + { + printf("Failed to receive data\r\n"); + for(;;); + } + buf[n] = '\0'; + printf("%s", buf); + + socket.close(); + wiconnect.deinit(); + + printf("Finished!"); + while(true) {} +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Aug 23 13:08:08 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target_config.h Sat Aug 23 13:08:08 2014 +0000 @@ -0,0 +1,93 @@ +/** + * ACKme WiConnect Host Library is licensed under the BSD licence: + * + * Copyright (c)2014 ACKme Networks. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + */ +#pragma once + + +// The BAUD rate your PC/MAC/Linux terminal uses with the eval board +#define CONSOLE_BAUD 115200 + + +// Uncomment this to enable WiConnect serial interface hardware flow control +// NOTE: your platform must support the serial flow control api functions +//#define ENABLE_FLOW_CONTROL + + +#define WICONNECT_INTERNAL_BUFFER_SIZE (4*1024) +#define WICONNECT_SERIAL_RX_BUFFER_SIZE (4*1024) + +#define DEFAULT_CMD_GETCHAR_TIMEOUT 250 +#define DEFAULT_COMMAND_LINE_LENGTH_MAX 128 +#define DEFAULT_COMMAND_MAX_HISTORY 16 +#define DEFAULT_CMD_PROMPT_STR "> " +#define DEFAULT_COMMAND_MAX_ARGV 16 + +#define TEST_NONBLOCKING_API false +#define TEST_BUFFER_LENGTH 4*1024 + + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// Seabass Target Configuration +#ifdef TARGET_SEABASS + +#define WICONNECT_TX_PIN PA_9 +#define WICONNECT_RX_PIN PA_10 +#define WICONNECT_RESET_PIN PB_0 +#define WICONNECT_WAKE_PIN NC + +#ifdef ENABLE_FLOW_CONTROL +#define WICONNECT_CTS_PIN PA_11 +#define WICONNECT_RTS_PIN PA_12 +#else +#define WICONNECT_CTS_PIN NC +#define WICONNECT_RTS_PIN NC +#endif + +#endif + + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// Nucleo F401RE Target Configuration +#ifdef TARGET_NUCLEO_F401RE + +#define WICONNECT_TX_PIN PA_9 +#define WICONNECT_RX_PIN PA_10 +#define WICONNECT_RESET_PIN PC_7 +#define WICONNECT_WAKE_PIN NC + +#ifdef ENABLE_FLOW_CONTROL +#define WICONNECT_CTS_PIN PA_11 +#define WICONNECT_RTS_PIN PA_12 +#else +#define WICONNECT_CTS_PIN NC +#define WICONNECT_RTS_PIN NC +#endif + +#endif + +