+ Reply to Thread
Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 41

Thread: DEMO: Using SNTP to sync the Spinneret's on-board RTC

  1. #21

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    skynugget,

    Hmm, that's a problem. I just tested the Perl script and it shows the same result...

    Code:
    [bschwabe@IC-Layout ~]$ timetest.pl
     Date: 9 / 9 / 2011 
     Time: 10 : 4 : 38
    ...This means that there is an error in the way the Date is derived from the elapsed seconds since January 1st 1900.

    I'll look into that and fix this

    email - Beau Schwabe || BS Circuit Designs

    web - www.BScircuitdesigns.com
    IC's * Inductive proximity sensors * Misc * and more!!

    Do YOU need custom programming? PIC micro? Basic Stamp? Propeller? A custom PCB design? or even a 3D-print design? ... Then send me an e-mail lets talk, I have +20 years experience.

  2. #22

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    skynugget,

    What Time Zone are you in?... that could make a difference ... I think that's where the problem is in the code.

    email - Beau Schwabe || BS Circuit Designs

    web - www.BScircuitdesigns.com
    IC's * Inductive proximity sensors * Misc * and more!!

    Do YOU need custom programming? PIC micro? Basic Stamp? Propeller? A custom PCB design? or even a 3D-print design? ... Then send me an e-mail lets talk, I have +20 years experience.

  3. #23

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    im in the est, but i had the same problem with GMT as my zone, if it helps.

  4. #24

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    skynugget,

    Keep in mind that GMT does not observe daylight savings so, while I am in CST (GMT-6) right now to see the proper time the GMT value would be GMT-5.

    That's not the problem with the wrong day, although there is some overlap around midnight with the current calculations. I'll see about addressing that.

    email - Beau Schwabe || BS Circuit Designs

    web - www.BScircuitdesigns.com
    IC's * Inductive proximity sensors * Misc * and more!!

    Do YOU need custom programming? PIC micro? Basic Stamp? Propeller? A custom PCB design? or even a 3D-print design? ... Then send me an e-mail lets talk, I have +20 years experience.

  5. #25

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    Found it!

    Inside of 'SNTP Simple Network Time Protocol.spin' change ....

    Code:
    if i&1 <> (i&8)>>4      '   Month has been reached
    ... so that it reads...

    Code:
    if i&1 <> (i&8)>>3      '   Month has been reached

    email - Beau Schwabe || BS Circuit Designs

    web - www.BScircuitdesigns.com
    IC's * Inductive proximity sensors * Misc * and more!!

    Do YOU need custom programming? PIC micro? Basic Stamp? Propeller? A custom PCB design? or even a 3D-print design? ... Then send me an e-mail lets talk, I have +20 years experience.

  6. #26

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    *highfive! thank you sir that worked.

  7. #27

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    Just in case anyone is curious... The logic behind ... if i&1 <> (i&8)>>3

    If you Start with January as 1 and December as 12 and look at the binary nibbles .. bits A and D
    With the exception of February if A and D are different then there are 31 days that month, if they are the same, then there are 30 days. ... With July and Aug being where the 'Flip' is. ...and Yes, I could have just had a lookup table, but I wanted to be different.

    0001 - Jan
    0010 - Feb
    0011 - Mar
    0100 -Apr
    0101 -May
    0110 -Jun
    0111 - Jul
    1000 -Aug
    1001 -Sept
    1010 -Oct
    1011 -Nov
    1100 -Dec

    email - Beau Schwabe || BS Circuit Designs

    web - www.BScircuitdesigns.com
    IC's * Inductive proximity sensors * Misc * and more!!

    Do YOU need custom programming? PIC micro? Basic Stamp? Propeller? A custom PCB design? or even a 3D-print design? ... Then send me an e-mail lets talk, I have +20 years experience.

  8. #28

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    Updated Code:


    Code:
    '#### SNTP Spinneret DEMO v1.0.1
    Revision History:
    02-09-2011        - 'SNTP Spinneret DEMO v1.spin' release
    09-08-2011        - optimized SNTP timeout for a more reliable server hit
                      - Added MAC ID validation (please play nice)
    
    
    'SNTP Simple Network Time Protocol v1.0.1
    Revision History:
    04-07-2011        - File created
    
    09-08-2011        - Minor code update to correct days in Month rendering
                      - and replace bytefill with bytemove for the 'ref-id' string

    email - Beau Schwabe || BS Circuit Designs

    web - www.BScircuitdesigns.com
    IC's * Inductive proximity sensors * Misc * and more!!

    Do YOU need custom programming? PIC micro? Basic Stamp? Propeller? A custom PCB design? or even a 3D-print design? ... Then send me an e-mail lets talk, I have +20 years experience.

  9. #29

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    Jeffa,

    Sorry I did not reply when you asked the question, I didn't see it and somehow missed it until now...

    "Curiosity and learning - Why is _clkmode and _clkfreq set in the "s-35390A_GBSbuild_02_09_2011.spin" driver?
    Is it just for testing when viewport is enabled?"
    ... I believe you are correct, and it is an artifact associated with ViewPort. This section of code is Roy's original code, all that I did was to add a routine FmtDateTime which formats the Date and Time into a human readable string

    email - Beau Schwabe || BS Circuit Designs

    web - www.BScircuitdesigns.com
    IC's * Inductive proximity sensors * Misc * and more!!

    Do YOU need custom programming? PIC micro? Basic Stamp? Propeller? A custom PCB design? or even a 3D-print design? ... Then send me an e-mail lets talk, I have +20 years experience.

  10. #30

    Question Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    And now the other way round ?

    Give some time to RS232, and make a SNTP server ?
    I know it wil not be realy sync, but ..... 1 second acuracy ?

    So I have a ref time on RS422, and want to distribute it with a SNTP spinneret server on local network ?

  11. #31

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    Beau, just wanted to take a sec and say thanks for the code!! It does the job!! Now I have auto time sync over SNTP every time you reboot my spinner. Love it! Just wish there was an easy way to know with daylight saving time starts and stops.

  12. #32

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    There is some bug in the date code of SNTP !
    .... 1/30/2012 and 1/31/2012 give me wrong date of march first ????
    I first think my SNTP server was wrong, I try severals, The time and Year are always corect, but not the day and month !
    Then thinking there was a issue with US MM/DD/YYYY and EU DD/MM/YYYY ... . but not !

    But without code change today I get SMPT 2/0/2012 !!! The RTC is set correct on 2/1/2012 ????

    After the RTC update I put this code to compare to "DisplayHumanTim" from SNTP :


    PauseMSec(950)
    RTC.update
    PST.str(string("RTC time:",13))
    PST.str(RTC.FmtDateTime)
    PST.Char(13)
    PST.str(SNTP.GetReferenceIdentifier(@Buffer,string ("----")))
    PST.Char(13)
    PST.Char(13)


    Result of terminal window:

    SNTP Server Sync time:
    (GMT + 1:00) 02/00/2012
    10:20:51

    RTC time:
    Wed Feb 01, 2012 10:20:51
    GPS

  13. #33

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    I'll look at it in more detail later.... the problem is that the SNTP server reports the current time and date in the number of seconds that have elapsed since Jan 1, 1900 ... That's a lot of seconds since then with a few leap years in between.... Since this year is a leap year, it threw things off.

    email - Beau Schwabe || BS Circuit Designs

    web - www.BScircuitdesigns.com
    IC's * Inductive proximity sensors * Misc * and more!!

    Do YOU need custom programming? PIC micro? Basic Stamp? Propeller? A custom PCB design? or even a 3D-print design? ... Then send me an e-mail lets talk, I have +20 years experience.

  14. #34

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    Beau, any news on leap year throwing the time off with this object? I have an app running on my spinner that has been working great for months but the other day I noticed the reported day set by this SNTP object to be exactly one day off. I know this worked fine last year and I don’t understand what is causing it to be one day behind. For example today is Feb 14, 2012 but when I make a call to get the SNTP time with your object it reports Feb 13, 2012? No errors everything looks fine just one day off?? I wonder if at the end of this month (since there are 29 days in February this year) it will go back to normal??

    Thanks for all the work on the object it really makes my solution look sharp!!

  15. #35

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    JohnR2010,

    I think it's in my calculation of #Leap Years since 1900 but I need to test it for when Feb 29th rolls over. I think there needs to be another check in February to see if the current year is a leap year. In the current Spinneret code it checks for previous leap years, thus where the one day difference error is occurring ... when the current year is a leap year.

    I have not tested this in the Spinneret yet, but only in the Perl code that I originally used to debug in the first place. I still need to implement a check for Feb rollover and if the current year is a leap year or not.

    Here is the Perl code if you or anyone is interested... cut-n-paste this to a file on a Linux operating system, then change the permissions of the file to 555 ... i.e. chmod 555 timetest.pl
    Code:
    #!/usr/bin/perl
    
     use IO::Socket::INET;
    $MySocket=new IO::Socket::INET->new(PeerPort=>123,  #open socket
            Proto=>'udp',
            PeerAddr=>'132.163.4.101');
    
    $data =     chr(227) . chr(0) . chr(0) . chr(148);  #LI/VN/Mode, Stratum, Poll, Precision
    $data = $data . chr(0) . chr(0) . chr(0) . chr(0);  #Root Delay
    $data = $data . chr(0) . chr(0) . chr(0) . chr(0);  #Root Dispersion
    $data = $data . "LOCL";                             #Reference Identifier
    $data = $data . chr(0) . chr(0) . chr(0) . chr(0);  #Reference Timestamp
    $data = $data . chr(0) . chr(0) . chr(0) . chr(0);
    $data = $data . chr(0) . chr(0) . chr(0) . chr(0);  #Originate Timestamp
    $data = $data . chr(0) . chr(0) . chr(0) . chr(0);
    $data = $data . chr(0) . chr(0) . chr(0) . chr(0);  #Receive Timestamp
    $data = $data . chr(0) . chr(0) . chr(0) . chr(0);
    $data = $data . chr(0) . chr(0) . chr(0) . chr(0);  #Transmit Timestamp
    $data = $data . chr(0) . chr(0) . chr(0) . chr(0);
    
    $MySocket->send($data);			            #Waiting to receive data		
    $MySocket->recv($data,56);                          
    $MySocket->close();                                 #received data close socket
    
    @Chars = split("", $data);
    
    $n1 = ord($Chars[40]);				    #Upper 32 bits of Transmit Timestamp
    $n2 = ord($Chars[41]);
    $n3 = ord($Chars[42]);
    $n4 = ord($Chars[43]);
    
    $Seconds = $n4 + $n3*256 + $n2*65536 + $n1*16777216; #Seconds since Jan1, 1900
    
    $Zone =  -6;                                         #GMT - 6 time zone adjust
    #$Zone =  -5;                                         #use GMT - 5 during daylight savings
    
    $Seconds = $Seconds  + 3600*$Zone;
    
    print "Seconds since Jan1, 1900 : $Seconds \n\r";
    
    
    
    
    
    
    $Days = int((($Seconds >> 7)/675)+1);                #Days since Jan1, 1900     {divide seconds by 86,400 and add 1}
    print "   Days since Jan1, 1900 : $Days \n\r";
              
    $DW = ($Days-1) % 7; 			             #Day of Week               
    
    $Years = int($Days / 365);                           #Years since 1900
    print "  Years since Jan1, 1900 : $Years \n\r";
    
    $Days = $Days % 365;                                 #Days this year
    
    $LeapYears = int(($Years-1) / 4);		     #Leap Years since 1900
    $CurrentYear = $Years + 1900 ;                       #Current Year
    
    $Days = $Days - $LeapYears;                          #Leap Year Days Correction
    
    print "          Days this year : $Days \n\r";
    
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    
    $count = 1;					     #Routine to determine
     do {                                                #  - The Current Month 
    $Month = 30;                                         #  - The Current Date       
    $c1 = ($count & 1);                                  #
    $c2 = (($count & 8) >>3);                            # from the number of Days
    if ($c1 != $c2) {                                    # passed in the current year 
        $Month = $Month +1;                              
       }
    if ($count == 2) {
        $Month = 28; 
       }
    
    print "Month : $count Days in Month : $Month \n\r";
    
    if ($Days >= $Month) {
       $Days = $Days - $Month;
       if ($Days <= $Month) {
          $CurrentMonth = $count + 1;
          $CurrentDate  = $Days;  
          $count = 12;
          }     
       }
    $count++;
     } until ($count == 13);
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    $Seconds = $Seconds - ((($Years * 365)*675) *128);   #Seconds this year
    $SS = $Seconds;
    
    print "\n\r";
    print "$SS";
    
    $MM = int($SS / 60);                                 
    $SS = $SS - ($MM*60);                                #Current Seconds
    $HH = int($MM / 60);                                 
    $MM = $MM - ($HH*60);                                #Current Minutes
    $DD = int($HH / 24);                                 
    $HH = $HH - ($DD*24);                                #Current Hour
    
    print "\n\r";
    print " Date: $CurrentMonth / $CurrentDate / $CurrentYear \n\r";
    print " Time: $HH : $MM : $SS \n\r";

    email - Beau Schwabe || BS Circuit Designs

    web - www.BScircuitdesigns.com
    IC's * Inductive proximity sensors * Misc * and more!!

    Do YOU need custom programming? PIC micro? Basic Stamp? Propeller? A custom PCB design? or even a 3D-print design? ... Then send me an e-mail lets talk, I have +20 years experience.

  16. #36

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    Beau, just as an update this code corrected itself after the end of leap day on March 1.

  17. #37

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    JohnR,

    Thanks John, that's what I suspect. Looks like I need to add a check to validate if the current month happens to be February AND if that month is a leap year. Previous years it seems to calculate ok, but if the current month is February and also a leap year it is off by a day.

    email - Beau Schwabe || BS Circuit Designs

    web - www.BScircuitdesigns.com
    IC's * Inductive proximity sensors * Misc * and more!!

    Do YOU need custom programming? PIC micro? Basic Stamp? Propeller? A custom PCB design? or even a 3D-print design? ... Then send me an e-mail lets talk, I have +20 years experience.

  18. #38

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC


    email - Beau Schwabe || BS Circuit Designs

    web - www.BScircuitdesigns.com
    IC's * Inductive proximity sensors * Misc * and more!!

    Do YOU need custom programming? PIC micro? Basic Stamp? Propeller? A custom PCB design? or even a 3D-print design? ... Then send me an e-mail lets talk, I have +20 years experience.

  19. #39

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    Hi, I am trying to use the latest code to update the RTC values, and it seems that it does not want to work for me. The problem I am experiencing is that the code is locked to CST even though I modify the code for EST. I also have an issue that it updates the week day string to a day prior, i.e. MON is shown as SUN. Also, I want the real time to synch to the SNTP server when I click a button on my webserver interface. How would I be able to tell it when to synch with real time?

    I'm new to these forums so if you need further details, I will be happy to fill you in more.

    Thank You!
    Brandon

  20. #40

    Default Re: DEMO: Using SNTP to sync the Spinneret's on-board RTC

    lopezb,

    Welcome to the forum ! feel free to ask any question you want. There are many people here that can help.


    Can you post the exact code that you are using? Use the 'File-->Archive-->Project' option in the Propeller Tool.

    email - Beau Schwabe || BS Circuit Designs

    web - www.BScircuitdesigns.com
    IC's * Inductive proximity sensors * Misc * and more!!

    Do YOU need custom programming? PIC micro? Basic Stamp? Propeller? A custom PCB design? or even a 3D-print design? ... Then send me an e-mail lets talk, I have +20 years experience.

+ Reply to Thread

Similar Threads

  1. AJAX Spinneret LED Demo and IP Camera
    By Mike G in forum Spinneret Web Server
    Replies: 11
    Last Post: 08-21-2011, 10:10 PM
  2. LOVING Spinneret Web Server DEMO v1.2
    By xanadu in forum Spinneret Web Server
    Replies: 9
    Last Post: 04-29-2011, 01:10 PM
  3. DEMO - RFC 2030 (SNTP) Simple Network Time Protocol with UDP packets over port 123
    By Beau Schwabe (Parallax) in forum Spinneret Web Server
    Replies: 13
    Last Post: 02-08-2011, 05:41 AM
  4. DEMO: Easy HTML with the Spinneret
    By Beau Schwabe (Parallax) in forum Spinneret Web Server
    Replies: 4
    Last Post: 01-29-2011, 10:13 PM
  5. Composite graphics demo now works on the Spinneret
    By zoopydogsit in forum Spinneret Web Server
    Replies: 0
    Last Post: 12-22-2010, 01:01 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts