Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By nodemcu
#60012 It's definitely a hardware or bootloader issue, as the code you provided doesn't work. If I change to 74880 baud (changing the program), it prints the following:
Code: Select all ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld
�C�*W�ѹ..
ResetInfo.reason = 5
going to sleep now...

 ets Jan  8 2013,rst cause:5, boot mode:(3,6)

ets_main.c

I tried on 2 NodeMCU (on one of them I accidentally broke the USB connector, so I use an external USB-Serial converter). It may be bootloader issue. I'm trying to compile the Espressif SDK.
User avatar
By schufti
#60031 the "cause:5" tells me that the restart wasn't caused by the rst pin but by the internals via sleeptimer
(see viewtopic.php?f=13&t=12180)

the "boot mode:(1,7)" tells me that something on the relevant boot pins is wrong at the time of wake-up
first part is gpio15/0/2 (boot_sel), second part gpio13/14/15 (sdio_boot_sel)

with boot_sel describing:
7 SDIO HighSpeed V2 IO Uart1 Booting
6 SDIO LowSpeed V1 IO Uart1 Booting
5 SDIO HighSpeed V1 IO Uart1 Booting
4 SDIO LowSpeed V2 IO Uart1 Booting
3 FLASH BOOT
2 Jump Boot
1 UART Boot
0 Remapping

so I conclude that:
gpio0 is low at wake-up whereas it is expexted to be high....
gpio16 - rst is not working as expected (nodemcu's - various clones, different assembly - have some problem here I realized)
User avatar
By nodemcu
#60052 I don't know what happened, but it works now if i connect D0 and RST. It's a clone and, as you mentioned, they have problems, but it fixed. So hardware problem solved.
Unfortunately, it looks like there is a problem with my program. If I try the other program, it works perfectly. But with mine, it doesn't. This is my program:
Code: Select allextern "C" {
#include "user_interface.h"
}

#include <EEPROM.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

const char* ssid = "MY_SSID";
const char* password = "MY_PASSWORD";
int totime;
int nowtime;
bool connectedOK;

WiFiServer server(80);

void OTAsetup() {
  //WiFi.forceSleepWake();
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.println("Booting");
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, HIGH);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }

  // Port defaults to 8266
  // ArduinoOTA.setPort(8266);

  // Hostname defaults to esp8266-[ChipID]
  // ArduinoOTA.setHostname("myesp8266");

  // No authentication by default
  // ArduinoOTA.setPassword((const char *)"123");

  ArduinoOTA.onStart([]() {
    Serial.println("Start");
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nEnd");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("End Failed");
  });
  ArduinoOTA.begin();
  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

void loopProcess() {
  ArduinoOTA.handle();
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Wait until the client sends some data
  Serial.println("new client");
  while (!client.available()) {
    delay(1);
  }

  // Read the first line of the request
  String req = client.readStringUntil('\r');
  Serial.println(req);
  client.flush();

  // Match the request
  int val;
  int val2;
  if (req.indexOf("/gpio/0") != -1) {
    val = 1;
    val2 = 1;
  } else if (req.indexOf("/gpio/1") != -1) {
    val = 0;
    val2 = 1;
  } else if (req.indexOf("/gpio/2") != -1) {
    val = 1;
    val2 = 0;
  } else if (req.indexOf("/gpio/3") != -1) {
    val = 0;
    val2 = 0;
  }
  else {
    Serial.println("invalid request");
    client.stop();
    return;
  }

  // Set GPIO2 according to the request
  digitalWrite(2, val);
  digitalWrite(D3, val);
  digitalWrite(LED_BUILTIN, val2);

  client.flush();

  // Prepare the response
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
  s += (val) ? "low" : "high";
  s += ".<br>GPIO2 is now ";
  s += (val2) ? "low" : "high";
  s += ".</html>\n";

  // Send the response to the client
  client.print(s);
  delay(1);
  Serial.println("Client disonnected");

  // The client will actually be disconnected
  // when the function returns and 'client' object is detroyed
  system_deep_sleep_set_option(0);
  system_deep_sleep(10000000);            // deep sleep for 10 seconds
  delay(1000);
}

void setup() {
  Serial.begin(74880);
  OTAsetup();
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED on (HIGH is the voltage level)
  Serial.begin(115200);
  delay(10);

  // prepare GPIO2
  pinMode(2, OUTPUT);
  digitalWrite(2, 1);

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.println(WiFi.localIP());
  /*nowtime = micros();
  loopProcess();
  totime = micros() - nowtime;*/
  connectedOK = true;
}

void loop() {
  loopProcess();
}

BTW, the LED GPIOs seem to be negated, as if I put LOW, they light up, and vice versa.
--- EDIT ---
The problem was that the builtin LED was connected to GPIO16, and when I tie it LOW, it resets. I just changed LED_BUILTIN by D1 and (optionally) put a LED on D1. Problem solved.
User avatar
By agk
#60071 I experienced the same problem before, for the NodeMCU board:

1. Make sure GPIO16 is connected RST, preferably with a resistor (470R to 2k2 would work okay) otherwise your RESET button will not work properly.

2. Do not use LED_BUILTIN, as that is actually GPIO16 as well, so every time you turn the LED_BUILTIN on by pulling it down, you're resetting the device, which is why you're getting the "reset loop"!