{dl��|�d�|�l�c|����{�cl�c��oo�doo���cp��dslsl�{��n�b�nbp�
--- EDIT ---
If I put Serial Monitor to 74880 baud, it prints the following:
ets Jan 8 2013,rst cause:5, boot mode:(1,7)
ets_main.c
My code is:
#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
ESP.deepSleep(1000000, WAKE_RF_DEFAULT);
}
void setup() {
Serial.begin(115200);
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();
}
Moving code from functions to setup does nothing. And if I try to connect GPIO16 (D0) with RST, it resets constantly. Pulling-up D3 and D4 (GPIO0 and 2) and pulling-down GPIO15 doesn't work, either.