2017-05-21 32 views
0

我有一個NodeMCU板在啓動約3秒後復位。正如其他職位所建議的,我沒有任何外部電容或電阻連接到我的電路板。我嘗試了幾種這些方法,但沒有運氣。我已將以下代碼與串行監視器的輸出一起附加。我使用帶有4M(3M SPIFFS)的Arduino IDE @ 115200波特(80mHz)上傳代碼。NodeMCU WDT復位

端子輸出:

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

我懷疑'while(1);'觸發它。 –

回答

0
delay(5000); 

我不認爲你可以把長期拖延代碼的NodeMCU。根據我的經驗,長時間的延遲電話會造成您描述的情況。

+0

嘗試將延遲更改爲500毫秒,但仍然沒有運氣。一個有趣的事情是,我只是使用幾乎完全相同的代碼來控制今天的繼電器,並且我已經成功... – Owen

+0

'delay'不應該觸發看門狗復位。 –

+0

那麼會怎麼樣? – Owen