最近所有设备定时任务不工作-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1905|回复: 7

[已解答] 最近所有设备定时任务不工作

[复制链接]
发表于 2020-6-28 12:12 | 显示全部楼层 |阅读模式
Arduino IDE 1.8.12
ESP 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();
}


定时任务定义如附图:



定时任务定义

定时任务定义
 楼主| 发表于 2020-6-28 17:46 | 显示全部楼层
1、在COM口里查看设备运行信息,时间显示Sun Jun 28 09:35:09 2020,(正确时间是17:35),不知是否正确,一下是设备的log

17:35:10.245 -> [21887] Current time: Sun Jun 28 09:35:09 2020
17:35:10.245 ->
17:35:10.245 -> [21888] NTP time: 1593308109
17:35:10.245 -> [21888] time (millis() - ntpFreshTime): 21888
17:35:10.245 -> [21888] ntpGetTime: 0
17:35:10.245 -> [21889] 1
17:35:10.245 -> [21890] ==== needInit ====
17:35:10.245 -> [21893] message: /share/device?deviceName=B49AA3DEWF0QNPE3RIHUPE94&key=ac06381e4172
17:35:10.245 -> [21900] blinker server begin
17:35:10.245 -> [21903] Freeheap: 29896
17:35:11.439 -> [23066] HTTPS begin: https://iot.diandeng.tech/api/v1/user/device/share/device?deviceName=B49AA3DEWF0QNPE3RIHUPE94&key=ac06381e4172
17:35:11.439 -> [23067] HTTPS payload: /share/device?deviceName=B49AA3DEWF0QNPE3RIHUPE94&key=ac06381e4172
17:35:11.439 -> [23074] [HTTP] status... code: 200
17:35:11.439 -> [23079] {"detail": {"users": []}, "message": 1000}
17:35:11.439 -> [23083] payload: {"users":[]}
17:35:11.439 -> [23087] sharers data: {"users":[]}
17:35:11.439 -> [23088] load timing
17:35:11.439 -> [23091] load timing taskCount: 0
17:35:11.439 -> [23093] freshTiming wDay: 0, nowMins: 575, nowSeconds: 34511
17:35:11.439 -> [23098] nextTask: 10  apartSeconds: 51889 wDay: 0
17:35:11.439 -> [23102] cbackData: 10
17:35:11.439 -> [23104] change apartSeconds: 3600
17:35:11.541 -> [23208] Connecting to MQTT...
17:35:12.701 -> [24337] MQTT Connected!
17:35:12.701 -> [24337] Freeheap: 9064
17:35:12.701 -> [24337] millis: 24337, connect_time: 21890
17:35:12.701 -> [24337] MQTT conn init success
17:35:12.701 -> [24337] =======================================================
17:35:12.701 -> [24342] =========== Blinker Auto Control mode init! ===========
17:35:12.701 -> [24348] Warning!EEPROM address 0-1279 is used for Auto Control!
17:35:12.701 -> [24353] =========== DON'T USE THESE EEPROM ADDRESS! ===========
17:35:12.701 -> [24359] =======================================================
17:35:12.701 -> [24365] _______autoStart_______
17:35:12.771 -> [24422] print: {"btn-abc":{"swi":"off","clr":"#C0C0C0","tex":"开灯","tex1":"关着呢"}}
17:35:12.771 -> [24422] Proto print...
17:35:12.771 -> [24423] Freeheap: 9064
17:35:12.771 -> [24424] isJson: {"data":{"btn-abc":{"swi":"off","clr":"#C0C0C0","tex":"开灯","tex1":"关着呢"}},"fromDevice":"B49AA3DEWF0QNPE3RIHUPE94","toDevice":"99a391f9204262a13caf9672f4c60b23","deviceType":"OwnApp"}
17:35:12.771 -> [24442] MQTT Publish...
17:35:12.771 -> [24444] Freeheap: 9064
17:35:12.771 -> [24446] _print_times: 1
17:35:12.873 -> [24524] {"data":{"btn-abc":{"swi":"off","clr":"#C0C0C0","tex":"开灯","tex1":"关着呢"}},"fromDevice":"B49AA3DEWF0QNPE3RIHUPE94","toDevice":"99a391f9204262a13caf9672f4c60b23","deviceType":"OwnApp"}
17:35:12.873 -> [24531] ...OK!
17:35:12.873 -> [24532] Freeheap: 9064
17:35:12.873 -> [24534] Freeheap: 10096
17:35:12.873 -> [24559] 设备时间为:9:35
17:35:15.924 -> [27595] 设备时间为:9:35
17:35:18.959 -> [30632] 设备时间为:9:35
17:35:22.002 -> [33658] 设备时间为:9:35
17:35:25.009 -> [36687] 设备时间为:9:35
17:35:28.047 -> [39717] 设备时间为:9:35
17:35:31.076 -> [42740] 设备时间为:9:35
17:35:34.112 -> [45770] 设备时间为:9:35
17:35:37.121 -> [48800] 设备时间为:9:35
17:35:40.169 -> [51832] 设备时间为:9:35
17:35:42.876 -> [54535] MQTT Ping!
17:35:42.876 -> [54535] Freeheap: 10096
17:35:43.425 -> [55114] 设备时间为:9:35
17:35:46.474 -> [58140] 设备时间为:9:35
17:35:49.507 -> [61172] 设备时间为:9:35

2、程序中添加如下代码,检查定时任务是否设置成功,结果放回为:0,log如下:17:44:42.625 -> [51978] 设备上定时设置0
17:44:42.625 -> [51978] 设备上定时设置0

    BLINKER_LOG("设备上定时设置",Blinker.timingState());
    BLINKER_LOG("设备上定时设置",Blinker.loopState());
    BLINKER_LOG("设备时间为:",Blinker.hour(),":",Blinker.minute());
 楼主| 发表于 2020-6-28 18:00 | 显示全部楼层
我找到原因了,可能是你们服务器上系统时间或时区设置不对,我把定时任务的时间往后推8个小时就能正常工作了。也就是说如果想让设备上的某个键北京时间18:00打开,我在定时任务里就得设成10:00
发表于 2020-6-28 18:53 | 显示全部楼层
8266 sdk 2.7.x 更新了时区,blinker lib已经对应更新,您确保都是最新版就行了
 楼主| 发表于 2020-6-28 21:08 | 显示全部楼层
我只更新了ESP8266的,blinker的还没更新,明天试一下,谢谢
 楼主| 发表于 2020-6-29 16:58 | 显示全部楼层
已经更新到最新版本了还是不行
发表于 2020-7-4 16:21 | 显示全部楼层
问题解决了吗?

点评

使用最新版的lib即可 https://github.com/blinker-iot/blinker-library/tree/dev_3.0  详情 回复 发表于 2020-7-4 16:29
发表于 2020-7-4 16:29 | 显示全部楼层
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-12-1 05:35 , Processed in 0.191942 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表