Hi everyone, for days I've been trying to create an access point with an ESP8266 board, but I'm having upload problems with this code. When I upload 'simpler' codes to the board, everything works fine: it creates the access point, I connect via WiFi with my smartphone, and I can load the web page. However, when I upload 'more complex' codes like the one in question, it doesn't show me anything when I search for it with WiFi.
Initially, I thought it was a memory problem, so I inserted ESP.getFreeHeap to check if it was full, even though it's almost empty. I also tried flashing the board, but to no avail. Thanks to anyone who can help me.
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <EEPROM.h>
#define LED_PIN D3
#define RELAY_PIN D5
#define SENSOR_PIN A0
ESP8266WebServer server(80);
int t1 = 85;
int t2 = 20;
int v1 = 400;
void setup() {
Serial.begin(115200);
EEPROM.begin(12);
t1 = EEPROM.read(0) << 8 | EEPROM.read(1);
t2 = EEPROM.read(2) << 8 | EEPROM.read(3);
v1 = EEPROM.read(4) << 8 | EEPROM.read(5);
pinMode(LED_PIN, OUTPUT);
pinMode(RELAY_PIN, OUTPUT);
pinMode(SENSOR_PIN, INPUT);
WiFi.softAP("ESP8266 AP", "12345678");
server.on("/", handleRoot);
server.begin();
Serial.print("Memoria heap libera: ");
Serial.println(ESP.getFreeHeap());
}
void loop() {
server.handleClient();
int sensorValue = analogRead(SENSOR_PIN);
if (sensorValue >= v1) {
delay(t2);
digitalWrite(LED_PIN, HIGH);
digitalWrite(RELAY_PIN, HIGH);
delay(t1);
digitalWrite(LED_PIN, LOW);
digitalWrite(RELAY_PIN, LOW);
}
}
void handleRoot() {
String s = "<html><body>";
s += "<form method='get' action='set'>";
s += "Tempo di taglio: <input name='t1' length=12 value='" + String(t1) + "'><br>";
s += "Ritardo cutoff: <input name='t2' length=12 value='" + String(t2) + "'><br>";
s += "Media sensore: <input name='v1' length=12 value='" + String(v1) + "'><br>";
s += "<input type='submit'></form></body></html>";
server.send(200, "text/html", s);
if (server.hasArg("t1") && server.hasArg("t2") && server.hasArg("v1")) {
t1 = server.arg("t1").toInt();
t2 = server.arg("t2").toInt();
v1 = server.arg("v1").toInt();
EEPROM.write(0, t1 >> 8);
EEPROM.write(1, t1 & 0xFF);
EEPROM.write(2, t2 >> 8);
EEPROM.write(3, t2 & 0xFF);
EEPROM.write(4, v1 >> 8);
EEPROM.write(5, v1 & 0xFF);
EEPROM.commit();
}
}