在Arduino中使用API获取时间
我正在用API获取当前的本地时间。我使用wemosd1 Mini和blynk的get方法从API返回JSON并存储它 我使用这个代码在Arduino中使用API获取时间,arduino,arduino-esp8266,Arduino,Arduino Esp8266,我正在用API获取当前的本地时间。我使用wemosd1 Mini和blynk的get方法从API返回JSON并存储它 我使用这个代码 #define BLYNK_PRINT Serial #include <ESP8266WiFi.h> #include <ArduinoJson.h> #include <BlynkSimpleEsp8266.h> String json; char auth[] = ""; char ssid[] = "YourNetw
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <BlynkSimpleEsp8266.h>
String json;
char auth[] = "";
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
BLYNK_WRITE(V0) {
json = param.asStr();
}
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop() {
Blynk.run();
Blynk.virtualWrite(V0, "https://api.bot-dev.org/time/");
JsonObject& root = jsonBuffer.parseObject(json);
long time = root[String("ENtime")];
}
#定义BLYNK#u打印序列
#包括
#包括
#包括
字符串json;
char auth[]=“”;
char ssid[]=“YourNetworkName”;
char pass[]=“您的密码”;
BLYNK_写入(V0){
json=param.asStr();
}
无效设置(){
Serial.begin(9600);
Blynk.begin(auth、ssid、pass);
}
void循环(){
Blynk.run();
Blynk.virtualWrite(V0,“https://api.bot-dev.org/time/");
JsonObject&root=jsonBuffer.parseObject(json);
长时间=根[String(“ENtime”)];
}
但是我不能用长时间变量来接收时间。你可以用更简单的方法来实现。 您需要将WebHook小部件添加到应用程序中。在Webhook小部件中,您需要放入
https://api.bot-dev.org/time/
url。并将这个小部件分配给虚拟pin,比如说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
,以避免
有关webhook小部件的更多详细信息。您得到了什么以及您期望得到什么?“工作不正常”不是一个好的问题描述。