我有一个NodeMCU板,在启动大约3秒后重置。我的电路板上没有附加任何外部电容或电阻,正如其他帖子所建议的那样。我尝试了其中几种没有运气的方法。我在下面附上了我的代码以及串行监视器的输出。我使用Arduino IDE @ 115200波特(80mHz)和4M(3M SPIFFS)上传代码。
终端输出:
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<<<
������
代码:
#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);
}
}
}
答案 0 :(得分:1)
delay(5000);
我认为你不能在NodeMCU上的代码中加长延迟。根据我的经验,长时间延迟调用会创建您描述的情况。