Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Date from netduino plus


  • Please log in to reply
6 replies to this topic

#1 michel capua

michel capua

    Member

  • Members
  • PipPip
  • 26 posts

Posted 13 June 2013 - 09:22 AM

Is it possible to have Date and Time from netduino plus using ethernet interface?



#2 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 13 June 2013 - 10:45 AM

Perhaps I don't understand but assuming you mean like sending Datetime.Now from N+ to another networked device, what could stop you from doing that?



#3 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 13 June 2013 - 05:07 PM

or maybe setting the boards date time from a sever accessed through the ethernet?  like NTP?

If so, here's at least one impl I came across:

http://www.jaypm.com...-automatically/



#4 michel capua

michel capua

    Member

  • Members
  • PipPip
  • 26 posts

Posted 13 June 2013 - 09:46 PM

I need in a NP [color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;font-size:14px;]Date and Time also after that NP is power off and power on.[/color]



#5 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 14 June 2013 - 06:19 AM

Could you please explain in more detail, what you need to do exactly and why, perferably with a brief description of the overall purpose and goal of your project. One-liners tend to be cryptic, especially since english might not be you first language.



#6 Graham.fry

Graham.fry

    Member

  • Members
  • PipPip
  • 15 posts

Posted 06 August 2013 - 12:03 PM

Here is the code to get time from the internet using netduino

 

using System;

using System.Net;

using System.Net.Sockets;

using Microsoft.SPOT;

using System.Threading;

namespace GetTime

{

public class Program

{

public static void Main()

{

var result = UpdateTimeFromNtpServer("time.nist.gov", 2); // gmt + 2

Debug.Print(result ? "Time successfully updated" : "Time not updated");

while (true)

{

Debug.Print("netduino Time is: " + DateTime.Now.ToString());//TimeClient.LocalDate.ToString());

Thread.Sleep(60000);

}

//return result;

}

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;

}

}

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;

}

}

}



#7 cce1911

cce1911

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts
  • LocationGeorgia, USA

Posted 21 August 2013 - 12:56 PM

I used the DS1307 real time clock from Adafruit: http://www.adafruit.com/products/264






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.