为什么nodemcu会自动重启啊-Arduino中文社区 - Powered by Discuz! Archiver

honghonglin 发表于 2021-11-10 16:21

为什么nodemcu会自动重启啊

#define BLINKER_WIFI

#include <Blinker.h>
#include <Wire.h>
#include <RTClib.h>
#include <SoftwareSerial.h>

char auth[] = "5152d66235f0";      
char ssid[] = "test";      
char pswd[] = "12345678";

RTC_DS1307 rtc;

const uint8_t ledPinw =D6;
int w = 0;


int H; //H for hour

unsigned long previousMillis = 0;
const long interval = 14; //Change this value (s)

// 新建组件对象
BlinkerButton Button1("btn-123");

void setColor(int W)
{
    while (w!=W)
    {
      unsigned long currentMillis = millis();
      if (currentMillis - previousMillis >= (1000*interval))
      {
          previousMillis = currentMillis;
          analogWrite(ledPinw,w);
          Serial.println(H);
            if (w!=W && w<W){
            w++;
            }   
            else if (w!=W && w>W)
            {
            w--;
      }
}

void daily()
{
    readTime();
    if(H <8)
    {
      setColor(0);
    }
    else if (H >=8 && H <=9)
    {
      setColor(239);
    }
    else if( H >=9 && H <13)
    {
      setColor(456);
    }
    else if( H >=13 && H <18)
    {
      setColor(784);
    }
    else if (H >=18)
    {
      setColor(0);
    }
}

void readTime()
{
    DateTime now = rtc.now();
    H = now.hour();
}

// 按下按键即会执行该函数
void button1_callback(const String & state)
{
    BLINKER_LOG("get button state: ", state);
    daily();
}

void setup()
{
    // 初始化串口
    Serial.begin(115200);
    BLINKER_DEBUG.stream(Serial);
    BLINKER_DEBUG.debugAll();

    Wire.begin();
    rtc.begin();
    //rtc.adjust(DateTime(2021,10,24,10,10,00)); // 设置时间后续加入ntp对时
    readTime();
   
    // 初始化有LED的IO
    pinMode(ledPinw, OUTPUT);
    Blinker.begin(auth, ssid, pswd);
    Button1.attach(button1_callback);

void loop() {
    Blinker.run();
    readTime();
}

honghonglin 发表于 2021-11-10 16:21

上面是部分代码。。

honghonglin 发表于 2021-11-10 16:22

16:21:51.998 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
16:21:51.998 ->
16:21:51.998 -> Soft WDT reset
16:21:51.998 ->
16:21:51.998 -> >>>stack>>>
16:21:51.998 ->
16:21:51.998 -> ctx: cont
16:21:51.998 -> sp: 3ffffc30 end: 3fffffc0 offset: 01a0
16:21:51.998 -> 3ffffdd0:3399115e 00000002 3fff0644 4021ddbc
16:21:51.998 -> 3ffffde0:00000246 3ffef428 3fff0644 00000048
16:21:51.998 -> 3ffffdf0:00000246 3ffef428 000003ff 40202420
16:21:52.045 -> 3ffffe00:3ffef420 3ffef424 3ffef430 4020250f
16:21:52.045 -> 3ffffe10:0a180a15 3fff1425 00000000 3ffffeb4
16:21:52.045 -> 3ffffe20:3fff16a4 3ffef430 3ffef430 4020256b
16:21:52.045 -> 3ffffe30:3fff16a4 3fff16a4 3ffef430 402039a6
16:21:52.045 -> 3ffffe40:00000000 3fff16a4 00000000 40203024
16:21:52.045 -> 3ffffe50:3fff16a4 3ffef430 3ffef430 4020af2b
16:21:52.045 -> 3ffffe60:00706174 3ffffee0 03000000 4020b0aa
16:21:52.045 -> 3ffffe70:00000000 3ffffe00 00000000 000000f8
16:21:52.045 -> 3ffffe80:3ffffee0 00000001 3ffef430 4020b0e4
16:21:52.045 -> 3ffffe90:3ffef630 00000000 3ffef430 4020db6d
16:21:52.092 -> 3ffffea0:3ffe9188 3fff34e4 3fff34f2 3fff38d4
16:21:52.092 -> 3ffffeb0:3fff38e4 3fff38d4 3fff38d4 00000020
16:21:52.092 -> 3ffffec0:00000000 00000000 00000000 4021d670
16:21:52.092 -> 3ffffed0:4021d664 3ffe9186 3fff0644 4021dcd8
16:21:52.092 -> 3ffffee0:3ffffeb4 3ffffea4 3ffefff0 00000000
16:21:52.092 -> 3ffffef0:4027a7a0 00000001 3ffefff0 402106e5
16:21:52.092 -> 3fffff00:4027a7a0 00000001 3ffefff0 4020515a
16:21:52.092 -> 3fffff10:00000001 00000001 3ffefff0 40205190
16:21:52.092 -> 3fffff20:3fff2614 00000001 4027a7a0 402051c2
16:21:52.092 -> 3fffff30:3fff0458 00000001 3ffef430 00000001
16:21:52.092 -> 3fffff40:00000001 3ffef630 3ffef430 4020e87d
16:21:52.139 -> 3fffff50:0000000a 00000018 3fffff80 402048d6
16:21:52.139 -> 3fffff60:007a1200 7550e72d 3ffef900 3fff07ec
16:21:52.139 -> 3fffff70:00000000 00000000 3fff07d8 4020250f
16:21:52.139 -> 3fffff80:00000000 00000000 00000001 3fff07ec
16:21:52.139 -> 3fffff90:3fffdad0 00000000 3fff07d8 4020ea54
16:21:52.139 -> 3fffffa0:feefeffe 00000000 3fff07d8 4021fc30
16:21:52.139 -> 3fffffb0:feefeffe feefeffe 3ffe86dc 40101155
16:21:52.139 -> <<<stack<<<
16:21:52.139 ->
16:21:52.139 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
16:21:52.184 ->
16:21:52.184 ->ets Jan8 2013,rst cause:2, boot mode:(3,6)
16:21:52.184 ->
16:21:52.184 -> load 0x4010f000, len 3460, room 16
16:21:52.184 -> tail 4
16:21:52.184 -> chksum 0xcc
16:21:52.184 -> load 0x3fff20b8, len 40, room 4
16:21:52.184 -> tail 4
16:21:52.184 -> chksum 0xc9
16:21:52.184 -> csum 0xc9
16:21:52.184 -> v00085190
16:21:52.184 -> ~ld
16:21:52.273 ->
16:21:52.273 ->
16:21:52.273 ->__       __                __
16:21:52.273 -> /\ \   /\ \    __      /\ \            v0.3.80210803
16:21:52.273 -> \ \ \___ \ \ \/\_\    ___\ \ \/'\      __   _ __   
16:21:52.273 ->\ \ '__`\\ \ \ \/\ \ /' _ `\ \ , <    /'__`\/\`'__\
16:21:52.273 ->   \ \ \L\ \\ \ \_\ \ \/\ \/\ \ \ \\`\ /\__/\ \ \./
16:21:52.273 ->    \ \_,__/ \ \__\\ \_\ \_\ \_\ \_\ \_\ \____\\ \_\
16:21:52.273 ->   \/___/   \/__/ \/_/\/_/\/_/\/_/\/_/\/____/ \/_/
16:21:52.273 ->   To better use blinker with your IoT project!
16:21:52.273 ->   Download latest blinker library here!
16:21:52.273 ->   => https://github.com/blinker-iot/blinker-library
16:21:52.273 ->
16:21:52.273 -> _aliType:
16:21:52.273 -> _duerType:
16:21:52.320 -> _miType:
16:21:52.320 -> _authKey: 5152d66235f0
16:21:52.320 -> Connecting to test
16:21:52.320 -> ESP8266_MQTT initialized...
16:21:52.320 ->
16:21:52.320 -> ===========================================================
16:21:52.320 -> ================== Blinker Timer loaded! ==================
16:21:52.320 ->      EEPROM address 1536-2431 is used for Blinker Timer!
16:21:52.320 -> ========= PLEASE AVOID USING THESE EEPROM ADDRESS! ========
16:21:52.320 -> ===========================================================
16:21:52.320 ->
16:21:52.320 -> countdown state: false
16:21:52.320 -> _cdRunState: 0
16:21:52.320 -> _totalTime: 0
16:21:52.320 -> _runTime: 0
16:21:52.320 -> _action:
16:21:52.320 -> loop state: false
16:21:52.367 -> _lpRunState: 0
16:21:52.367 -> _times: 0
16:21:52.367 -> _tri_times: 0
16:21:52.367 -> _time1: 0
16:21:52.367 -> _action1:
16:21:52.367 -> _time2: 0
16:21:52.367 -> _action2:
16:21:52.367 -> _lpData: 0
16:21:52.367 -> checkNum count: 3
16:21:52.367 -> checkNum count: 3
16:21:52.367 -> checkNum count: 3
16:21:52.367 -> checkNum count: 3
16:21:52.367 -> checkNum count: 3
16:21:52.367 -> checkNum count: 3
16:22:05.763 -> WiFi Connected.
16:22:05.763 -> IP Address:
16:22:05.763 -> 192.168.43.63
16:22:05.763 -> begin: http://iot.diandeng.tech/api/v1/user/device/diy/auth?authKey=5152d66235f0&version=0.1.0&protocol=mqtt
16:22:06.022 -> GET... code: 200
16:22:06.022 -> reply was:
16:22:06.022 -> ==============================
16:22:06.022 -> {"detail": {"broker": "blinker", "deviceName": "26E77DDF4AGHSKPEVB7IO8UD", "host": "mqtt://broker.diandeng.tech", "iotId": "CwLLjvoQqAPBdGGxxxcWzuNyaQ", "iotToken": "Gx4NcyfAadcrY3itytMuAJSEzWiR5Ezm", "port": "1883", "productKey": "blinker", "uuid": "26f311aa1ee011ec928b5254"}, "message": 1000}
16:22:06.022 -> ==============================
16:22:06.022 -> _num: 4
16:22:06.022 -> ====================
16:22:06.070 -> DEVICE_NAME_MQTT: 26E77DDF4AGHSKPEVB7IO8UD
16:22:06.070 -> MQTT_PRODUCTINFO_MQTT: blinker
16:22:06.070 -> MQTT_ID_MQTT: 26E77DDF4AGHSKPEVB7IO8UD
16:22:06.070 -> MQTT_NAME_MQTT: CwLLjvoQqAPBdGGxxxcWzuNyaQ
16:22:06.070 -> MQTT_KEY_MQTT: Gx4NcyfAadcrY3itytMuAJSEzWiR5Ezm
16:22:06.070 -> MQTT_BROKER: blinker
16:22:06.070 -> HOST: broker.diandeng.tech
16:22:06.070 -> PORT: 1883
16:22:06.070 -> HOST: broker.diandeng.tech
16:22:06.070 -> PORT: 1883
16:22:06.070 -> UUID_MQTT: 26f311aa1ee011ec928b5254
16:22:06.070 -> ====================
16:22:06.070 -> BLINKER_PUB_TOPIC_MQTT: /device/26E77DDF4AGHSKPEVB7IO8UD/s
16:22:06.070 -> BLINKER_SUB_TOPIC_MQTT: /device/26E77DDF4AGHSKPEVB7IO8UD/r
16:22:06.117 -> Freeheap: 35800
16:22:06.117 -> mDNS responder started
16:22:06.117 -> webSocket_MQTT server started
16:22:06.117 -> ws://26E77DDF4AGHSKPEVB7IO8UD.local:81
16:22:07.101 -> Current time: Wed Nov 10 08:22:07 2021
16:22:07.101 ->
16:22:07.101 -> NTP time: 1636503727
16:22:07.101 -> ==== needInit ====
16:22:07.101 -> message: /share/device?deviceName=26E77DDF4AGHSKPEVB7IO8UD&key=5152d66235f0
16:22:07.101 -> blinker server begin
16:22:07.101 -> Freeheap: 37008
16:22:07.334 -> HTTPS begin: http://iot.diandeng.tech/api/v1/user/device/share/device?deviceName=26E77DDF4AGHSKPEVB7IO8UD&key=5152d66235f0
16:22:07.334 -> HTTPS payload: /share/device?deviceName=26E77DDF4AGHSKPEVB7IO8UD&key=5152d66235f0
16:22:07.374 -> status... code: 200
16:22:07.374 -> {"detail": {"users": []}, "message": 1000}
16:22:07.374 -> _type: 16
16:22:07.374 -> payload: {"users":[]}
16:22:07.374 -> sharers data: {"users":[]}
16:22:07.374 -> load timing
16:22:07.374 -> load timing taskCount: 0
16:22:07.374 -> freshTiming wDay: 3, nowMins: 982, nowSeconds: 58927
16:22:07.374 -> nextTask: 10apartSeconds: 27473 wDay: 3
16:22:07.374 -> cbackData: 10
16:22:07.374 -> change apartSeconds: 3600
16:22:07.467 -> millis: 15304, connect_time: 14923
16:22:07.467 -> MQTT conn init success
16:22:07.467 -> =======================================================
16:22:07.514 -> =========== Blinker Auto Control mode init! ===========
16:22:07.514 ->       EEPROM address 0-1279 is used for Auto Control!
16:22:07.514 -> ======= PLEASE AVOID USING THESE EEPROM ADDRESS! ======
16:22:07.514 -> =======================================================
16:22:07.514 -> _______autoStart_______
16:22:07.514 -> _aCount: 1
16:22:07.514 -> new BlinkerAUTO() _num: 0
16:22:07.514 -> _haveAuto: 0
16:22:07.514 -> _autoState: 0
16:22:07.514 -> _logicType: 0
16:22:07.514 -> _compareType: 0
16:22:07.514 -> Connecting to MQTT...
16:22:07.561 -> reconnect_time: 0
16:22:08.283 -> MQTT Connected!
16:22:08.283 -> Freeheap: 36728

honghonglin 发表于 2021-11-10 16:24

honghonglin 发表于 2021-11-10 16:21
上面是部分代码。。

其他代码部分是正常的,删掉其他代码只剩这部分mcu也会重启

lwq1947 发表于 2021-11-10 17:25

honghonglin 发表于 2021-11-10 16:24
其他代码部分是正常的,删掉其他代码只剩这部分mcu也会重启

会不会是硬件的原因:www.arduino.cn/thread-98936-1-1.html

honghonglin 发表于 2021-11-10 18:17

lwq1947 发表于 2021-11-10 17:25
会不会是硬件的原因:www.arduino.cn/thread-98936-1-1.html

应该不是,换了个io口也会这样,只要一点这个按钮就重启了

HAIFAN 发表于 2022-3-5 19:27

老哥有解决这个问题吗?我也遇到这个问题了,能否指点一下,谢谢

奈何col 发表于 2022-3-5 22:36

1. 回调函数中不能有耗时操作;
2. while 循环可能造成了看门狗复位,尝试喂狗。
页: [1]
查看完整版本: 为什么nodemcu会自动重启啊