Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: CameraC328 WizFi250Interface mbed-src
Fork of WizFi250TcpUdpExample by
Diff: src/main.cpp
- Revision:
- 0:279f250818f6
- Child:
- 1:c0b6bfde0ea9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main.cpp Tue Jun 03 01:00:04 2014 +0000
@@ -0,0 +1,190 @@
+/*
+ /* Copyright (C) 2014 Wiznet, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include "mbed.h"
+#include "WizFi250Interface.h"
+
+#define TARGET_FRDM_KL25Z
+#define SECURE WizFi250::SEC_AUTO
+#define SSID "WiznetKaizen"
+#define PASS "12345678"
+
+#define ECHO_SERVER_ADDRESS "192.168.15.14"
+#define ECHO_SERVER_PORT 5000
+
+#define FEED_HOST "api.xively.com"
+#define FEED_ID "EUHFMSwZj8pDdE6jKZgooDt3vlDivDy6srpKgbfE0rgdnZ3D"
+#define API_KEY "827175846"
+
+void testUdpEchoClient();
+void testUdpEchoServer();
+void testTcpEchoClient();
+void testTcpEchoServer();
+
+int main()
+{
+ int i;
+ char input;
+
+ WizFi250Interface wizfi250(PTE0,PTE1,PTD5,PTD0,PTD4,NC,115200);
+ wizfi250.init();
+ if ( wizfi250.connect(SECURE, SSID, PASS)) return -1;
+ printf("IP Address is %s\r\n", wizfi250.getIPAddress());
+
+
+ while(1)
+ {
+ printf("\r\nInput Test Mode ( 1:)\r\n");
+ scanf("%c",&input);
+
+ if(input == 'q')
+ break;
+
+ switch(input)
+ {
+ case '1':
+ testTcpEchoServer();
+ break;
+ case '2':
+ testTcpEchoClient();
+ break;
+ case '3':
+ testUdpEchoClient();
+ break;
+ case '4':
+ testUdpEchoServer();
+ break;
+ }
+ }
+
+ printf("End the test program\r\n");
+}
+
+
+void testTcpEchoServer()
+{
+ char buffer[1024];
+ int n = 0;
+
+ TCPSocketServer server;
+ server.bind(ECHO_SERVER_PORT);
+ server.listen();
+
+ printf("\nWait for new connection...\r\n");
+ TCPSocketConnection client;
+ server.accept(client);
+ client.set_blocking(false, 1500);
+
+ printf("Connection from: %s\r\n", client.get_address());
+ while (true)
+ {
+ if( client.is_connected() == false )
+ {
+ client.close();
+ break;
+ }
+
+ n = client.receive_all(buffer, sizeof(buffer));
+ if ( n > 0 )
+ {
+ buffer[n] = '\0';
+ printf("length : %d\r\n", n);
+
+ client.send_all(buffer, n);
+ }
+ }
+}
+
+void testUdpEchoClient()
+{
+ int i;
+ UDPSocket sock;
+ sock.init();
+
+ Endpoint echo_server;
+ echo_server.set_address(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
+
+
+ for(i=0;i<10;i++)
+ {
+ char out_buffer[] = "Hello World\n";
+ sock.sendTo(echo_server, out_buffer, sizeof(out_buffer));
+
+ char in_buffer[256];
+ int n = sock.receiveFrom(echo_server, in_buffer, sizeof(in_buffer));
+ in_buffer[n] = '\0';
+
+ if( n > 0 )
+ printf("%s\r\n", in_buffer);
+ }
+
+ sock.close();
+}
+
+
+void testUdpEchoServer()
+{
+ UDPSocket server;
+ server.set_blocking(false);
+ server.bind(ECHO_SERVER_PORT);
+
+ Endpoint client;
+ char buffer[256];
+ while(true)
+ {
+ int n = server.receiveFrom(client, buffer, sizeof(buffer));
+ if(n > 0)
+ {
+ //INFO("Received packet from: %s\n", client.get_address());
+ buffer[n] = '\0';
+ printf("%s\r\n", buffer);
+ server.sendTo(client, buffer, n);
+ break;
+ }
+ }
+}
+
+
+void testTcpEchoClient()
+{
+ char buffer[512];
+ 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);
+ }
+
+ while(true)
+ {
+ int n = socket.receive(buffer, sizeof(buffer));
+ if(n > 0)
+ {
+ buffer[n] = '\0';
+ printf("%s\r\n",buffer);
+ socket.send(buffer, strlen(buffer));
+ //socket.send_all(buffer, sizeof(buffer)-1);
+ break;
+ }
+ }
+
+ socket.close();
+}
\ No newline at end of file
