NTPClient - can you use without WiFi?

Hello, I am generally new to Arduino. I want to add computer timestamps with real external time to my serial print outputs, to track data against real time. I would happy to use my computer time, but I looked into it, and its not clear that its easy to interrogate my computer's time and feed it to my code.

I discovered there is an NTPClient library, which would do exactly what I want, but it seems to be set up to use WiFi only (I presume so that if you have an Arduino set up with a WiFi shield running under independent power it can get the time remotely with Wifi. For the moment I always use my Arduino connected to/powered by my USB, as I learn to code - the mechatronics stuff for me will follow.

Can anyone advise if I can use my Arduino Uno running with my USB cable, and access NTPClient via the library? If no, is there any work around for my general problem?

Thanks, Steven Lightfoot, Canada

NTP stands for Network Time Protocol so you have to have a network connection for it to work.

If you will always be connected to a PC you could write code on the PC to take the serial data and add a timestamp from the PC.

Another possibility is to add a real time clock (RTC) to your Arduino and get the time and date from that. I would recommend a DS3231 based one. It will need to be set initially from the PC.

Thank you. I am networked for sure. I dont have the capability to write code on the PC/send serial data to my Arduino, maybe one day.

I am attracted to the NTPClient library and it looks it would do what I want, except it uses Wifi. Do you know if it can be easily adapted to use normal hardwired network IP addresses?

NTP works over wired Ethernet connections also (that is where my PC gets its time). I don't know what the Arduino library does, but if it did support wired Ethernet you would need some type of Ethernet adapter on your Arduino.

The NTPclient library doesn't care if the connection is via WiFi or ethernet cable, but the arduino must be part of a network. When connected to a PC via USB cable, the Arduino is not part of a network. The USB cable emulates a simple serial/UART connection. That doesn't make it part of a network. But perhaps it could if you can find the right software to run on the PC, I don't know.

Thx, yeah I assume that the Arduino library doesn't specifically need WiFi, could use the ethernet cable, but I take your point. The Uno itself isn't part of the network, there could be an ethernet shield for it, but if I am going to have to buy a shield, I'd just buy a Wifi shield. Just trying to find if there is any fast workaround with my existing kit, which there may not be.

This maybe worth checking out:

Perfect, I will check it out. That is generally what I am looking for. I will see if to make it work is within my current capabilities. Thanks!!!! Steven Lightfoot

Btw, that is an excellent website. I have learned a lot already from their vids. I like Paul McWhorter too, if you know him.

Thanks again, this looks perfectly doable, with this great step by step example. I will report back if I manage to get access to NPT server data, without WiFi, via the internet.

1 Like

Again, thanks, this is DEFINITELY doable, but it now requires a but of study of the Processing language to understand some of the details. But I can eventually make it work. Appreciate the help. Steven Lightfoot

If I understand the above correctly, I think you are engaged in an utterly pointless exercise, indeed, more than one.

Practically any freebie terminal programme can record your data on your PC and add a timestamp on each loop. That timestamp is derived from the PC clock, which is regularly updated from the Internet anyway.

Deriving the time from the PC only to feed it back with your data would certainly be hard - and also absurd. But no more absurd than installing an RTC.

Try RealTerm. There are others. All are freebies.

Bingo! Perfect, thanks, I use TeraTerm, I had no idea this feature exists and its exactly what I want. So, problem solved. Thank you!

PS: It has been quite a useful detour to learn about Processing.org and that you can actually get internet API data. and pass it tp the Arduino if you need to. Half the battle here is knowing that things exist and are readily possible, even if you don't yet know the details.

You might also explore data direct to Excel, instead of the terminal. This allows you to have live graphs, which might be useful, and also has PC timestamping.

PLX-DAQ version 2 - now with 64 bit support! (and further new features)

OK thank you.

I am finally getting this to work (even though my immediate problem was solved using the time stamp feature in my serial mon).

This is a REALLY useful thing to know how to do, to do serial comm between Arduino and http API data using Processing serial functions code. Really appreciate the reference. Love this. Steven Lightfoot

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.