在Arduino中获取API时间

时间:2017-09-14 23:52:55

标签: arduino arduino-esp8266

我正在尝试使用API​​获取当前的本地时间。我正在使用WEMOS D1 Mini和blynk的get方法从API返回JSON并存储它。

我使用此代码

<a>

但我不能在长时间变量中获得时间。

1 个答案:

答案 0 :(得分:0)

你可以用更简单的方式做到这一点。 您需要将WebHook小部件添加到您的应用程序。在webhoook小部件中,您需要放置https://api.bot-dev.org/time/网址。并将此小部件分配给虚拟引脚,让我们说V0。 Webhook小部件将在触发后返回对硬件的响应。所以你的代码应该是这样的:

BLYNK_WRITE(V0) {
  //here you'll get response from the webhook
  json = param.asStr();
}

void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
}

void loop() {
  Blynk.run();

  //trigger the webhook
  Blynk.virtualWrite(V0, 1); //you can send any value to trigger webhook
}

请注意,您还需要从主循环中移出Blynk.virtualWrite以避免flooding

Here is有关webhook小部件的更多详细信息。