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

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1690|回复: 7

[已解答] 为什么nodemcu会自动重启啊

[复制链接]
发表于 2021-11-10 16:21 | 显示全部楼层 |阅读模式
  1. #define BLINKER_WIFI

  2. #include <Blinker.h>
  3. #include <Wire.h>
  4. #include <RTClib.h>
  5. #include <SoftwareSerial.h>

  6. char auth[] = "5152d66235f0";      
  7. char ssid[] = "test";      
  8. char pswd[] = "12345678";  

  9. RTC_DS1307 rtc;

  10. const uint8_t ledPinw =D6;
  11. int w = 0;


  12. int H; //H for hour

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

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

  17. void setColor(int W)
  18. {
  19.     while (w!=W)
  20.     {
  21.         unsigned long currentMillis = millis();
  22.         if (currentMillis - previousMillis >= (1000*interval))
  23.         {
  24.           previousMillis = currentMillis;
  25.           analogWrite(ledPinw,w);
  26.           Serial.println(H);
  27.             if (w!=W && w<W){
  28.               w++;
  29.             }   
  30.             else if (w!=W && w>W)
  31.             {
  32.               w--;
  33.         }
  34. }

  35. void daily()
  36. {
  37.     readTime();
  38.     if(H <8)
  39.     {
  40.       setColor(0);
  41.     }
  42.     else if (H >=8 && H <=9)
  43.     {
  44.       setColor(239);
  45.     }
  46.     else if( H >=9 && H <13)
  47.     {
  48.       setColor(456);
  49.     }
  50.     else if( H >=13 && H <18)
  51.     {
  52.       setColor(784);
  53.     }
  54.     else if (H >=18)
  55.     {
  56.       setColor(0);
  57.     }
  58. }

  59. void readTime()
  60. {
  61.     DateTime now = rtc.now();
  62.     H = now.hour();
  63. }

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

  70. void setup()
  71. {
  72.     // 初始化串口
  73.     Serial.begin(115200);
  74.     BLINKER_DEBUG.stream(Serial);
  75.     BLINKER_DEBUG.debugAll();

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

  85. void loop() {
  86.     Blinker.run();
  87.     readTime();
  88. }
复制代码
 楼主| 发表于 2021-11-10 16:21 | 显示全部楼层
上面是部分代码。。
 楼主| 发表于 2021-11-10 16:22 | 显示全部楼层
  1. 16:21:51.998 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
  2. 16:21:51.998 ->
  3. 16:21:51.998 -> Soft WDT reset
  4. 16:21:51.998 ->
  5. 16:21:51.998 -> >>>stack>>>
  6. 16:21:51.998 ->
  7. 16:21:51.998 -> ctx: cont
  8. 16:21:51.998 -> sp: 3ffffc30 end: 3fffffc0 offset: 01a0
  9. 16:21:51.998 -> 3ffffdd0:  3399115e 00000002 3fff0644 4021ddbc  
  10. 16:21:51.998 -> 3ffffde0:  00000246 3ffef428 3fff0644 00000048  
  11. 16:21:51.998 -> 3ffffdf0:  00000246 3ffef428 000003ff 40202420  
  12. 16:21:52.045 -> 3ffffe00:  3ffef420 3ffef424 3ffef430 4020250f  
  13. 16:21:52.045 -> 3ffffe10:  0a180a15 3fff1425 00000000 3ffffeb4  
  14. 16:21:52.045 -> 3ffffe20:  3fff16a4 3ffef430 3ffef430 4020256b  
  15. 16:21:52.045 -> 3ffffe30:  3fff16a4 3fff16a4 3ffef430 402039a6  
  16. 16:21:52.045 -> 3ffffe40:  00000000 3fff16a4 00000000 40203024  
  17. 16:21:52.045 -> 3ffffe50:  3fff16a4 3ffef430 3ffef430 4020af2b  
  18. 16:21:52.045 -> 3ffffe60:  00706174 3ffffee0 03000000 4020b0aa  
  19. 16:21:52.045 -> 3ffffe70:  00000000 3ffffe00 00000000 000000f8  
  20. 16:21:52.045 -> 3ffffe80:  3ffffee0 00000001 3ffef430 4020b0e4  
  21. 16:21:52.045 -> 3ffffe90:  3ffef630 00000000 3ffef430 4020db6d  
  22. 16:21:52.092 -> 3ffffea0:  3ffe9188 3fff34e4 3fff34f2 3fff38d4  
  23. 16:21:52.092 -> 3ffffeb0:  3fff38e4 3fff38d4 3fff38d4 00000020  
  24. 16:21:52.092 -> 3ffffec0:  00000000 00000000 00000000 4021d670  
  25. 16:21:52.092 -> 3ffffed0:  4021d664 3ffe9186 3fff0644 4021dcd8  
  26. 16:21:52.092 -> 3ffffee0:  3ffffeb4 3ffffea4 3ffefff0 00000000  
  27. 16:21:52.092 -> 3ffffef0:  4027a7a0 00000001 3ffefff0 402106e5  
  28. 16:21:52.092 -> 3fffff00:  4027a7a0 00000001 3ffefff0 4020515a  
  29. 16:21:52.092 -> 3fffff10:  00000001 00000001 3ffefff0 40205190  
  30. 16:21:52.092 -> 3fffff20:  3fff2614 00000001 4027a7a0 402051c2  
  31. 16:21:52.092 -> 3fffff30:  3fff0458 00000001 3ffef430 00000001  
  32. 16:21:52.092 -> 3fffff40:  00000001 3ffef630 3ffef430 4020e87d  
  33. 16:21:52.139 -> 3fffff50:  0000000a 00000018 3fffff80 402048d6  
  34. 16:21:52.139 -> 3fffff60:  007a1200 7550e72d 3ffef900 3fff07ec  
  35. 16:21:52.139 -> 3fffff70:  00000000 00000000 3fff07d8 4020250f  
  36. 16:21:52.139 -> 3fffff80:  00000000 00000000 00000001 3fff07ec  
  37. 16:21:52.139 -> 3fffff90:  3fffdad0 00000000 3fff07d8 4020ea54  
  38. 16:21:52.139 -> 3fffffa0:  feefeffe 00000000 3fff07d8 4021fc30  
  39. 16:21:52.139 -> 3fffffb0:  feefeffe feefeffe 3ffe86dc 40101155  
  40. 16:21:52.139 -> <<<stack<<<
  41. 16:21:52.139 ->
  42. 16:21:52.139 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
  43. 16:21:52.184 ->
  44. 16:21:52.184 ->  ets Jan  8 2013,rst cause:2, boot mode:(3,6)
  45. 16:21:52.184 ->
  46. 16:21:52.184 -> load 0x4010f000, len 3460, room 16
  47. 16:21:52.184 -> tail 4
  48. 16:21:52.184 -> chksum 0xcc
  49. 16:21:52.184 -> load 0x3fff20b8, len 40, room 4
  50. 16:21:52.184 -> tail 4
  51. 16:21:52.184 -> chksum 0xc9
  52. 16:21:52.184 -> csum 0xc9
  53. 16:21:52.184 -> v00085190
  54. 16:21:52.184 -> ~ld
  55. 16:21:52.273 -> [71]
  56. 16:21:52.273 -> [71]
  57. 16:21:52.273 ->  __       __                __
  58. 16:21:52.273 -> /\ \     /\ \    __        /\ \              v0.3.80210803
  59. 16:21:52.273 -> \ \ \___ \ \ \  /\_\    ___\ \ \/'\      __   _ __   
  60. 16:21:52.273 ->  \ \ '__`\\ \ \ \/\ \ /' _ `\ \ , <    /'__`\/\`'__\
  61. 16:21:52.273 ->   \ \ \L\ \\ \ \_\ \ \/\ \/\ \ \ \\`\ /\  __/\ \ \./
  62. 16:21:52.273 ->    \ \_,__/ \ \__\\ \_\ \_\ \_\ \_\ \_\ \____\\ \_\  
  63. 16:21:52.273 ->     \/___/   \/__/ \/_/\/_/\/_/\/_/\/_/\/____/ \/_/  
  64. 16:21:52.273 ->     To better use blinker with your IoT project!
  65. 16:21:52.273 ->     Download latest blinker library here!
  66. 16:21:52.273 ->     => https://github.com/blinker-iot/blinker-library
  67. 16:21:52.273 ->
  68. 16:21:52.273 -> [105] _aliType:
  69. 16:21:52.273 -> [107] _duerType:
  70. 16:21:52.320 -> [108] _miType:
  71. 16:21:52.320 -> [110] _authKey: 5152d66235f0
  72. 16:21:52.320 -> [112] Connecting to test
  73. 16:21:52.320 -> [118] ESP8266_MQTT initialized...
  74. 16:21:52.320 -> [118]
  75. 16:21:52.320 -> ===========================================================
  76. 16:21:52.320 -> ================== Blinker Timer loaded! ==================
  77. 16:21:52.320 ->      EEPROM address 1536-2431 is used for Blinker Timer!
  78. 16:21:52.320 -> ========= PLEASE AVOID USING THESE EEPROM ADDRESS! ========
  79. 16:21:52.320 -> ===========================================================
  80. 16:21:52.320 ->
  81. 16:21:52.320 -> [146] countdown state: false
  82. 16:21:52.320 -> [147] _cdRunState: 0
  83. 16:21:52.320 -> [149] _totalTime: 0
  84. 16:21:52.320 -> [151] _runTime: 0
  85. 16:21:52.320 -> [152] _action:
  86. 16:21:52.320 -> [155] loop state: false
  87. 16:21:52.367 -> [156] _lpRunState: 0
  88. 16:21:52.367 -> [158] _times: 0
  89. 16:21:52.367 -> [159] _tri_times: 0
  90. 16:21:52.367 -> [161] _time1: 0
  91. 16:21:52.367 -> [163] _action1:
  92. 16:21:52.367 -> [164] _time2: 0
  93. 16:21:52.367 -> [166] _action2:
  94. 16:21:52.367 -> [167] _lpData: 0
  95. 16:21:52.367 -> [169] checkNum count: 3
  96. 16:21:52.367 -> [171] checkNum count: 3
  97. 16:21:52.367 -> [173] checkNum count: 3
  98. 16:21:52.367 -> [175] checkNum count: 3
  99. 16:21:52.367 -> [177] checkNum count: 3
  100. 16:21:52.367 -> [180] checkNum count: 3
  101. 16:22:05.763 -> [13574] WiFi Connected.
  102. 16:22:05.763 -> [13574] IP Address:
  103. 16:22:05.763 -> [13574] 192.168.43.63
  104. 16:22:05.763 -> [13586] [HTTP] begin: http://iot.diandeng.tech/api/v1/user/device/diy/auth?authKey=5152d66235f0&version=0.1.0&protocol=mqtt
  105. 16:22:06.022 -> [13826] [HTTP] GET... code: 200
  106. 16:22:06.022 -> [13827] reply was:
  107. 16:22:06.022 -> [13827] ==============================
  108. 16:22:06.022 -> [13828] {"detail": {"broker": "blinker", "deviceName": "26E77DDF4AGHSKPEVB7IO8UD", "host": "mqtt://broker.diandeng.tech", "iotId": "CwLLjvoQqAPBdGGxxxcWzuNyaQ", "iotToken": "Gx4NcyfAadcrY3itytMuAJSEzWiR5Ezm", "port": "1883", "productKey": "blinker", "uuid": "26f311aa1ee011ec928b5254"}, "message": 1000}
  109. 16:22:06.022 -> [13849] ==============================
  110. 16:22:06.022 -> [13854] _num: 4
  111. 16:22:06.022 -> [13854] ====================
  112. 16:22:06.070 -> [13857] DEVICE_NAME_MQTT: 26E77DDF4AGHSKPEVB7IO8UD
  113. 16:22:06.070 -> [13861] MQTT_PRODUCTINFO_MQTT: blinker
  114. 16:22:06.070 -> [13865] MQTT_ID_MQTT: 26E77DDF4AGHSKPEVB7IO8UD
  115. 16:22:06.070 -> [13869] MQTT_NAME_MQTT: CwLLjvoQqAPBdGGxxxcWzuNyaQ
  116. 16:22:06.070 -> [13873] MQTT_KEY_MQTT: Gx4NcyfAadcrY3itytMuAJSEzWiR5Ezm
  117. 16:22:06.070 -> [13878] MQTT_BROKER: blinker
  118. 16:22:06.070 -> [13881] HOST: broker.diandeng.tech
  119. 16:22:06.070 -> [13884] PORT: 1883
  120. 16:22:06.070 -> [13886] HOST: broker.diandeng.tech
  121. 16:22:06.070 -> [13889] PORT: 1883
  122. 16:22:06.070 -> [13891] UUID_MQTT: 26f311aa1ee011ec928b5254
  123. 16:22:06.070 -> [13894] ====================
  124. 16:22:06.070 -> [13897] BLINKER_PUB_TOPIC_MQTT: /device/26E77DDF4AGHSKPEVB7IO8UD/s
  125. 16:22:06.070 -> [13903] BLINKER_SUB_TOPIC_MQTT: /device/26E77DDF4AGHSKPEVB7IO8UD/r
  126. 16:22:06.117 -> [13909] Freeheap: 35800
  127. 16:22:06.117 -> [13912] mDNS responder started
  128. 16:22:06.117 -> [13915] webSocket_MQTT server started
  129. 16:22:06.117 -> [13917] ws://26E77DDF4AGHSKPEVB7IO8UD.local:81
  130. 16:22:07.101 -> [14923] Current time: Wed Nov 10 08:22:07 2021
  131. 16:22:07.101 ->
  132. 16:22:07.101 -> [14923] NTP time: 1636503727
  133. 16:22:07.101 -> [14923] ==== needInit ====
  134. 16:22:07.101 -> [14924] message: /share/device?deviceName=26E77DDF4AGHSKPEVB7IO8UD&key=5152d66235f0
  135. 16:22:07.101 -> [14928] blinker server begin
  136. 16:22:07.101 -> [14931] Freeheap: 37008
  137. 16:22:07.334 -> [15161] HTTPS begin: http://iot.diandeng.tech/api/v1/user/device/share/device?deviceName=26E77DDF4AGHSKPEVB7IO8UD&key=5152d66235f0
  138. 16:22:07.334 -> [15162] HTTPS payload: /share/device?deviceName=26E77DDF4AGHSKPEVB7IO8UD&key=5152d66235f0
  139. 16:22:07.374 -> [15170] [HTTP] status... code: 200
  140. 16:22:07.374 -> [15174] {"detail": {"users": []}, "message": 1000}
  141. 16:22:07.374 -> [15178] _type: 16
  142. 16:22:07.374 -> [15179] payload: {"users":[]}
  143. 16:22:07.374 -> [15183] sharers data: {"users":[]}
  144. 16:22:07.374 -> [15185] load timing
  145. 16:22:07.374 -> [15187] load timing taskCount: 0
  146. 16:22:07.374 -> [15190] freshTiming wDay: 3, nowMins: 982, nowSeconds: 58927
  147. 16:22:07.374 -> [15195] nextTask: 10  apartSeconds: 27473 wDay: 3
  148. 16:22:07.374 -> [15199] cbackData: 10
  149. 16:22:07.374 -> [15201] change apartSeconds: 3600
  150. 16:22:07.467 -> [15305] millis: 15304, connect_time: 14923
  151. 16:22:07.467 -> [15305] MQTT conn init success
  152. 16:22:07.467 -> [15305] =======================================================
  153. 16:22:07.514 -> [15306] =========== Blinker Auto Control mode init! ===========
  154. 16:22:07.514 -> [15311]      EEPROM address 0-1279 is used for Auto Control!
  155. 16:22:07.514 -> [15317] ======= PLEASE AVOID USING THESE EEPROM ADDRESS! ======
  156. 16:22:07.514 -> [15322] =======================================================
  157. 16:22:07.514 -> [15328] _______autoStart_______
  158. 16:22:07.514 -> [15332] _aCount: 1
  159. 16:22:07.514 -> [15333] new BlinkerAUTO() _num: 0
  160. 16:22:07.514 -> [15336] _haveAuto: 0
  161. 16:22:07.514 -> [15338] _autoState: 0
  162. 16:22:07.514 -> [15340] _logicType: 0
  163. 16:22:07.514 -> [15342] _compareType: 0
  164. 16:22:07.514 -> [15344] Connecting to MQTT...
  165. 16:22:07.561 -> [15347] reconnect_time: 0
  166. 16:22:08.283 -> [16100] MQTT Connected!
  167. 16:22:08.283 -> [16100] Freeheap: 36728
复制代码
 楼主| 发表于 2021-11-10 16:24 | 显示全部楼层
honghonglin 发表于 2021-11-10 16:21
上面是部分代码。。

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

会不会是硬件的原因:www.arduino.cn/thread-98936-1-1.html
 楼主| 发表于 2021-11-10 18:17 | 显示全部楼层
lwq1947 发表于 2021-11-10 17:25
会不会是硬件的原因:www.arduino.cn/thread-98936-1-1.html

应该不是,换了个io口也会这样,只要一点这个按钮就重启了
发表于 2022-3-5 19:27 | 显示全部楼层
老哥有解决这个问题吗?我也遇到这个问题了,能否指点一下,谢谢
发表于 2022-3-5 22:36 | 显示全部楼层
1. 回调函数中不能有耗时操作;
2. while 循环可能造成了看门狗复位,尝试喂狗。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-28 10:37 , Processed in 0.078508 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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