最近所有设备定时任务不工作
Arduino IDE 1.8.12ESP 8266 lib 2.5.2 或 2.6.3
最新的blinker arduino支持库
问题描述:
1.原来都可以正常工作
2.最近定义定时任务,打开Button1开关,定时任务不能工作
3.所有注册设备定时任务都不能工作
4.倒计时任务都可以正常工作
源代码如下:
/* *****************************************************************
*
* Download latest Blinker library here:
* https://github.com/blinker-iot/blinker-library/archive/master.zip
*
*
* Blinker is a cross-hardware, cross-platform solution for the IoT.
* It provides APP, device and server support,
* and uses public cloud services for data transmission and storage.
* It can be used in smart home, data monitoring and other fields
* to help users build Internet of Things projects better and faster.
*
* Make sure installed 2.5.0 or later ESP8266/Arduino package,
* if use ESP8266 with Blinker.
* https://github.com/esp8266/Arduino/releases
*
* Make sure installed 1.0.2 or later ESP32/Arduino package,
* if use ESP32 with Blinker.
* https://github.com/espressif/arduino-esp32/releases
*
* Docs: https://doc.blinker.app/
* https://github.com/blinker-iot/blinker-doc/wiki
*
* *****************************************************************
*
* Blinker 库下载地址:
* https://github.com/blinker-iot/blinker-library/archive/master.zip
*
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
*
* 如果使用 ESP8266 接入 Blinker,
* 请确保安装了 2.5.0 或更新的 ESP8266/Arduino 支持包。
* https://github.com/esp8266/Arduino/releases
*
* 如果使用 ESP32 接入 Blinker,
* 请确保安装了 1.0.2 或更新的 ESP32/Arduino 支持包。
* https://github.com/espressif/arduino-esp32/releases
*
* 文档: https://doc.blinker.app/
* https://github.com/blinker-iot/blinker-doc/wiki
*
* *****************************************************************/
#define BLINKER_WIFI
#include <Blinker.h>
//GPIO 0
int ledpin = 0;
int switchon=0;
//开关
char auth[] = "70b68c67a262";
char ssid[] = "xxx";
char pswd[] = "xxxxxx";
// 新建组件对象
BlinkerButton Button1("btn-abc");
BlinkerNumber Number1("num-abc");
int counter = 0;
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
if (state=="off") {
digitalWrite(ledpin, HIGH);
switchon=0;
// 反馈开关状态
// Button1.icon("fas fa-toggle-off");
Button1.color("#C0C0C0");
Button1.text("开关关闭了");
Button1.print("off");
} else if (state=="on"){
digitalWrite(ledpin, LOW);
switchon=1;
// 反馈开关状态
//Button1.icon("fas fa-toggle-on");
Button1.color("#1E90FF");
Button1.text("开关打开了");
Button1.print("on");
}
counter++;
Number1.print(counter);
}
// 心跳包函数
void heartbeat() {
if (switchon==0){
Button1.color("#C0C0C0");
Button1.text("开关关闭了");
Button1.print("off");
}
else if (switchon==1){
Button1.color("#1E90FF");
Button1.text("开关打开啦");
Button1.print("on");
}
}
// 如果未绑定的组件被触发,则会执行其中内容
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
//Blinker.print(BlinkerTime);
//tex-smz.print(BlinkerTime);
}
void setup()
{
// 初始化串口
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
// 初始化有开关的IO
pinMode(ledpin, OUTPUT);
//将开关关闭
digitalWrite(ledpin, HIGH);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
//Blinker.attachData(dataRead);
Button1.attach(button1_callback);
//注册一个心跳包
Blinker.attachHeartbeat(heartbeat);
}
void loop() {
Blinker.run();
}
定时任务定义如附图:
1、在COM口里查看设备运行信息,时间显示Sun Jun 28 09:35:09 2020,(正确时间是17:35),不知是否正确,一下是设备的log
17:35:10.245 -> Current time: Sun Jun 28 09:35:09 2020
17:35:10.245 ->
17:35:10.245 -> NTP time: 1593308109
17:35:10.245 -> time (millis() - ntpFreshTime): 21888
17:35:10.245 -> ntpGetTime: 0
17:35:10.245 -> 1
17:35:10.245 -> ==== needInit ====
17:35:10.245 -> message: /share/device?deviceName=B49AA3DEWF0QNPE3RIHUPE94&key=ac06381e4172
17:35:10.245 -> blinker server begin
17:35:10.245 -> Freeheap: 29896
17:35:11.439 -> HTTPS begin: https://iot.diandeng.tech/api/v1/user/device/share/device?deviceName=B49AA3DEWF0QNPE3RIHUPE94&key=ac06381e4172
17:35:11.439 -> HTTPS payload: /share/device?deviceName=B49AA3DEWF0QNPE3RIHUPE94&key=ac06381e4172
17:35:11.439 -> status... code: 200
17:35:11.439 -> {"detail": {"users": []}, "message": 1000}
17:35:11.439 -> payload: {"users":[]}
17:35:11.439 -> sharers data: {"users":[]}
17:35:11.439 -> load timing
17:35:11.439 -> load timing taskCount: 0
17:35:11.439 -> freshTiming wDay: 0, nowMins: 575, nowSeconds: 34511
17:35:11.439 -> nextTask: 10apartSeconds: 51889 wDay: 0
17:35:11.439 -> cbackData: 10
17:35:11.439 -> change apartSeconds: 3600
17:35:11.541 -> Connecting to MQTT...
17:35:12.701 -> MQTT Connected!
17:35:12.701 -> Freeheap: 9064
17:35:12.701 -> millis: 24337, connect_time: 21890
17:35:12.701 -> MQTT conn init success
17:35:12.701 -> =======================================================
17:35:12.701 -> =========== Blinker Auto Control mode init! ===========
17:35:12.701 -> Warning!EEPROM address 0-1279 is used for Auto Control!
17:35:12.701 -> =========== DON'T USE THESE EEPROM ADDRESS! ===========
17:35:12.701 -> =======================================================
17:35:12.701 -> _______autoStart_______
17:35:12.771 -> print: {"btn-abc":{"swi":"off","clr":"#C0C0C0","tex":"开灯","tex1":"关着呢"}}
17:35:12.771 -> Proto print...
17:35:12.771 -> Freeheap: 9064
17:35:12.771 -> isJson: {"data":{"btn-abc":{"swi":"off","clr":"#C0C0C0","tex":"开灯","tex1":"关着呢"}},"fromDevice":"B49AA3DEWF0QNPE3RIHUPE94","toDevice":"99a391f9204262a13caf9672f4c60b23","deviceType":"OwnApp"}
17:35:12.771 -> MQTT Publish...
17:35:12.771 -> Freeheap: 9064
17:35:12.771 -> _print_times: 1
17:35:12.873 -> {"data":{"btn-abc":{"swi":"off","clr":"#C0C0C0","tex":"开灯","tex1":"关着呢"}},"fromDevice":"B49AA3DEWF0QNPE3RIHUPE94","toDevice":"99a391f9204262a13caf9672f4c60b23","deviceType":"OwnApp"}
17:35:12.873 -> ...OK!
17:35:12.873 -> Freeheap: 9064
17:35:12.873 -> Freeheap: 10096
17:35:12.873 -> 设备时间为:9:35
17:35:15.924 -> 设备时间为:9:35
17:35:18.959 -> 设备时间为:9:35
17:35:22.002 -> 设备时间为:9:35
17:35:25.009 -> 设备时间为:9:35
17:35:28.047 -> 设备时间为:9:35
17:35:31.076 -> 设备时间为:9:35
17:35:34.112 -> 设备时间为:9:35
17:35:37.121 -> 设备时间为:9:35
17:35:40.169 -> 设备时间为:9:35
17:35:42.876 -> MQTT Ping!
17:35:42.876 -> Freeheap: 10096
17:35:43.425 -> 设备时间为:9:35
17:35:46.474 -> 设备时间为:9:35
17:35:49.507 -> 设备时间为:9:35
2、程序中添加如下代码,检查定时任务是否设置成功,结果放回为:0,log如下:17:44:42.625 -> 设备上定时设置0
17:44:42.625 -> 设备上定时设置0
,
BLINKER_LOG("设备上定时设置",Blinker.timingState());
BLINKER_LOG("设备上定时设置",Blinker.loopState());
BLINKER_LOG("设备时间为:",Blinker.hour(),":",Blinker.minute()); 我找到原因了,可能是你们服务器上系统时间或时区设置不对,我把定时任务的时间往后推8个小时就能正常工作了。也就是说如果想让设备上的某个键北京时间18:00打开,我在定时任务里就得设成10:00 8266 sdk 2.7.x 更新了时区,blinker lib已经对应更新,您确保都是最新版就行了 我只更新了ESP8266的,blinker的还没更新,明天试一下,谢谢 已经更新到最新版本了还是不行 问题解决了吗? 17865566707 发表于 2020-7-4 16:21
问题解决了吗?
使用最新版的lib即可
https://github.com/blinker-iot/blinker-library/tree/dev_3.0
页:
[1]