5
\$\begingroup\$

Is there a standard way to retrieve Time-of-day onto a "dongle" connected to a computer over USB?

My IoT device is connected over USB for power, but has data connection pins (for firmware download). I would like to get TOD w/o software on computer and am not sure how this is typically done.

I understand I'm out of luck if the user connects my device to a power-brick, but if to a computer, how's the best way to grab the time?

Thanks,
Kent

\$\endgroup\$
5
  • 7
    \$\begingroup\$ No. (need more characters for a comment) \$\endgroup\$
    – brhans
    Commented Nov 14 at 17:08
  • \$\begingroup\$ I was hoping for something like the UDP/TCP time service (port 37). Less complex than NTP but good enough for log messages \$\endgroup\$
    – KentH
    Commented Nov 14 at 17:30
  • 2
    \$\begingroup\$ Native USB knows nothing about UDP or TCP - those are networking protocols. Even if your device enumerated as a networking device, it would still require the TCP/IP software stack running in the host PC. \$\endgroup\$
    – brhans
    Commented Nov 14 at 17:45
  • \$\begingroup\$ The method fully depends on what kind of device your IoT device looks like for the computer - is it a serial port, mass storage device, mouse, keyboard, joystick, network interface, or something else? \$\endgroup\$
    – Justme
    Commented Nov 14 at 18:03
  • \$\begingroup\$ It's been almost 20 years, but I vaguely remember that Windows could sync the clocks of connected MTP devices over USB. I think the old windows media DRM needed the clocks to agree. Could be mixing up protocols though. \$\endgroup\$ Commented Nov 15 at 13:39

2 Answers 2

10
\$\begingroup\$

Is there a standard way to retrieve Time-of-day from a "dongle" connected to a computer over USB?

Not that I'm aware of, and a quick scroll through USB device classes brings up nothing.

I would like to get TOD w/o software on computer and am not sure how this is typically done.

You would need some time source – NTP if you have internet connectivity, or you need to have GPS receiver, or you could have a time-standard receiver (in central Europe, that'd be DCF77). Anyways, nothing that cares about whether it's connected via USB.

I understand I'm out of luck if the user connects my device to a power-brick, but if to a computer, how's the best way to grab the time?

You're conflating things here. A computer is not a USB device, it's a host. Your device can't "query" the computer – it needs the computer to query it to be able to respond. So, that computer would need a driver for your device. To get the computer time to your device, you need that driver (or a program using that driver) to update the device time from the computer.

So, I think what you want is plain impossible.

My IoT device is…

(emphasis mine)

Your Internet of Things device probably has an internet connection, so it can use the internet to query time (e.g., via NTP, but if you can live with a bit of uncertainty / inaccuracy, also via other methods like reading a HTTP response's date: header. Either way, the device would need to know the time zone it is in (that does not automatically follow from e.g. its IP address, at all), and how to convert a UTC time to its own timezone, if you need time stamps to be in local time. (if this is just about logs, you don't.)

Since the A in "Internet of Things" stands for "naming Accuracy", it might be that your IoT device is just part of some network where it's individually addressable. No problem – just propagate time information through that network. Quite likely, that is already implemented in some form if that is a wide-area wireless network.

\$\endgroup\$
5
\$\begingroup\$

Is there a standard way to retrieve Time-of-day from a "dongle" connected to a computer over USB?

Yes, there is. Sort of. In fact, there are two major ways that have relatively low "friction" from user perspective.

Ethernet-over-USB

The "dongle" needs to present as if it were an Ethernet adapter over USB. Which exact class will depend on what OS you're targeting.

When connected to a computer, the dongle will appear in the network manager as a yet another ethernet adapter. By default, link-local IP addresses will be used on both ends of the link.

Web Browser + Billboard

A billboard class device is recognized by most OSes and shows up a notification with a URL. That URL can point to the local name (mdns) of the dongle. User experience:

  1. Plug in dongle.
  2. Notfication appears, click on the link.
  3. Browser opens, a "welcome" web app loads, JS executes, time gets sent to the device.

NTP

You also need to enable NTP (network time protocol) service on the machine. The dongle can then query the time on the computer. The computer's time service will be synchronized with other, more authoritative, time references on the internet (usually).

webusb + Billboard

Using webusb from a web page or a web application, access the dongle from the browser and send the time to it. Which protocol you'd be using for this is up to you. It can be fairly low level. For Windows compatibility, the dongle should expose the descriptors for a winusb device. That way, Windows will load the generic winusb.sys driver for the device automatically. Devices that use this driver can be accessed via webusb on Windows.

A billboard will also offer a notification with a link to click on.

User experience:

  1. Plug in dongle
  2. Notification appears, click link.
  3. A web site on the internet opens.
  4. User is asked for permission to access the dongle via webusb, approves it.
  5. The web site can communicate with the dongle now.
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.