Page 1 of 1

Cannot connect WiFi in AP mode when using a hardware timer

Posted: Thu Feb 10, 2022 10:16 am
by Modulex
When the client(smartphone) tries to connect after starting the hardware timer on the server (ESP32), it does not connect to the server.
The timer cycle cannot be changed.
How can I solve this isue?

Thank you very much in advance,

#include <WiFi.h>
#include <WiFiAP.h>
#include "esp_system.h"

WiFiServer server(80);

const char *ssid = "AP";
const char *password = "";
const int localPort = 10000;
const IPAddress ip(192,168,13,2);
const IPAddress subnet(255,255,255,0);
hw_timer_t * timer = NULL;
int Counter = 0;

void IRAM_ATTR onTimer();

void setup() {
Serial.begin(115200);
pinMode(2, OUTPUT);
WiFi.softAP(ssid, password);
WiFi.softAPConfig(ip, ip, subnet);
IPAddress myIP = WiFi.softAPIP();
server.begin();

timer = timerBegin(2, 250, true);
timerAttachInterrupt(timer, &onTimer, true);
timerAlarmWrite(timer, 30, true);
timerAlarmEnable(timer);
}
void IRAM_ATTR onTimer(){
//timer cycle: 940us(was mesured by osilloscope)
static boolean tim= false;

digitalWrite(2,tim);
tim = !tim;
Counter++;
}

void loop() {
Serial.println(Counter);
delay(100);
}