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: NTPClient W5500Interface Watchdog device_configuration eeprom_flash mbed-rpc-nucleo mbed-rtos mbed
Fork of F103-Serial-to-Ethernet by
Revision 10:4cd965d79de0, committed 2014-09-26
- Comitter:
- olympux
- Date:
- Fri Sep 26 20:32:57 2014 +0000
- Parent:
- 9:d2534ecf88c6
- Child:
- 11:709f90a3b599
- Commit message:
- Added NNIOTM command for update time using NTP
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| readme.txt | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Sep 26 20:07:34 2014 +0000
+++ b/main.cpp Fri Sep 26 20:32:57 2014 +0000
@@ -61,7 +61,7 @@
//#define TCP_CLIENT
#define UDP_SERVER
//#define UDP_CLIENT
-//#define NTP
+#define NTP
#define DEFAULT_IP_ADDRESS "192.168.0.249"
#define DEFAULT_IP_SUBNET "255.255.255.0"
@@ -342,22 +342,6 @@
// Network processor
while (true) {
-#ifdef NTP
- printf("Trying to update time...\r\n");
- if (ntp.setTime("0.pool.ntp.org") == 0)
- {
- printf("Set time successfully\r\n");
- time_t ctTime;
- ctTime = time(NULL);
- printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
- }
- else
- {
- printf("Error\r\n");
- }
-#endif
-
-
// FOR INTERFACING
#ifdef TCP_SERVER
// no tcp client connected
@@ -455,19 +439,45 @@
// discovery command
if (strstr(buffer, "NNIODS") != NULL) {
udp_server.sendTo(ep_udp_client, ip_addr, strlen(ip_addr));
- }
+ } // NNIODS
// ask for TCP server port
else if (strstr(buffer, "NNIOTP") != NULL) {
char port[5];
sprintf(port, "%5d", tcp_server_port);
udp_server.sendTo(ep_udp_client, port, strlen(port));
- }
+ } // NNIOTP
// ask for UDP server port
else if (strstr(buffer, "NNIOUP") != NULL) {
char port[5];
sprintf(port, "%5d", udp_server_port);
udp_server.sendTo(ep_udp_client, port, strlen(port));
- }
+ } // NNIOUP
+ else if (strstr(buffer, "NNIOTM") != NULL) {
+#ifdef NTP
+ char str_time[50];
+
+ //printf("Trying to update time...\r\n");
+ if (ntp.setTime("0.pool.ntp.org") == 0) {
+ //printf("Set time successfully\r\n");
+ time_t ctTime;
+ ctTime = time(NULL);
+
+ //printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
+ sprintf(str_time, "%s", ctime(&ctTime));
+ udp_server.sendTo(ep_udp_client, str_time, strlen(str_time));
+ }
+ else {
+ //printf("Error\r\n");
+ sprintf(str_time, "ERR");
+ udp_server.sendTo(ep_udp_client, str_time, strlen(str_time));
+ }
+#elif
+ //printf("NTP disabled\r\n");
+ sprintf(str_time, "DIS");
+ udp_server.sendTo(ep_udp_client, str_time, strlen(str_time));
+#endif
+ } // NNIOTM
+
break;
// length = 19, SET NETWORK CONFIGURATION
// Format: 4E 4E 49 4F C0 A8 00 78 FF FF FF 00 C0 A8 00 01 00 00 01
--- a/readme.txt Fri Sep 26 20:07:34 2014 +0000
+++ b/readme.txt Fri Sep 26 20:32:57 2014 +0000
@@ -11,11 +11,20 @@
3. UDP SERVER PORT Command
+ Send: NNIOUP
+ Receive: 11000
-
-3. Set new network configuration
+
+4. Set time using NTP Command
+ + Send NNIOTM
+ + Receive:
+ DIS: if NTP is disabled
+ ERR: if cannot update time
+ Successful: Fri Sep 26 20:28:01 2014 {0A}
+
+5. Set new network configuration
+ Send: 19 bytes in total, NNIO + 15-byte
15-byte = 4-byte IP address + 4-byte subnet + 4-byte gateway + 3-byte MAC
+
+
INTERFACING SECTION (TCP)
4. Receiving Protocol: 58-bytes in total
+ Field ID (4-bytes) = NNIO
