getting back to this issue which I have too. Of course there must be something wrong, but what ?
Here my simple code and the result from 5m distance to the router. On 3m it works.
// Digital Clock Galactico
// Test for ESP32C3 Supermini
// November 2023
// Bernardo Gullasch
// including Wifi, OLED, Setbuttons
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#include <WiFi.h>
#include <time.h>
#include <ESP32Time.h>
#define I2Cadd 0x3C
//*******************************************************************************
#define MY_TZ "<-04>4<-03>,M9.1.6/24,M4.1.6/24" // for time() ctime()
#define MY_NTP_SERVER "cl.pool.ntp.org"
//*******************************************************************************
// WiFi setup data
//const char* ssid = "Galactico_Salon"; // Name of the Wi-Fi box
//const char* password = "saturno002"; // MDP of the Wi-Fi box
const char* ssid = "GalacticoVTR"; // Name of the Wi-Fi box
const char* password = "19Galactico"; // MDP of the Wi-Fi box
//*******************************************************************************
/* Globals */
time_t now; // this are the seconds since Epoch (1970) - UTC
tm timeinfo; // the structure tm holds time information in a more convenient way *
//*******************************************************************************
// Create the OLED oled
//Adafruit_SH1106G oled = Adafruit_SH1106G(128, 64, &Wire, -1);
Adafruit_SSD1306 oled = Adafruit_SSD1306(128, 64, &Wire, -1);
int AdjustPin = 4; // black button
int SetPin = 2; // yellow button
ESP32Time rtc;
const char *WeekDay[] = {"Domingo ", "Lunes ", "Martes ", "Miercoles", "Jueves ", "Viernes ", "Sabado ", "Domingo "};
bool END;
int Block[7];
int setVal=0;
int dispPos=0;
int count;
// --------- SETUP ---------
void setup()
{
//Serial.begin(115200);
//Serial.println("start setup.....");
//oled.begin(I2Cadd, true);
oled.begin(SSD1306_SWITCHCAPVCC, I2Cadd);
oled.setTextSize(1);
oled.setTextColor(SH110X_WHITE);
oled.clearDisplay();
oled.fillRect(0,0,128,64,SH110X_BLACK);
oled.display();
delay(100);
pinMode(AdjustPin, INPUT); // right button
pinMode(SetPin, INPUT); // left button
//Serial.println(" ***** Start Setup *****");
WiFi.persistent(false);
WiFi.mode(WIFI_STA); // Optional
WiFi.begin(ssid, password);
oled.setCursor(0,10);
oled.println(" Time init");
oled.println(" Connecting");
while (WiFi.status() != WL_CONNECTED)
{
oled.print("."); oled.display();
count++;
if(count>100)
{
oled.clearDisplay();
oled.setCursor(0,40);
oled.println("connection failed");
oled.display();
delay(1000);
oled.clearDisplay();
break;
}
delay(200);
}
if(WiFi.status() == WL_CONNECTED)
{
oled.clearDisplay();
oled.setCursor(0,8);
oled.println("Connected to ");
oled.println();
oled.println(ssid);
oled.println();
oled.println("Local ESP32 IP: ");
oled.println();
oled.println(WiFi.localIP());
oled.display();
delay(2000);
//while (!digitalRead(SetPin)) {;}
oled.clearDisplay();
oled.setCursor(0,10);
oled.println("get Time from NTP...");
oled.display();
// We configure the NTP server
//*******************************************************************************
configTime(0, 0, MY_NTP_SERVER); // 0, 0 because we will use TZ in the next line
setenv("TZ", MY_TZ, 1); // Set environment variable with your time zone
tzset();
//*******************************************************************************
}
if (!getLocalTime(&timeinfo))
{
oled.setCursor(0,40);
oled.println("Failed to obtain time");
oled.println("adjust time manually");
oled.display();
delay(2000);
InputTime();
}
else
{
rtc.setTimeStruct(timeinfo);
oled.clearDisplay();
oled.setCursor(0,40);
oled.println("Time set succesfully");
oled.display();
}
WiFi.disconnect();
//Serial.println("ready for Setup ...");
Block[0] = rtc.getYear();
Block[1] = rtc.getMonth()+1;
Block[2] = rtc.getDay();
Block[3] = rtc.getDayofWeek();
Block[4] = rtc.getHour(true);
Block[5] = rtc.getMinute();
Block[6] = rtc.getSecond();
oled.setCursor(0,10);
oled.println("RTC actual time is ");
oled.println("---------------------");
if (Block[2]<10) {oled.print("0");}
oled.print(Block[2]);
oled.print(".");
if (Block[1]<10) {oled.print("0");}
oled.print(Block[1]);
oled.print(". ");
//oled.print("20"); oled.print(Block[0]);
oled.print(" ");
oled.print(Block[4]);
oled.print(":");
oled.print(Block[5]);
oled.print(":");
oled.println(Block[6]);
oled.println(" ");
/*
oled.println("Left -> set time");
oled.println(" ");
oled.println("Right -> continue");
*/
oled.display();
delay(1000);
oled.clearDisplay();
oled.setCursor(5,30);
oled.print("* Time Set *");
oled.display();
delay(1000);
// LET´S GO
} // --------------------- finish Setup ------------------------
void loop()
{
showTime();
}
// ------------------------------------- End Loop ------------------------------
void InputTime()
{
while (setVal<7) // input date/time values
{
if (digitalRead(AdjustPin)) // ajust actual value
{
Block[setVal]++ ;
if (Block[0] > 32) {Block[0] = 22;}
if (Block[1] > 12) {Block[1] = 1;}
if (Block[2] > 31) {Block[2] = 1;}
if (Block[3] > 7 ) {Block[3] = 1;}
if (Block[4] > 23) {Block[4] = 0;}
if (Block[5] > 59) {Block[5] = 0;}
if (Block[6] > 59) {Block[6] = 0;}
delay(100);
}
if (digitalRead(SetPin)) // set value and goto next
{
setVal++;
delay(100);
}
showInput();
delay(200);
} // ready input date/time values 0 to 5
oled.clearDisplay();
//oled.setCursor(0,10);
//oled.print("Ready for adjust time");
BlockOnOLED();
SetClock();
}
void showInput()
{
oled.clearDisplay();
oled.setCursor(0,8);
oled.setTextSize(1);
oled.println("ingresar fecha/hora");
oled.println("---------------------");
oled.setCursor(0,24);
oled.println("Ano Mes Dia Sem");
for (dispPos=0; dispPos<4; dispPos++)
{
oled.setCursor((dispPos*34),33);
if (dispPos==setVal) {oled.setTextColor(SH110X_BLACK, SH110X_WHITE);} else {oled.setTextColor(SH110X_WHITE, SH110X_BLACK);}
if (Block[dispPos] < 10) {oled.print("0"); oled.print(Block[dispPos]);} else {oled.print(Block[dispPos]);}
}
oled.setTextColor(SH110X_WHITE, SH110X_BLACK);
oled.setCursor(0,46);
oled.print("Hora Minuto Segundo");
for (dispPos=4; dispPos<7; dispPos++)
{
oled.setCursor(((dispPos-4)*36),54);
if (dispPos==setVal) {oled.setTextColor(SH110X_BLACK, SH110X_WHITE);} else {oled.setTextColor(SH110X_WHITE, SH110X_BLACK);}
oled.setTextSize(1);
if (Block[dispPos] < 10) {oled.print("0"); oled.print(Block[dispPos]);} else {oled.print(Block[dispPos]);}
oled.setTextSize(1);
//oled.display();
}
oled.display();
oled.setTextColor(SH110X_WHITE, SH110X_BLACK);
}
void SetClock()
{
rtc.setTime(Block[6],Block[5],Block[4],Block[2],(Block[1]),Block[0]+2000);
oled.clearDisplay();
oled.setCursor(30,24);
oled.print("* READY *");
oled.display();
delay(1000);
}
void showTime()
{
oled.clearDisplay();
oled.setTextSize(1);
oled.setCursor(0,8);
if(rtc.getDay() < 10) {oled.print("0");}
oled.print(rtc.getDay());
oled.print(".");
if(rtc.getMonth() < 10) {oled.print("0");}
oled.print(rtc.getMonth() +1);
oled.print(". ");
//oled.print("20");
oled.print(rtc.getYear());
oled.print(" ");
oled.print(WeekDay[rtc.getDayofWeek()]);
oled.setTextSize(2);
oled.setCursor(15,33);
if ((rtc.getHour(true)) < 10){oled.print("0");}
oled.print(rtc.getHour(true));
oled.print(":");
if ((rtc.getMinute()) < 10){oled.print("0");}
oled.print(rtc.getMinute());
oled.print(":");
if ((rtc.getSecond()) < 10){oled.print("0");}
oled.print(rtc.getSecond());
oled.print(" ");
oled.drawRoundRect(0,25,128,32,10,WHITE);
oled.drawRoundRect(1,26,126,30,10,WHITE);
oled.display();
}
void BlockOnOLED()
{
oled.clearDisplay();
oled.setCursor(0,0);
for(int i=0; i<7; i++)
{
oled.print("Block ");
oled.print(i);
oled.print(" -> ");
oled.println(Block[i]);
}
oled.display();
while (!digitalRead(SetPin)) {;}
}