Go Down

Topic: Time Library added to Playground (Read 39 times) previous topic - next topic

Marc Peabody

#110
Oct 10, 2010, 04:08 am Last Edit: Oct 10, 2010, 04:10 am by marcpeabody Reason: 1
It's not just you, Mike. I've been trying to sort through this as well.

I haven't tested the sketch yet, but I finally got it to compile on 0021. I'm not terribly familiar with C/C++ :-[ so I wouldn't mind a few "don't do that; do this" comments from the more elite folks.

Here's what I did:
1) I previously had these files in an Ethernet directory under the <mysketches>/libraries directory. This works for other libraries but this TimeNTP code seemed to have issues finding the built-in Ethernet library files. I found the built-in Ethernet library directory and moved the library files for the Time stuff all into there.
2) In all the files (UdpBytewise,UdpString,UdpRaw), change the extern area to:
// extern "C" {
// #include "types.h"
#include "w5100.h"
#include "socket.h"
// }
3) #include <SPI.h> at the top of the sketch
4) Seems like some string methods got dropped from 0021 so these libraries have a hard time calling cstr or capacity on String. In hardware/arduino/cores/arduino/WString.h add the following to the public defs:
   const char * cstr() const {return _buffer;}
   int capacity() {return _capacity;}
5) This one I'm the least sure about what's the best thing to do about the W5100 class - where/how it ought to be instantiated. The below will at least fix the compilation issues... so it's a naive start.
UdpRaw.cpp:
W5100Class wizzy;
int UdpRawClass::available() {
     return wizzy.getRXReceivedSize(_sock);
}
and UdpString
W5100Class wizzyForUdpString;
int UdpStringClass::available() {
     return wizzyForUdpString.getRXReceivedSize(_sock);
}

Marc Peabody

I forgot to mention that references in the Udp code to SnMR need to be updated to SnMR::UDP

I just tried the TimeNTP sketch (with 0021) on my Arduino and I'm successfully getting timestamps outputted to Serial every second.

mitpatterson

I don't know a whole lot about arduino programming ect. but i downloaded the libary(the latestest version, download a few minutes ago) extacted it, copied and pasted it into the libraries file, load a example into arduino and try to compile and get the following errors in red at the bottom:

Code: [Select]
TimeSerial.cpp:12:20: error: Time.h: No such file or directory
TimeSerial:16: error: 'time_t' does not name a type
TimeSerial.cpp: In function 'void setup()':
TimeSerial:19: error: 'requestSync' was not declared in this scope
TimeSerial:19: error: 'setSyncProvider' was not declared in this scope
TimeSerial.cpp: In function 'void loop()':
TimeSerial:28: error: 'timeStatus' was not declared in this scope
TimeSerial:28: error: 'timeNotSet' was not declared in this scope
TimeSerial:30: error: 'timeSet' was not declared in this scope
TimeSerial.cpp: In function 'void digitalClockDisplay()':
TimeSerial:38: error: 'hour' was not declared in this scope
TimeSerial:39: error: 'minute' was not declared in this scope
TimeSerial:40: error: 'second' was not declared in this scope
TimeSerial:42: error: 'day' was not declared in this scope
TimeSerial:44: error: 'month' was not declared in this scope
TimeSerial:46: error: 'year' was not declared in this scope
TimeSerial.cpp: In function 'void processSyncMessage()':
TimeSerial:64: error: 'time_t' was not declared in this scope
TimeSerial:64: error: expected `;' before 'pctime'
TimeSerial:68: error: 'pctime' was not declared in this scope
TimeSerial:71: error: 'pctime' was not declared in this scope
TimeSerial:71: error: 'setTime' was not declared in this scope
TimeSerial.cpp: At global scope:
TimeSerial:76: error: 'time_t' does not name a type


I may be doing something wrong, if i am let me know, its the TimeSerial example sketch all i did was load the example(from the file, examples list) and hit compile. If it matters I am running the IDE 0021 on Windows 7 64 bit. Due to these errors i haven't even got to try loading it to an arduino (i have an uno and duemilanove)

PaulS

Open the IDE, with a blank sketch. Use the Sketch + Import Library... menu item to try to import the Time library. You will probably find that you can't.

This indicates that you did not put the library in the correct place, or correctly in the place that you put it.

Make note of the name of one of the libraries that you CAN import. Use your computer's search capability to find that name. Look at where that name occurs, as opposed to where you put the time library. Look at the structure of that library, as opposed to the time library structure that you created.

The difference should be obvious. If not, post what you find, and we'll help you get it straightened out.

loomi

Hi, I propose a different way to set the date / time for the library. I implemented this because I get the time information out of a HTTP response. Here we find an UTC string where the month is encoded as 3 letter string.

Code: [Select]
Wed, 27 Oct 2010 18:18:04 GMT

I have an example code which works for me:

First define the months as PROGMEM variables.
Code: [Select]

prog_char m_jan[] PROGMEM = "Jan";   // The months for UTC Date conversion
prog_char m_feb[] PROGMEM = "Feb";
prog_char m_mar[] PROGMEM = "Mar";
prog_char m_apr[] PROGMEM = "Apr";
prog_char m_may[] PROGMEM = "May";
prog_char m_jun[] PROGMEM = "Jun";
prog_char m_jul[] PROGMEM = "Jul";
prog_char m_aug[] PROGMEM = "Aug";
prog_char m_sep[] PROGMEM = "Sep";
prog_char m_oct[] PROGMEM = "Oct";
prog_char m_nov[] PROGMEM = "Nov";
prog_char m_dec[] PROGMEM = "Dec";

PROGMEM const char *MONTHS[] =          // as an array
{  
 m_jan, m_feb, m_mar, m_apr, m_may, m_jun, m_jul, m_aug, m_sep, m_oct, m_nov, m_dec
};


Then just iterate over them until it could be matched. datebuf helds a string as shown above.

Code: [Select]

   int h,m,s,y,d,mo = 0;
   char mon[2];
   sscanf(datebuf,"%*s %d %s %d %d:%d:%d",&d,&mon,&y,&h,&m,&s); //split the UTC Date string
 
   while (strcmp_P(mon, (char*)pgm_read_word(&(MONTHS[mo]))) != 0) //decode the month
       mo++;

   // NOTICE: the actual month is mo+1 !!
   setTime(h,m,s,d,mo+1,y); // to set with the time library


I hope this helps.. Who do I best contact to integrate this in the Time Library?

Hope this helps someone
Michael

Go Up