Netduino + hangs while calling time using NTP service
#1
Posted 24 October 2012 - 09:51 PM
#2
Posted 24 October 2012 - 10:56 PM
#3
Posted 24 October 2012 - 11:09 PM
http://tf.nist.gov/tf-cgi/servers.cgi
You may also have a network problem. Do a ping sweep on your router DHCP address range and then then arp -a from the command line and see if the Netduino and laptop show up. I use a fixed IP address for the Netduino and a wireless to ehernet adapter. In this configuration, the Netduino will take the MAC address of the wireless adapter.
C:\Users\beb\Desktop>arp -a Interface: 192.168.0.126 --- 0xb Internet Address Physical Address Type 192.168.0.1 98-fc-11-6e-6a-40 dynamic 192.168.0.3 64-70-02-32-6e-38 dynamic <-- Ethernet/wireless adapter(voIP) 192.168.0.4 80-1f-02-19-25-98 dynamic <-- Ethernet/wireless adapter (Netduino) 192.168.0.50 80-1f-02-19-25-98 dynamic <-- Netduino Plus 192.168.0.102 4c-e6-76-12-ba-24 dynamic 192.168.0.103 98-4b-e1-55-78-d6 dynamic 192.168.0.114 c8-bc-c8-71-d6-21 dynamic 192.168.0.117 f4-ce-46-4d-22-bc dynamic 192.168.0.128 64-70-02-32-6e-38 dynamic <-- VoIP 192.168.0.136 08-ed-b9-3d-00-0b dynamic 192.168.0.138 00-1e-64-24-94-98 dynamic 192.168.0.140 c4-17-fe-ac-99-b6 dynamic 192.168.0.142 9c-ad-ef-00-18-78 dynamic 192.168.0.255 ff-ff-ff-ff-ff-ff static 224.0.0.2 01-00-5e-00-00-02 static 224.0.0.22 01-00-5e-00-00-16 static 224.0.0.251 01-00-5e-00-00-fb static 224.0.0.252 01-00-5e-00-00-fc static 239.255.255.250 01-00-5e-7f-ff-fa static 255.255.255.255 ff-ff-ff-ff-ff-ff static
If your Netduino and laptop do not show up in a table like this, then you have a network configuration problem.
Baxter
#4
Posted 24 October 2012 - 11:25 PM
Attached Files
#5
Posted 25 October 2012 - 02:33 AM
Hi Chuck.Skarphedinnos,
I am not best person to help on this question, but I might be able to if I had a little more information.
For instance having the code to look at would allow someone to verify proper usage and declarations.
What classes are you using?
Assuming that you are using C# are you using the proper case etc.
Please provide more information and I think you will likely get the help that you are looking for.
Chuck
Here is the code:
using System; using System.Net; using System.Net.Sockets; using Microsoft.SPOT; public static class Ntp { public static bool UpdateTimeFromNtpServer(string server, int timeZoneOffset) { try { var currentTime = GetNtpTime(server, timeZoneOffset); Microsoft.SPOT.Hardware.Utility.SetLocalTime(currentTime); return true; } catch { return false; } } /// <summary> /// Get DateTime from NTP Server /// Based on: /// http://weblogs.asp.net/mschwarz/archive/2008/03/09/wrong-datetime-on-net-micro-framework-devices.aspx /// </summary> /// <param name="timeServer">Time Server (NTP) address</param> /// <param name="timeZoneOffset">Difference in hours from UTC</param> /// <returns>Local NTP Time</returns> private static DateTime GetNtpTime(String timeServer, int timeZoneOffset) { // Find endpoint for TimeServer var ep = new IPEndPoint(Dns.GetHostEntry(timeServer).AddressList[0], 123); // Make send/receive buffer var ntpData = new byte[48]; // Connect to TimeServer using (var s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) { // Set 10s send/receive timeout and connect s.SendTimeout = s.ReceiveTimeout = 10000; // 10,000 ms s.Connect(ep); // Set protocol version ntpData[0] = 0x1B; // Send Request s.Send(ntpData); // Receive Time s.Receive(ntpData); // Close the socket s.Close(); } const byte offsetTransmitTime = 40; ulong intpart = 0; ulong fractpart = 0; for (var i = 0; i <= 3; i++) intpart = (intpart << 8) | ntpData[offsetTransmitTime + i]; for (var i = 4; i <= 7; i++) fractpart = (fractpart << 8) | ntpData[offsetTransmitTime + i]; ulong milliseconds = (intpart * 1000 + (fractpart * 1000) / 0x100000000L); var timeSpan = TimeSpan.FromTicks((long)milliseconds * TimeSpan.TicksPerMillisecond); var dateTime = new DateTime(1900, 1, 1); dateTime += timeSpan; var offsetAmount = new TimeSpan(timeZoneOffset, 0, 0); var networkDateTime = (dateTime + offsetAmount); return networkDateTime; } }I have tried various examples I found here and there, but they are basically all the same. The program seems to having hard time here:
// Receive Time s.Receive(ntpData);
Sounds like your server may be busy or down for maintenance. I use the DayTime Protocol with the University of Colorado, Boulder servers and they are always available,
http://tf.nist.gov/tf-cgi/servers.cgi
You may also have a network problem. Do a ping sweep on your router DHCP address range and then then arp -a from the command line and see if the Netduino and laptop show up. I use a fixed IP address for the Netduino and a wireless to ehernet adapter. In this configuration, the Netduino will take the MAC address of the wireless adapter.
C:\Users\beb\Desktop>arp -a Interface: 192.168.0.126 --- 0xb Internet Address Physical Address Type 192.168.0.1 98-fc-11-6e-6a-40 dynamic 192.168.0.3 64-70-02-32-6e-38 dynamic <-- Ethernet/wireless adapter(voIP) 192.168.0.4 80-1f-02-19-25-98 dynamic <-- Ethernet/wireless adapter (Netduino) 192.168.0.50 80-1f-02-19-25-98 dynamic <-- Netduino Plus 192.168.0.102 4c-e6-76-12-ba-24 dynamic 192.168.0.103 98-4b-e1-55-78-d6 dynamic 192.168.0.114 c8-bc-c8-71-d6-21 dynamic 192.168.0.117 f4-ce-46-4d-22-bc dynamic 192.168.0.128 64-70-02-32-6e-38 dynamic <-- VoIP 192.168.0.136 08-ed-b9-3d-00-0b dynamic 192.168.0.138 00-1e-64-24-94-98 dynamic 192.168.0.140 c4-17-fe-ac-99-b6 dynamic 192.168.0.142 9c-ad-ef-00-18-78 dynamic 192.168.0.255 ff-ff-ff-ff-ff-ff static 224.0.0.2 01-00-5e-00-00-02 static 224.0.0.22 01-00-5e-00-00-16 static 224.0.0.251 01-00-5e-00-00-fb static 224.0.0.252 01-00-5e-00-00-fc static 239.255.255.250 01-00-5e-7f-ff-fa static 255.255.255.255 ff-ff-ff-ff-ff-ff static
If your Netduino and laptop do not show up in a table like this, then you have a network configuration problem.
Baxter
Hi Baxter.
Thanks for good comment. I am used to do basic things in command prompt but I havent seen this "arp -a" before, brilliant
This seems to be the problem. The thing is I have my ND connected to the laptop and the laptop is connected wifi. Then those two connections are bridget together. If I use other pc (hardwired) and do "arp -a" I cannot see either the laptop nor the ND.
I will try connecting the ND directly to the router
Thanks guys...
#6
Posted 25 October 2012 - 02:57 AM
#7
Posted 25 October 2012 - 08:21 AM
#8
Posted 25 October 2012 - 10:24 AM
#9
Posted 25 October 2012 - 10:52 AM
and Girls.Got it to work
I simply connected the ND to my router directly and whallahh.
Thanks a lot guys.
Skarphedinn.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users