I have sketch (about 500 lines) that works fine
when I let my router assign its IP but when I try to run it in softAP mode relay 3 chatters. In both modes an ip is set and in ap i can also log into it with my phone and everything seems to work except relay 3 on IO pin 25 continuously picks and drops. I eliminated all of the code and created 2 sketches below where one connection chatters and the other is normal. I'm not at all sure what connection there could be between the wifi set up and relay 3.
The firt sketch uses my router to asign the ip and the second it asigns it itself and chatters. Guess I'd like to know can anyone else duplicate this with the same board.
The chatter sketch
#include <WiFi.h>
#include <WiFiAP.h>
const char* ssid = "Camp";
const char* password = ""; //123456789
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_AP);
//WiFi.softAPConfig(local_IP, gateway, subnet);
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
}
void loop(){
delay(2000);
}
The resulting console out put:
14:30:39.277 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
14:30:39.277 -> configsip: 0, SPIWP:0xee
14:30:39.277 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
14:30:39.277 -> mode:DIO, clock div:1
14:30:39.277 -> load:0x3fff0030,len:4916
14:30:39.277 -> load:0x40078000,len:16492
14:30:39.277 -> load:0x40080400,len:4
14:30:39.277 -> load:0x40080404,len:3524
14:30:39.277 -> entry 0x400805b8
14:30:39.626 -> AP IP address: 192.168.4.1
Now for the other sketch and no relay chatter
#include <WiFi.h>
#include <WiFiAP.h>
const char* ssid = "MY SSID";
const char* password = "MY Password";
void setup() {
Serial.begin(115200);
Serial.print("Connecting to WiFi");
WiFi.begin(ssid, password);
int attempts = 0;
while (WiFi.status() != WL_CONNECTED && attempts < 20) {
delay(500);
Serial.print(".");
attempts++;
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println("\nWiFi Connected!");
Serial.println("IP Address: " + WiFi.localIP().toString());
} else {
Serial.println("\nFailed to connect to WiFi. Restarting...");
delay(5000);
ESP.restart();
}
}
void loop(){
delay(2000);
}
the console output:
12:16:08.715 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
12:16:08.715 -> configsip: 0, SPIWP:0xee
12:16:08.715 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
12:16:08.715 -> mode:DIO, clock div:1
12:16:08.715 -> load:0x3fff0030,len:4916
12:16:08.715 -> load:0x40078000,len:16492
12:16:08.715 -> load:0x40080400,len:4
12:16:08.715 -> load:0x40080404,len:3524
12:16:08.715 -> entry 0x400805b8
12:16:08.995 -> Connecting to WiFi......
12:16:12.113 -> WiFi Connected!
12:16:12.113 -> IP Address: 192.168.0.170
So in both cases an IP was assigned but for the AP mode the relay chatters.
This is the board I'm using and I also got a new board out and it does the same thing. AC/DC powered ESP32 Relay Board x4 | devices.esphome.io