关于nodemcu重启的问题-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2192|回复: 7

[已解答] 关于nodemcu重启的问题

[复制链接]
发表于 2020-8-9 00:00 | 显示全部楼层 |阅读模式
最近在调试多个传感器加屏幕,发现nodemcu动态内存使用到46%左右时就会重启,怀疑多种问题仍然调试无果。故写了一个简单程序测试(详细代码如下),在上报温湿度的代码基础上,定义了3个字符串变量(String SMS0~SMS2),每个变量1000字节左右,当加入这3个变量后,动态内存占用48%,当串口调试信息提示==== needInit ====附近后重启(见附录)。而当注释掉这3个变量,动态内存使用45%,此时程序正常连接平台。已经更换过nodemcu,单独供电测试过。请问有朋友知道原因么,谢谢。(esp8266版本是2.7.1,blinker库是最新的)
  1. String SMS0="121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghj";

  2. String SMS1="gjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjh121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjgg3gfghjggfjhgjf121343gfgfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf12134hj";

  3. String SMS2="ghjggfjhgjf121343gfghjggfjhgjf121343gjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjh121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfgfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjgg3gfghjggfjhgjf121343gfgfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf12134hj";

  4. #define BLINKER_WIFI
  5. #include <Blinker.h>
  6. char auth[] = "***";
  7. char ssid[] = "***";
  8. char pswd[] = "***";
  9. BlinkerNumber HUMI("humi");
  10. BlinkerNumber TEMP("temp");
  11. #include <DHT.h>
  12. #define DHTPIN D7
  13. #define DHTTYPE DHT11 // DHT 11
  14. DHT dht(DHTPIN, DHTTYPE);
  15. uint32_t read_time = 0;
  16. float humi_read, temp_read;
  17. void dataRead(const String & data)
  18. {
  19. BLINKER_LOG("Blinker readString: ", data);
  20. Blinker.vibrate();
  21. uint32_t BlinkerTime = millis();
  22. Blinker.print("millis", BlinkerTime);
  23. }

  24. void heartbeat()
  25. {
  26. HUMI.print(humi_read);
  27. TEMP.print(temp_read);
  28. }

  29. void setup()
  30. {
  31. Serial.begin(9600);
  32. BLINKER_DEBUG.stream(Serial);
  33. BLINKER_DEBUG.debugAll();
  34. pinMode(LED_BUILTIN, OUTPUT);
  35. digitalWrite(LED_BUILTIN, LOW);

  36. Blinker.begin(auth, ssid, pswd);
  37. Blinker.attachData(dataRead);
  38. Blinker.attachHeartbeat(heartbeat);

  39. dht.begin();
  40. }

  41. void loop()
  42. {
  43. Blinker.run();
  44. if (read_time == 0 || (millis() - read_time) >= 2000)
  45. {
  46. read_time = millis();

  47. float h = dht.readHumidity();
  48. float t = dht.readTemperature();

  49. if (isnan(h) || isnan(t)) {
  50. BLINKER_LOG("Failed to read from DHT sensor!");
  51. return;
  52. }

  53. float hic = dht.computeHeatIndex(t, h, false);

  54. humi_read = h;
  55. temp_read = t;

  56. }
  57. }
复制代码
报错信息一般从以下位置开始,提示
[size=1em] exception (9)
,但调整内存占用,也出现过 在串口显示MQTT连接成功后,提示exception (28)后重启。

  1. 23:43:43.629 -> [19021] ==== needInit ====
  2. 23:43:43.629 -> [19021] message: /share/device?deviceName=66438E2ACAZFQ66OSCZRQRPF&key=1c******a5
  3. 23:43:43.723 -> [19088] blinker server begin
  4. 23:43:43.770 -> [19119] Freeheap: 23880
  5. 23:43:58.844 -> [34334] HTTPS begin: https://iot.diandeng.tech/api/v1/user/device/share/device?deviceName=66438E2ACAZFQ66OSCZRQRPF&key=1c****a5
  6. 23:43:58.985 -> [34341] HTTPS payload: /share/device?deviceName=66438E2ACAZFQ66OSCZRQRPF&key=<span style="display: inline !important; float: none; background-color: rgb(247, 247, 247); color: rgb(68, 68, 68); font-family: Microsoft YaHei,SimHei,Verdana,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;">1c****a5</span>
  7. 23:43:59.078 -> [34435] [HTTP] ... failed, error: connection refused
  8. 23:43:59.125 ->
  9. 23:43:59.125 -> Exception (9):
  10. 23:43:59.172 -> epc1=0x40240141 epc2=0x00000000 epc3=0x00000000 excvaddr=0x000010ab depc=0x00000000
  11. 23:43:59.219 ->
  12. 23:43:59.219 -> >>>stack>>>
  13. 23:43:59.266 ->
  14. 23:43:59.266 -> ctx: bearssl
  15. 23:43:59.266 -> sp: 3fff43b0 end: 3fff4820 offset: 0190
  16. 23:43:59.313 -> 3fff4540:  3fff5b64 3fff5b48 3fff5064 4023fa70
复制代码


发表于 2020-8-9 00:32 | 显示全部楼层
确保8266package和blinker lib为最新
发表于 2020-8-9 01:30 | 显示全部楼层
运行的时候使用的内存并不是固定的
 楼主| 发表于 2020-8-9 11:21 | 显示全部楼层
本帖最后由 kkduoduo 于 2020-8-9 17:52 编辑
奈何col 发表于 2020-8-9 00:32
确保8266package和blinker lib为最新
大老板,已经测试了2.7.4,仍然不行。(擦出了所有flash内容)
 楼主| 发表于 2020-8-9 11:22 | 显示全部楼层
XlinliY.Zhang 发表于 2020-8-9 01:30
运行的时候使用的内存并不是固定的

这如何理解
发表于 2020-8-9 19:18 | 显示全部楼层

长数组自己丢Flash里
 楼主| 发表于 2020-8-10 09:20 | 显示全部楼层
XlinliY.Zhang 发表于 2020-8-9 19:18
长数组自己丢Flash里

您说的没问题,放flash里面肯定节约内存,这里只是为了重复内存故障现象才如此定义。如果存在歧义,也可以加入一些其他代码来占用内存
 楼主| 发表于 2020-8-10 12:53 | 显示全部楼层
初步怀疑是平台bug,目前移植到blynk一切正常,定了10个1000字节的字符串,内存使用51%。建议大老板能抽空分析下,谢谢。@奈何col
1111111.png
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-28 11:49 , Processed in 0.110873 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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