Version 1.8.10
Using: ESP32
here is code: #include "heltec.h"
#include "images.h"
#include <WiFi.h>
#include "time.h"
const char* ssid = "Danielle";
const char* password = "3054917474";
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 0;
const int daylightOffset_sec = 3600;
void setup(){
Serial.begin(115200);
// Connect to Wi-Fi
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
// Init and get the time
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
printLocalTime();
//disconnect WiFi as it's no longer needed
WiFi.disconnect(false);
WiFi.mode(WIFI_OFF);
}
void loop(){
delay(1000);
printLocalTime();
}
void printLocalTime(){
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
Serial.print("Day of week: ");
Serial.println(&timeinfo, "%A");
Serial.print("Month: ");
Serial.println(&timeinfo, "%B");
Serial.print("Day of Month: ");
Serial.println(&timeinfo, "%d");
Serial.print("Year: ");
Serial.println(&timeinfo, "%Y");
Serial.print("Hour: ");
Serial.println(&timeinfo, "%H");
Serial.print("Hour (12 hour format): ");
Serial.println(&timeinfo, "%I");
Serial.print("Minute: ");
Serial.println(&timeinfo, "%M");
Serial.print("Second: ");
Serial.println(&timeinfo, "%S");
Serial.println("Time variables");
char timeHour[3];
strftime(timeHour,3, "%H", &timeinfo);
Serial.println(timeHour);
char timeWeekDay[10];
strftime(timeWeekDay,10, "%A", &timeinfo);
Serial.println(timeWeekDay);
Serial.println();
}
void WIFISetUp(void)
{
// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.disconnect(true);
delay(1000);
WiFi.mode(WIFI_STA);
WiFi.setAutoConnect(true);
WiFi.begin("Your WIFI SSID","Your WIFI Password");
delay(100);
byte count = 0;
while(WiFi.status() != WL_CONNECTED && count < 10)
{
count ++;
delay(500);
Heltec.display -> drawString(0, 0, "Connecting...");
Heltec.display -> display();
}
Heltec.display -> clear();
if(WiFi.status() == WL_CONNECTED)
{
Heltec.display -> drawString(0, 0, "Connecting...OK.");
Heltec.display -> display();
// delay(500);
}
else
{
Heltec.display -> clear();
Heltec.display -> drawString(0, 0, "Connecting...Failed");
Heltec.display -> display();
// while(1);
}
Heltec.display -> drawString(0, 10, "WIFI Setup done");
Heltec.display -> display();
delay(500);
}
void WIFIScan(void)
{
Heltec.display -> drawString(0, 20, "Scan start...");
Heltec.display -> display();
int n = WiFi.scanNetworks();
Heltec.display -> drawString(0, 30, "Scan done");
Heltec.display -> display();
delay(500);
Heltec.display -> clear();
if (n == 0)
{
Heltec.display -> clear();
Heltec.display -> drawString(0, 0, "no network found");
Heltec.display -> display();
while(1);
}
else
{
Serial.print(n);
Heltec.display -> drawString(0, 0, (String)n);
Heltec.display -> drawString(14, 0, "networks found:");
Heltec.display -> display();
delay(500);
for (int i = 0; i < n; ++i) {
// Print SSID and RSSI for each network found
Heltec.display -> drawString(0, (i+1)*9,(String)(i + 1));
Heltec.display -> drawString(6, (i+1)*9, ":");
Heltec.display -> drawString(12,(i+1)*9, (String)(WiFi.SSID(i)));
Heltec.display -> drawString(90,(i+1)*9, " (");
Heltec.display -> drawString(98,(i+1)*9, (String)(WiFi.RSSI(i)));
Heltec.display -> drawString(114,(i+1)9, ")");
// display.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"");
delay(10);
}
}
Heltec.display -> display();
delay(800);
Heltec.display -> clear();
}
void TimeScan()
{
pinMode(LED,OUTPUT);
digitalWrite(LED,HIGH);
Heltec.begin(true /DisplayEnable Enable/, false /LoRa Enable/, true /Serial Enable/);
delay(300);
Heltec.display->clear();
WIFISetUp();
WiFi.disconnect(false);//重新初始化WIFI
delay(1000);
WiFi.mode(WIFI_STA);
WiFi.setAutoConnect(true);
}
void WifiLoop()
{
WIFIScan();
delay(2000);
}
I am currently trying to figure out why the wifi setup doesn't show up on the built-in screen, I got the time to work on the serial monitor and my intention was to have the wifi on the screen and the time on the serial monitor. anyone know why my ESP32 has a blank screen? any replies is greatly appreciated. pretty new to this.