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

kkduoduo 发表于 2020-8-9 00:00

关于nodemcu重启的问题

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

String SMS1="gjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjh121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjgg3gfghjggfjhgjf121343gfgfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf12134hj";

String SMS2="ghjggfjhgjf121343gfghjggfjhgjf121343gjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjh121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfgfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjgg3gfghjggfjhgjf121343gfgfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf121343gfghjggfjhgjf12134hj";

#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "***";
char ssid[] = "***";
char pswd[] = "***";
BlinkerNumber HUMI("humi");
BlinkerNumber TEMP("temp");
#include <DHT.h>
#define DHTPIN D7
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
uint32_t read_time = 0;
float humi_read, temp_read;
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
}

void heartbeat()
{
HUMI.print(humi_read);
TEMP.print(temp_read);
}

void setup()
{
Serial.begin(9600);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);

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

dht.begin();
}

void loop()
{
Blinker.run();
if (read_time == 0 || (millis() - read_time) >= 2000)
{
read_time = millis();

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

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

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

humi_read = h;
temp_read = t;

}
}报错信息一般从以下位置开始,提示 exception (9),但调整内存占用,也出现过 在串口显示MQTT连接成功后,提示exception (28)后重启。
23:43:43.629 -> ==== needInit ====
23:43:43.629 -> message: /share/device?deviceName=66438E2ACAZFQ66OSCZRQRPF&key=1c******a5
23:43:43.723 -> blinker server begin
23:43:43.770 -> Freeheap: 23880
23:43:58.844 -> HTTPS begin: https://iot.diandeng.tech/api/v1/user/device/share/device?deviceName=66438E2ACAZFQ66OSCZRQRPF&key=1c****a5
23:43:58.985 -> 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>
23:43:59.078 -> ... failed, error: connection refused
23:43:59.125 ->
23:43:59.125 -> Exception (9):
23:43:59.172 -> epc1=0x40240141 epc2=0x00000000 epc3=0x00000000 excvaddr=0x000010ab depc=0x00000000
23:43:59.219 ->
23:43:59.219 -> >>>stack>>>
23:43:59.266 ->
23:43:59.266 -> ctx: bearssl
23:43:59.266 -> sp: 3fff43b0 end: 3fff4820 offset: 0190
23:43:59.313 -> 3fff4540:3fff5b64 3fff5b48 3fff5064 4023fa70

奈何col 发表于 2020-8-9 00:32

确保8266package和blinker lib为最新

XlinliY.Zhang 发表于 2020-8-9 01:30

运行的时候使用的内存并不是固定的

kkduoduo 发表于 2020-8-9 11:21

本帖最后由 kkduoduo 于 2020-8-9 17:52 编辑

奈何col 发表于 2020-8-9 00:32
确保8266package和blinker lib为最新大老板,已经测试了2.7.4,仍然不行。(擦出了所有flash内容):(

kkduoduo 发表于 2020-8-9 11:22

XlinliY.Zhang 发表于 2020-8-9 01:30
运行的时候使用的内存并不是固定的

这如何理解

XlinliY.Zhang 发表于 2020-8-9 19:18

kkduoduo 发表于 2020-8-9 11:22
这如何理解

长数组自己丢Flash里

kkduoduo 发表于 2020-8-10 09:20

XlinliY.Zhang 发表于 2020-8-9 19:18
长数组自己丢Flash里

您说的没问题,放flash里面肯定节约内存,这里只是为了重复内存故障现象才如此定义。如果存在歧义,也可以加入一些其他代码来占用内存

kkduoduo 发表于 2020-8-10 12:53

初步怀疑是平台bug,目前移植到blynk一切正常,定了10个1000字节的字符串,内存使用51%。建议大老板能抽空分析下,谢谢。@奈何col
页: [1]
查看完整版本: 关于nodemcu重启的问题