我需要更新一些通过 Azure IoT 中心连接到 Azure 的设备中的日期和时间。
有没有办法从 IoT 中心获取日期时间?
如何管理时区?
哪个时区将提供 Azure IoT 中心?
还有其他选择吗?
最佳答案
不知道 Azure IoT 中心中存在此类 API 接口(interface),但是,您的选项包括 -
- 针对公共(public)时间服务器池 (
pool.ntp.org
) 使用 NTP。我会使用来自 NIST 或其他资金比 ntp-org 实体更好的主机 - https://tf.nist.gov/tf-cgi/servers.cgi - 编写一个 Azure 函数,该函数根据从设备发送的位置查询参数(GET 或 POST)返回日期/时间字符串。例如
http://somethingSomething.azurewebsites.net/api/now?location=NewYork
- 使用现成的公共(public) REST API,即 http://worldtimeapi.org/
通过 HTTPS“滥用”您的 IoT 中心端点,即使对于 400 错误请求也会返回日期/时间,例如:
$ curl https://poorlyfundedskynet.azure-devices.net -i HTTP/1.1 400 Bad Request Content-Length: 157 ..snip other headers.. Date: Wed, 11 Dec 2019 16:16:51 GMT
注意:仅限 HTTPS。优点:您可以与同一位主持人讨论所有事情。缺点:无法保证时间戳准确,但其他所有服务也是如此。接受一点风险! :)
编辑:
链接到此relevant GitHub issue (在适用于 C 的 Azure IoT 中心客户端 SDK 下)。
关于azure - 如何从 Azure IoT 中心获取设备上的日期时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59289678/