Shop OBEX P1 Docs P2 Docs Learn Events
Anyone having SNTP / RTC issue on Spinneret today? — Parallax Forums

Anyone having SNTP / RTC issue on Spinneret today?

RforbesRforbes Posts: 281
edited 2012-12-05 20:29 in Accessories
Hey all,

Yesterday the sntp protocol on my spinneret worked fine. Today, I keep getting 31/12/2013 for the date (Dec 31, 2013)

I'm trying to troubleshoot it and I'm pretty sure it's the sntp object that isn't calculating it correctly. But if anyone else is getting the correct date after using SNTP then I guess that's not the issue (using the same object of course.)

Comments

  • Mike GMike G Posts: 2,702
    edited 2012-12-04 14:29
    I'm getting 13/229/2013. This is probably a good time to figure out what the heck is going on with the object since the issue is easily reproducible.
  • RforbesRforbes Posts: 281
    edited 2012-12-04 16:16
    Phew... I won't say I'm glad you're having an issue too, but man I was scratching my head on this. I'll try to figure something more out, but I'm not too confident on my skill set yet.
    DAT
      approot               byte    "\", 0 
      defaultpage           byte    "index.htm", 0
      logfile               byte    "log.xml", 0
      binFile               byte    $0[13]
      binDir                byte    $0[9]
      loadFile              byte    $0[13]  'note
      FS                    byte    "/", 0
      crlf                  byte    13, 10, 0
      crlf_crlf             byte    13, 10, 13, 10, 0
      tempNum               byte    "0000",0
      numBuff              ੲ摩猽彬癳㑮弲㐲ਵ㸊琼⁤汣獡㵳猢畯捲≥㰾牢㰾琯㹤⼼牴㸊琼ੲ摩猽彬癳㑮弲㐲ਸ਼㸊琼⁤汣獡㵳猢畯捲≥‾†䐠⁄㴺䠠⁈ 㐲††††††††††††⌦㤳☻瑬ⴻ搠祡⁳桴獩礠慥
    

    Somehow, between the last time I saved and shutdown the propeller tool just now, I got the HTTPServer object file corrupted or something, shown above. wth??

    Also- earlier today, I was able to get something outta pst. Shown below:
    PRI GetSntp(id) | tempMask
    
        'pst..str(string(13, "GET SNTP Time"))
        tempMask := tcpMask
        SetTcpSocketMaskById(id, 0)
        
           
        Socket.Close(id)
        pause(delay)
        'pst..str(string(13, "Initialize UDP Socket"))
        InitializeSntpUdpSocket(id)
        pause(delay)
    
        'pst..str(string(13, "Request Time"))
        if GetSntpTime(id, @tempBuff)
    '                        Decode 64-Bit time from server
          pst.Str(String("Got this"))      
    '≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈       
             if sntp.GetTransmitTimestamp(Zone,@tempBuff,@LongHIGH,@LongLOW)
                                           '(Offset,BufferAddress,Long1,Long2)
                 pst.Str(String("Got something"))
             else
                 pst.Str(String("Got nothing")) 
               
    '               Display Reference/Sync TimeZone corrected Time           
    '≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈       
              'DisplayHumanTime
    
    '                         Set RTC to Internet Time
             'pst..str(string(13, "SET RTC"))
    '≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈
             {{ rtc.SetDateTime(byte[@MM_DD_YYYY][3],   { <- Month 
                            } byte[@MM_DD_YYYY][2],   { <- Day 
                            } word[@MM_DD_YYYY][0]-2000,   { <- Year 
                            } byte[@DW_HH_MM_SS][3],  { <- (day of week)
                            } byte[@DW_HH_MM_SS][2],  { <- Hour
                            } byte[@DW_HH_MM_SS][1],  { <- Minutes
                            } byte[@DW_HH_MM_SS][0])  { <- Seconds }
              }}
              ''PUB writeTime(second, minute, hour, day, date, month, year) 
              rtc.writeTime(byte[@DW_HH_MM_SS][0],        { <- second 
                            } byte[@DW_HH_MM_SS][1],      { <- minute 
                            } byte[@DW_HH_MM_SS][2],      { <- hour 
                            } byte[@DW_HH_MM_SS][3]+2,      { <- (day of week)
                            } byte[@MM_DD_YYYY][2],       { <- date
                            } byte[@MM_DD_YYYY][3],       { <- month
                            } word[@MM_DD_YYYY][0])  { <- year }
               
              
    
        pst.str(string("test"))
        pst.newline
        pst.dec(byte[@MM_DD_YYYY][0])
        pst.Newline
        pst.dec(byte[@MM_DD_YYYY][1])
        pst.Newline    
        pst.dec(byte[@MM_DD_YYYY][2])
        pst.Newline
        pst.dec(byte[@MM_DD_YYYY][3])
        pst.Newline        
    
        
        ' Reset the socket
        Socket.Disconnect(id)
        pause(delay)
    
        'Socket.SocketClose(id)
        'pause(delay)
        
        ' Reset the tcpMask 
        tcpMask := tempMask
        
        InitializeSocket(id)
        pause(delay)
        
        return
    
    

    It's interesting that you got "13/229/2013" from the rtc.readTime though.... My date is 31/12/2013 but if I use pst as I've shown above:

    The pst.Dec(byte[@MM_DD_YYYY][X]) showed the values 7, 221, 229 and 13. I don't remember which order now, and I also get nothing but 0's now. I haven't changed the code since earlier, at all.
  • RforbesRforbes Posts: 281
    edited 2012-12-05 18:07
    Update- the problem is in the HumanTime method of SNTP Simple Network Time Protocol v1.0.1. I'll try to get the HumanTime method worked out but it's still pretty challenging for me.

    (I'm still trying to figure out how HumanTime does everything, so in the mean time I wrote a sample that works. It's clunky and nothing to be proud of, but it does work. I'm going to see if I can adapt it for use in the sntp object soon.)

    In case anyone needs to get the sntp functionality on the spinneret working quickly, here's my sample. It might help you figure out a much better way to do it.
    {{
    SAMPLE:
    
      *Alternative way to use UTC seconds to determine date from an NTP time server.
      *Does NOT adjust for daylight savings time.
      *Does NOT work after feb 29th, 2020 unless you place 2020 as a condition for leap year.
    
      *Here is a good website for calculating UTC.
       http://www.mbari.org/staff/rich/utccalc.htm
    
      *Example:
                 April 23, 2015, 8:25:49 GMT would be a UTC value of 1429777549
                 Enter this UTC value in pst and it'll spit out the date and time.
                 If you're in Eastern time zone, it'll tell you 3:25:49 if you have -5 in the Zone constant.
    
    }}  
    
    CON
      _clkmode = xtal1 + pll16x     
      _xinfreq = 5_000_000
    
    utc2010 = 1262304000  'This is the UTC seconds value of Jan 1, 2010, 0:00 hours
    Zone    = -5          'Time zone in relation to GMT.  example: EST =  GMT-5, so enter  -5 for this constant.
    
    VAR
    
      long day,month,year,hours,minutes,seconds
      
    OBJ
      pst:  "parallax serial terminal"
    
    pub Main
    
      pst.Start(115_200)
    
        pst.Str(String("Starting...")) 
        pst.Newline
      repeat
    
        pst.Str(String("Enter UTC seconds value:"))
    
        seconds:=pst.DecIn
        pst.Dec(seconds)
    
        Get_Date
    
        pst.NewLine    
        pst.Str(String("Year: "))
        pst.Dec(year)
        pst.NewLine
        pst.Str(String("Month: "))
        pst.Dec(month)
        pst.NewLine
        pst.Str(String("Day: "))
        pst.Dec(day)
        pst.NewLine
        pst.Str(String("Hours: "))
        pst.Dec(Hours)
        pst.NewLine
        pst.Str(String("Minutes: "))
        pst.Dec(Minutes)
        pst.NewLine
        pst.Str(String("Seconds: "))
        pst.Dec(Seconds)
        pst.NewLine
        pst.Str(String("-----------------"))
        pst.NewLine
        pst.NewLine
            
    pub Get_Date
    
      seconds-=utc2010      'Subtract the value of utc2010 from the value we got from the time server.
      seconds+=(Zone*3600)  'Adjust the value again for our time zone.
      year:=2010            'This is our starting year.
      Month:=1              '...our starting month.
      day:=1                '...our starting day.
      
      repeat while seconds=>86400                             'More than a day in seconds left?
    
        If (month==1) and (seconds=>86400)                    'Month is 1 and more than a day in seconds left?        
                                                            
          if ((daycounter(31))== 31) AND (seconds=>86400)     'Did we max our day value for the month?     
            month:=2                                          'move to next month      
            Day:=0                                            'set first day value to 0
    
        If (month==2) and (seconds=>86400) and ((year==2012) OR (year==2016))   'same as above- leap year??
          
          if ((daycounter(29))== 29) AND (seconds=>86400)
            month:=3   
            Day:=0 
    
        If (month==2) and (seconds=>86400)
          
          if ((daycounter(28))== 28) AND (seconds=>86400)     'same as above- not a leap year??
            month:=3   
            Day:=0
    
        If (month==3) and (seconds=>86400)                    'same for all remaining months
          
          if ((daycounter(31))== 31) AND (seconds=>86400)
            month:=4
            Day:=0
            
        If (month==4) and (seconds=>86400)
          
          if ((daycounter(30))== 30) AND (seconds=>86400)
            month:=5
            Day:=0
            
        If (month==5) and (seconds=>86400)
          
          if ((daycounter(31))== 31) AND (seconds=>86400)
            month:=6
            Day:=0
            
        If (month==6) and (seconds=>86400)
          
          if ((daycounter(30))== 30) AND (seconds=>86400)
            month:=7
            Day:=0
            
        If (month==7) and (seconds=>86400)
          
          if ((daycounter(31))== 31) AND (seconds=>86400)
            month:=8
            Day:=0
            
        If (month==8) and (seconds=>86400)
          
          if ((daycounter(31))== 31) AND (seconds=>86400)
            month:=9
            Day:=0
            
        If (month==9) and (seconds=>86400) 
          
          if ((daycounter(30))== 30) AND (seconds=>86400)
            month:=10
            Day:=0
            
        If (month==10) and (seconds=>86400)
        
          if ((daycounter(31))== 31) AND (seconds=>86400)
            month:=11
            Day:=0
            
        If (month==11) and (seconds=>86400)
          
          if ((daycounter(30))== 30) AND (seconds=>86400)
            month:=12
            Day:=0
            
        If (month==12) and (seconds=>86400)
          
          if ((daycounter(31))== 31) AND (seconds=>86400)
            year:= year+1                                        'Still have more seconds? Increment year and start over.
            month:=1
            Day:=0
    
      Get_Time
    
    pub daycounter(maxday)
    
            repeat while (seconds=>86400)         
               seconds-=86400                     
               day++                              
               if day == maxday                   
                 quit                             
    
            return day                            
    
    pub Get_Time
    
      Hours:=0
      Minutes:=0
      repeat while (seconds=>60)
        seconds-=60
        minutes++
        if minutes == 60
           hours++
           minutes:=0
    
    
  • Mike GMike G Posts: 2,702
    edited 2012-12-05 20:29
    Nice work. Thanks for sharing.
Sign In or Register to comment.