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: WIZnetInterface mbed
Fork of TCPEchoServer-WIZwiki-W7500 by
Revision 12:aee11a1d7f14, committed 2015-07-20
- Comitter:
- kzl108
- Date:
- Mon Jul 20 07:54:18 2015 +0000
- Parent:
- 11:0da8667a9201
- Commit message:
- LED Control by TCP
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Jun 29 09:46:12 2015 +0000
+++ b/main.cpp Mon Jul 20 07:54:18 2015 +0000
@@ -3,10 +3,17 @@
#define ECHO_SERVER_PORT 7
+DigitalOut myled(LED1);
+
+int compare_strings(char [], char []);
+
int main (void)
{
+ myled = 1; // LED OFF in WIZwiki-W7500
+ int flag=1;
+
printf("Wait a second...\r\n");
- uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02};
+ uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x55, 0x51, 0x52};
EthernetInterface eth;
eth.init(mac_addr); //Use DHCP
eth.connect();
@@ -32,6 +39,39 @@
// print received message to terminal
buffer[n] = '\0';
printf("Received message from Client :'%s'\r\n",buffer);
+
+
+ // LED control if received message matches pre-defined command
+ /*
+ if ((buffer[0] == 'L') & (buffer[1] == '\0'))
+ myled = 0; // LED ON in WIZwiki-W7500
+ else
+ myled = 1;
+ */
+
+ // LED control if received message matches pre-defined command
+ char command_buf[256] = {'L', 'E', 'D', '_', 'O', 'N', '\0'};
+
+ char string[256];
+ strcpy (string, command_buf);
+ printf("Received command : %s\n", string);
+
+ flag = compare_strings(buffer, command_buf);
+
+ if (flag == 0) {
+ myled = 0; // LED ON in WIZwiki-W7500
+ printf("LED is turned on!\r\n");
+ }
+ else {
+ myled = 1;
+ printf("LED is turned off!\r\n");
+ }
+
+
+ // LED blink one time
+ //myled = 0; // LED ON in WIZwiki-W7500
+ //wait(1.0);
+ //myled = 1; // LED OFF in WIZwiki-W7500
// reverse the message
char temp;
@@ -54,3 +94,18 @@
}
+int compare_strings(char a[], char b[])
+{
+ int c = 0;
+
+ while (a[c] == b[c]) {
+ if (a[c] == '\0' || b[c] == '\0')
+ break;
+ c++;
+ }
+
+ if (a[c] == '\0' && b[c] == '\0')
+ return 0;
+ else
+ return -1;
+}
