首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >NodeMCU WDT重置

NodeMCU WDT重置
EN

Stack Overflow用户
提问于 2017-05-22 01:54:46
回答 1查看 1.9K关注 0票数 0

我有一块NodeMCU板,它在启动大约3秒后被重置。我没有像其他帖子所建议的那样,在我的电路板上附加任何外部电容或电阻器。我尝试了这些方法中的几种,但都没有成功。我已将我的代码与串行监视器的输出一起附加到下面。我上传的代码与Arduino集成开发环境@115200波特(80 the )与4M (3M尖峰)。

终端输出:

代码语言:javascript
运行
复制
tai
chx2d
csum 0x2d
v60000318
~ld
�� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �� �load 0x4010f000, len 1384, room 16 
�� �� �� �� �� �� �� �� �� �� �� �������������to Hardy
.....
Attempting MQTT connection...connected
Adafruit MPR121 Capacitive Touch sensor test

Soft WDT reset

ctx: cont 
sp: 3ffef550 end: 3ffef7e0 offset: 01b0

>>>stack>>>
3ffef700:  00003a97 00000001 00000002 00000001  
3ffef710:  3ffee5d6 00000150 00000004 4020120c  
3ffef720:  3ffee5d6 0000005a 00000004 402013ca  
3ffef730:  00000001 00000000 00000004 40201300  
3ffef740:  0000005a 000d0462 3ffee630 3ffee7b0  
3ffef750:  0000005d 3ffee594 00000001 40202c5c  
3ffef760:  0000005d 3ffee594 3ffee5a0 40202c87  
3ffef770:  4020153a 00000001 3ffee5a0 4020408b  
3ffef780:  3fffdad0 0000005a 3ffee594 402040db  
3ffef790:  3fffdad0 3ffee4c0 3ffee784 40202a2b  
3ffef7a0:  00000000 00000000 00000000 40204ce8  
3ffef7b0:  00000000 00000000 00000000 feefeffe  
3ffef7c0:  feefeffe 00000000 3ffee7a9 40204b18  
3ffef7d0:  feefeffe feefeffe 3ffee7c0 40100718  
<<<stack<<<
������

代码:

代码语言:javascript
运行
复制
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include "Adafruit_MPR121.h"

int led1 = D6;
int led2 = D3;

const char* inTopic = "/home/room1/switch1/in";
const char* outTopic = "/home/room1/switch1/out";

const char* ssid = "Hardy";
const char* password = "*****";
const char* mqtt_server = "192.168.1.199";

uint16_t lasttouched = 0;
uint16_t currtouched = 0;

Adafruit_MPR121 cap = Adafruit_MPR121();

WiFiClient espClient;
PubSubClient client(espClient);

void setup() {

  Serial.begin(9600);

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);

  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
  client.subscribe(inTopic);

  Serial.println("Connecting to " + (String)ssid);
  setup_wifi();

  reconnect();

  Serial.println("Adafruit MPR121 Capacitive Touch sensor test"); 

  if (!cap.begin(0x5A)) {
    Serial.println("MPR121 not found, check wiring?");
    while (1);
  }
  Serial.println("MPR121 found!");
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }

  client.loop();  //Check for updated commands on topic
  checkTouches(); //See if buttons were pressed

  //delay(100);
}

void checkTouches() {
  currtouched = cap.touched();

  if ((currtouched & _BV(0)) && !(lasttouched & _BV(0)) ) {
    publishCommand(outTopic, 0);
  }
  if ((currtouched & _BV(1)) && !(lasttouched & _BV(1)) ) {
    publishCommand(outTopic, 1);
  }

  lasttouched = currtouched;
}

void publishCommand(String topic,float topic_val){
    Serial.print("Newest topic " + topic + " value:");
    Serial.println(String(topic_val).c_str());
    client.publish(topic.c_str(), String(topic_val).c_str(), true);
}

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");

  int value = (int) payload[0];
  value -= 48;  //For byte to int conversion
  Serial.println(value);

  if (value == 0) {  //Switch 1
    //temp
    analogWrite(led1, 0);
    /*
    if((char)payload[1] == '0') {  //LED off
      analogWrite(led1, 0);
    }
    else if((char)payload[1] == '1') {  //LED on
      analogWrite(led1, 200);
    }
    else if((char)payload[1] == '2') {  //LED dimmed for night mode
      analogWrite(led1, 100);
    }
    */
  }
  if(value == 1) {  //Switch 2
    //temp
    analogWrite(led1, 255);
    /*
    if((char)payload[1] == '0') {  //LED off
      analogWrite(led1, 0);
    }
    else if((char)payload[1] == '1') {  //LED on
      analogWrite(led1, 200);
    }
    else if((char)payload[1] == '2') {  //LED dimmed for night mode
      analogWrite(led1, 100);
    }
    */
  }


}

void setup_wifi() {
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  randomSeed(micros());

  Serial.println("WiFi connected at " + WiFi.localIP());
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Create a random client ID
    String clientId = "ESP8266Client-";
    clientId += String(random(0xffff), HEX);
    // Attempt to connect
    if (client.connect(clientId.c_str())) {
      Serial.println("connected");
      // Once connected, publish an announcement...
      // ... and resubscribe
      client.subscribe(inTopic);
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}
EN

回答 1

Stack Overflow用户

发布于 2017-05-22 02:19:15

代码语言:javascript
运行
复制
delay(5000);

我不认为你可以在NodeMCU的代码中设置长时间的延迟。根据我的经验,长时间延迟呼叫所造成的情况正是您所描述的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44100043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档