You've already forked TEF6686_ESP32
In Poland, we say `to źes dowalił do pieca"
This commit is contained in:
@@ -9,3 +9,4 @@ constexpr int NTP_PACKET_SIZE = 48;
|
|||||||
void sendNTPpacket(IPAddress &address);
|
void sendNTPpacket(IPAddress &address);
|
||||||
void NTPupdate();
|
void NTPupdate();
|
||||||
time_t getNtpTime();
|
time_t getNtpTime();
|
||||||
|
void ntpPoll();
|
||||||
@@ -10,6 +10,7 @@ void Communication();
|
|||||||
void XDRGTKRoutine();
|
void XDRGTKRoutine();
|
||||||
void passwordcrypt();
|
void passwordcrypt();
|
||||||
void tryWiFi();
|
void tryWiFi();
|
||||||
|
void wifiPoll();
|
||||||
void total_pc_control();
|
void total_pc_control();
|
||||||
|
|
||||||
extern void BuildDisplay();
|
extern void BuildDisplay();
|
||||||
|
|||||||
@@ -571,6 +571,34 @@ static const uint8_t WiFi4[] PROGMEM = {
|
|||||||
0x00, 0x00, 0x00, 0x00
|
0x00, 0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const uint8_t WiFiX[] PROGMEM = {
|
||||||
|
0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x18, 0x00, 0x00, 0x60,
|
||||||
|
0x0C, 0x00, 0x00, 0xC0,
|
||||||
|
0x06, 0x00, 0x01, 0x80,
|
||||||
|
0x03, 0x00, 0x03, 0x00,
|
||||||
|
0x01, 0x80, 0x06, 0x00,
|
||||||
|
0x00, 0xC0, 0x0C, 0x00,
|
||||||
|
0x00, 0x60, 0x18, 0x00,
|
||||||
|
0x00, 0x30, 0x30, 0x00,
|
||||||
|
0x00, 0x18, 0x60, 0x00,
|
||||||
|
0x00, 0x0C, 0xC0, 0x00,
|
||||||
|
0x00, 0x07, 0x80, 0x00,
|
||||||
|
0x00, 0x07, 0x80, 0x00,
|
||||||
|
0x00, 0x07, 0x80, 0x00,
|
||||||
|
0x00, 0x0C, 0xC0, 0x00,
|
||||||
|
0x00, 0x18, 0x60, 0x00,
|
||||||
|
0x00, 0x30, 0x30, 0x00,
|
||||||
|
0x00, 0x60, 0x18, 0x00,
|
||||||
|
0x00, 0xC0, 0x0C, 0x00,
|
||||||
|
0x01, 0x80, 0x06, 0x00,
|
||||||
|
0x03, 0x00, 0x03, 0x00,
|
||||||
|
0x06, 0x00, 0x01, 0x80,
|
||||||
|
0x0C, 0x00, 0x00, 0xC0,
|
||||||
|
0x18, 0x00, 0x00, 0x60,
|
||||||
|
0x00, 0x00, 0x00, 0x00
|
||||||
|
};
|
||||||
|
|
||||||
static const uint16_t radiologo[] PROGMEM = {
|
static const uint16_t radiologo[] PROGMEM = {
|
||||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
|||||||
@@ -1,61 +1,86 @@
|
|||||||
#include "NTPupdate.h"
|
#include "NTPupdate.h"
|
||||||
|
|
||||||
|
// Sends an NTP request packet to the specified server address
|
||||||
void sendNTPpacket(IPAddress &address) {
|
void sendNTPpacket(IPAddress &address) {
|
||||||
byte packetBuffer[NTP_PACKET_SIZE] = {0};
|
byte packetBuffer[NTP_PACKET_SIZE] = {0}; // Initialize buffer with zeros
|
||||||
|
|
||||||
|
// Set NTP packet header fields as per NTP protocol
|
||||||
packetBuffer[0] = 0b11100011; // LI, Version, Mode
|
packetBuffer[0] = 0b11100011; // LI, Version, Mode
|
||||||
packetBuffer[2] = 6; // Polling interval
|
packetBuffer[2] = 6; // Polling interval
|
||||||
packetBuffer[3] = 0xEC; // Peer clock precision
|
packetBuffer[3] = 0xEC; // Peer clock precision
|
||||||
|
|
||||||
|
// Root Delay & Root Dispersion fields
|
||||||
packetBuffer[12] = 49;
|
packetBuffer[12] = 49;
|
||||||
packetBuffer[13] = 0x4E;
|
packetBuffer[13] = 0x4E;
|
||||||
packetBuffer[14] = 49;
|
packetBuffer[14] = 49;
|
||||||
packetBuffer[15] = 52;
|
packetBuffer[15] = 52;
|
||||||
|
|
||||||
|
// Send the NTP request to port 123 (NTP standard port)
|
||||||
Udp.beginPacket(address, 123);
|
Udp.beginPacket(address, 123);
|
||||||
Udp.write(packetBuffer, NTP_PACKET_SIZE);
|
Udp.write(packetBuffer, NTP_PACKET_SIZE);
|
||||||
Udp.endPacket();
|
Udp.endPacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t getNtpTime() {
|
static uint8_t _ntpState = 0;
|
||||||
IPAddress ntpServerIP;
|
static unsigned long _ntpSendMs = 0;
|
||||||
byte packetBuffer[NTP_PACKET_SIZE];
|
static constexpr unsigned long NTP_TIMEOUT_MS = 1500;
|
||||||
|
|
||||||
while (Udp.parsePacket() > 0);
|
|
||||||
|
|
||||||
if (!WiFi.hostByName(ntpServerName, ntpServerIP)) return 0;
|
|
||||||
|
|
||||||
sendNTPpacket(ntpServerIP);
|
|
||||||
|
|
||||||
uint32_t startWait = millis();
|
|
||||||
while (millis() - startWait < 1500) {
|
|
||||||
if (Udp.parsePacket() >= NTP_PACKET_SIZE) {
|
|
||||||
Udp.read(packetBuffer, NTP_PACKET_SIZE);
|
|
||||||
|
|
||||||
unsigned long secsSince1900 = ((unsigned long)packetBuffer[40] << 24) | ((unsigned long)packetBuffer[41] << 16) | ((unsigned long)packetBuffer[42] << 8) | (unsigned long)packetBuffer[43];
|
|
||||||
|
|
||||||
return secsSince1900 - 2208988800UL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Starts an NTP request (non-blocking). Call ntpPoll() in loop to process the reply.
|
||||||
void NTPupdate() {
|
void NTPupdate() {
|
||||||
if (!wifi) {
|
if (!wifi || WiFi.status() != WL_CONNECTED) {
|
||||||
NTPupdated = false;
|
NTPupdated = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t currentTime = getNtpTime();
|
IPAddress ntpServerIP;
|
||||||
|
|
||||||
if (currentTime) {
|
// Clear any previously received UDP packets
|
||||||
|
while (Udp.parsePacket() > 0);
|
||||||
|
|
||||||
|
// Resolve the NTP server's hostname to its IP address
|
||||||
|
if (!WiFi.hostByName(ntpServerName, ntpServerIP)) {
|
||||||
|
NTPupdated = false;
|
||||||
|
radio.rds.ctupdate = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send an NTP request and enter waiting state
|
||||||
|
sendNTPpacket(ntpServerIP);
|
||||||
|
_ntpState = 1;
|
||||||
|
_ntpSendMs = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ntpPoll() {
|
||||||
|
if (_ntpState != 1) return;
|
||||||
|
|
||||||
|
byte packetBuffer[NTP_PACKET_SIZE];
|
||||||
|
|
||||||
|
if (Udp.parsePacket() >= NTP_PACKET_SIZE) {
|
||||||
|
Udp.read(packetBuffer, NTP_PACKET_SIZE);
|
||||||
|
|
||||||
|
// Extract "seconds since 1900" from the packet (bytes 40-43)
|
||||||
|
unsigned long secsSince1900 =
|
||||||
|
((unsigned long)packetBuffer[40] << 24) |
|
||||||
|
((unsigned long)packetBuffer[41] << 16) |
|
||||||
|
((unsigned long)packetBuffer[42] << 8) |
|
||||||
|
(unsigned long)packetBuffer[43];
|
||||||
|
|
||||||
|
// Convert to UNIX epoch time (seconds since 1970)
|
||||||
|
time_t currentTime = secsSince1900 - 2208988800UL;
|
||||||
|
|
||||||
|
rtc.setTime(currentTime);
|
||||||
set_time(currentTime, Timezone);
|
set_time(currentTime, Timezone);
|
||||||
rtcset = true;
|
rtcset = true;
|
||||||
NTPupdated = true;
|
NTPupdated = true;
|
||||||
radio.rds.ctupdate = false;
|
radio.rds.ctupdate = false;
|
||||||
} else {
|
_ntpState = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timeout
|
||||||
|
if (millis() - _ntpSendMs >= NTP_TIMEOUT_MS) {
|
||||||
NTPupdated = false;
|
NTPupdated = false;
|
||||||
radio.rds.ctupdate = true;
|
radio.rds.ctupdate = true;
|
||||||
|
_ntpState = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,7 +227,7 @@ boolean WiFiConnect::autoConnect(char const *ssidName, char const *ssidPassword,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean WiFiConnect::startConfigurationPortal() {
|
boolean WiFiConnect::startConfigurationPortal(int8_t cancelPin) {
|
||||||
delay(50);
|
delay(50);
|
||||||
|
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
@@ -269,6 +269,11 @@ boolean WiFiConnect::startConfigurationPortal() {
|
|||||||
|
|
||||||
server->begin();
|
server->begin();
|
||||||
|
|
||||||
|
if (cancelPin >= 0) {
|
||||||
|
while (digitalRead(cancelPin) == LOW) delay(10);
|
||||||
|
delay(200);
|
||||||
|
}
|
||||||
|
|
||||||
_readyToConnect = false;
|
_readyToConnect = false;
|
||||||
while (true) {
|
while (true) {
|
||||||
dnsServer->processNextRequest();
|
dnsServer->processNextRequest();
|
||||||
@@ -282,6 +287,10 @@ boolean WiFiConnect::startConfigurationPortal() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (cancelPin >= 0 && digitalRead(cancelPin) == LOW) {
|
||||||
|
delay(50); // debounce
|
||||||
|
if (digitalRead(cancelPin) == LOW) break;
|
||||||
|
}
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
|
|
||||||
boolean autoConnect();
|
boolean autoConnect();
|
||||||
void addParameter(WiFiConnectParam *p);
|
void addParameter(WiFiConnectParam *p);
|
||||||
boolean startConfigurationPortal();
|
boolean startConfigurationPortal(int8_t cancelPin);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr int RETRY_ATTEMPTS = 3;
|
static constexpr int RETRY_ATTEMPTS = 3;
|
||||||
|
|||||||
122
src/comms.cpp
122
src/comms.cpp
@@ -1,6 +1,7 @@
|
|||||||
#include "comms.h"
|
#include "comms.h"
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
|
#include <ESPmDNS.h>
|
||||||
|
|
||||||
extern mem presets[];
|
extern mem presets[];
|
||||||
|
|
||||||
@@ -888,38 +889,99 @@ void passwordcrypt() {
|
|||||||
cryptedpassword = String(sha1(salt));
|
cryptedpassword = String(sha1(salt));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tryWiFi() {
|
static uint8_t _wifiConnState = 0; // 0=idle, 1=connecting
|
||||||
if (!setupmode && wifi) {
|
static unsigned long _wifiConnMs = 0;
|
||||||
tft.drawRoundRect(1, 20, 319, 180, 5, ActiveColor);
|
static uint8_t _wifiConnRetry = 0;
|
||||||
tft.fillRoundRect(3, 22, 315, 176, 5, BackgroundColor);
|
static bool _wifiServicesUp = false;
|
||||||
Infoboxprint(textUI(52));
|
static bool _wifiHandlersSet = false;
|
||||||
|
static constexpr uint8_t WIFI_MAX_RETRIES = 3;
|
||||||
|
static constexpr unsigned long WIFI_TIMEOUT_MS = 10000; // 10s per attempt
|
||||||
|
static constexpr unsigned long WIFI_RECONNECT_MS = 30000; // 30s between reconnect cycles
|
||||||
|
|
||||||
|
static void wifiStartServices() {
|
||||||
|
Server.begin();
|
||||||
|
Udp.begin(9031);
|
||||||
|
if (!_wifiHandlersSet) {
|
||||||
|
webserver.on("/", handleRoot);
|
||||||
|
webserver.on("/downloadCSV", HTTP_GET, handleDownloadCSV);
|
||||||
|
webserver.on("/logo.png", handleLogo);
|
||||||
|
_wifiHandlersSet = true;
|
||||||
}
|
}
|
||||||
if (wifi) {
|
webserver.begin();
|
||||||
if (wc.autoConnect()) {
|
MDNS.begin("tef");
|
||||||
Server.begin();
|
NTPupdate();
|
||||||
Udp.begin(9031);
|
remoteip = IPAddress(WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], subnetclient);
|
||||||
webserver.on("/", handleRoot);
|
_wifiServicesUp = true;
|
||||||
webserver.on("/downloadCSV", HTTP_GET, handleDownloadCSV);
|
if (menu && menupage == CONNECTIVITY) BuildMenu();
|
||||||
webserver.on("/logo.png", handleLogo);
|
}
|
||||||
webserver.begin();
|
|
||||||
NTPupdate();
|
static void wifiStopServices() {
|
||||||
remoteip = IPAddress(WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], subnetclient);
|
_wifiServicesUp = false;
|
||||||
if (!setupmode) tftPrint(ACENTER, textUI(54), 155, 128, InsignificantColor, InsignificantColorSmooth, 28);
|
MDNS.end();
|
||||||
} else {
|
Server.end();
|
||||||
if (!setupmode) tftPrint(ACENTER, textUI(53), 155, 128, SignificantColor, SignificantColorSmooth, 28);
|
webserver.stop();
|
||||||
Server.end();
|
Udp.stop();
|
||||||
webserver.stop();
|
}
|
||||||
Udp.stop();
|
|
||||||
WiFi.mode(WIFI_OFF);
|
void tryWiFi() {
|
||||||
wifi = false;
|
if (!wifi) {
|
||||||
XDRGTKTCP = false;
|
_wifiConnState = 0;
|
||||||
RDSSPYTCP = false;
|
if (_wifiServicesUp) wifiStopServices();
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Server.end();
|
|
||||||
webserver.stop();
|
|
||||||
Udp.stop();
|
|
||||||
WiFi.mode(WIFI_OFF);
|
WiFi.mode(WIFI_OFF);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
|
_wifiConnState = 0;
|
||||||
|
if (!_wifiServicesUp) wifiStartServices();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
WiFi.begin();
|
||||||
|
_wifiConnState = 1;
|
||||||
|
_wifiConnMs = millis();
|
||||||
|
_wifiConnRetry = 0;
|
||||||
|
_wifiServicesUp = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void wifiPoll() {
|
||||||
|
if (!wifi) return;
|
||||||
|
|
||||||
|
if (_wifiConnState == 1) {
|
||||||
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
|
_wifiConnState = 0;
|
||||||
|
wifiStartServices();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (millis() - _wifiConnMs >= WIFI_TIMEOUT_MS) {
|
||||||
|
_wifiConnRetry++;
|
||||||
|
if (_wifiConnRetry < WIFI_MAX_RETRIES) {
|
||||||
|
WiFi.begin();
|
||||||
|
_wifiConnMs = millis();
|
||||||
|
} else {
|
||||||
|
_wifiConnState = 0;
|
||||||
|
_wifiConnMs = millis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
|
if (!_wifiServicesUp) wifiStartServices();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_wifiServicesUp) wifiStopServices();
|
||||||
|
|
||||||
|
if (millis() - _wifiConnMs >= WIFI_RECONNECT_MS) {
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
WiFi.begin();
|
||||||
|
_wifiConnState = 1;
|
||||||
|
_wifiConnMs = millis();
|
||||||
|
_wifiConnRetry = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
52
src/core.cpp
52
src/core.cpp
@@ -503,34 +503,34 @@ void toggleiMSEQ() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TuneFreq(int temp) {
|
bool TuneFreq(int temp) {
|
||||||
int newfreq = temp;
|
int newfreq = temp;
|
||||||
|
|
||||||
if (band == BAND_FM) {
|
if (band == BAND_FM) {
|
||||||
while (newfreq < (LowEdgeSet * 10)) newfreq *= 10;
|
while (newfreq < (LowEdgeSet * 10)) newfreq *= 10;
|
||||||
if (newfreq > (HighEdgeSet * 10)) {
|
if (newfreq > (HighEdgeSet * 10)) {
|
||||||
EdgeBeeper();
|
EdgeBeeper();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (newfreq == frequency) return;
|
if (newfreq == frequency) return true;
|
||||||
frequency = newfreq;
|
frequency = newfreq;
|
||||||
radio.SetFreq(frequency);
|
radio.SetFreq(frequency);
|
||||||
} else if (band == BAND_OIRT) {
|
} else if (band == BAND_OIRT) {
|
||||||
while (newfreq < (LowEdgeOIRTSet * 10)) newfreq *= 10;
|
while (temp < LowEdgeOIRTSet) temp = temp * 10;
|
||||||
if (newfreq > HighEdgeOIRTSet) {
|
if (newfreq > HighEdgeOIRTSet) {
|
||||||
EdgeBeeper();
|
EdgeBeeper();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (newfreq == frequency_OIRT) return;
|
if (newfreq == frequency_OIRT) return true;
|
||||||
frequency_OIRT = newfreq;
|
frequency_OIRT = newfreq;
|
||||||
radio.SetFreq(frequency_OIRT);
|
radio.SetFreq(frequency_OIRT);
|
||||||
} else if (band == BAND_LW) {
|
} else if (band == BAND_LW) {
|
||||||
while (newfreq < LWLowEdgeSet) newfreq *= 10;
|
while (newfreq < LWLowEdgeSet) newfreq *= 10;
|
||||||
if (newfreq > LWHighEdgeSet) {
|
if (newfreq > LWHighEdgeSet) {
|
||||||
EdgeBeeper();
|
EdgeBeeper();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (newfreq == frequency_LW) return;
|
if (newfreq == frequency_LW) return true;
|
||||||
frequency_AM = newfreq;
|
frequency_AM = newfreq;
|
||||||
frequency_LW = newfreq;
|
frequency_LW = newfreq;
|
||||||
radio.SetFreqAM(frequency_AM);
|
radio.SetFreqAM(frequency_AM);
|
||||||
@@ -538,9 +538,9 @@ void TuneFreq(int temp) {
|
|||||||
while (newfreq < MWLowEdgeSet) newfreq *= 10;
|
while (newfreq < MWLowEdgeSet) newfreq *= 10;
|
||||||
if (newfreq > MWHighEdgeSet) {
|
if (newfreq > MWHighEdgeSet) {
|
||||||
EdgeBeeper();
|
EdgeBeeper();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (newfreq == frequency_MW) return;
|
if (newfreq == frequency_MW) return true;
|
||||||
frequency_AM = newfreq;
|
frequency_AM = newfreq;
|
||||||
frequency_MW = newfreq;
|
frequency_MW = newfreq;
|
||||||
radio.SetFreqAM(frequency_AM);
|
radio.SetFreqAM(frequency_AM);
|
||||||
@@ -548,9 +548,9 @@ void TuneFreq(int temp) {
|
|||||||
while (newfreq < SWLowEdgeSet) newfreq *= 10;
|
while (newfreq < SWLowEdgeSet) newfreq *= 10;
|
||||||
if (newfreq > SWHighEdgeSet) {
|
if (newfreq > SWHighEdgeSet) {
|
||||||
EdgeBeeper();
|
EdgeBeeper();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (newfreq == frequency_SW) return;
|
if (newfreq == frequency_SW) return true;
|
||||||
frequency_AM = newfreq;
|
frequency_AM = newfreq;
|
||||||
frequency_SW = newfreq;
|
frequency_SW = newfreq;
|
||||||
radio.SetFreqAM(frequency_AM);
|
radio.SetFreqAM(frequency_AM);
|
||||||
@@ -562,6 +562,7 @@ void TuneFreq(int temp) {
|
|||||||
radio.clearRDS();
|
radio.clearRDS();
|
||||||
if (RDSSPYUSB) Serial.print("G:\r\nRESET-------\r\n\r\n");
|
if (RDSSPYUSB) Serial.print("G:\r\nRESET-------\r\n\r\n");
|
||||||
if (RDSSPYTCP) RemoteClient.print("G:\r\nRESET-------\r\n\r\n");
|
if (RDSSPYTCP) RemoteClient.print("G:\r\nRESET-------\r\n\r\n");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowNum(int val) {
|
void ShowNum(int val) {
|
||||||
@@ -768,15 +769,26 @@ void NumpadProcess(int num) {
|
|||||||
BuildMenu();
|
BuildMenu();
|
||||||
} else if (num == 13) {
|
} else if (num == 13) {
|
||||||
if (freq_in != 0) {
|
if (freq_in != 0) {
|
||||||
TuneFreq(freq_in);
|
if (TuneFreq(freq_in)) {
|
||||||
if (XDRGTKUSB || XDRGTKTCP) {
|
if (XDRGTKUSB || XDRGTKTCP) {
|
||||||
if (band == BAND_FM) DataPrint("M0\nT" + String(frequency * 10) + "\n"); else if (band == BAND_OIRT) DataPrint("M0\nT" + String(frequency_OIRT * 10) + "\n"); else DataPrint("M1\nT" + String(frequency_AM) + "\n");
|
if (band == BAND_FM) DataPrint("M0\nT" + String(frequency * 10) + "\n"); else if (band == BAND_OIRT) DataPrint("M0\nT" + String(frequency_OIRT * 10) + "\n"); else DataPrint("M1\nT" + String(frequency_AM) + "\n");
|
||||||
}
|
}
|
||||||
if (!memorystore) {
|
if (!memorystore) {
|
||||||
if (!memtune) radio.clearRDS();
|
if (!memtune) radio.clearRDS();
|
||||||
memtune = false;
|
memtune = false;
|
||||||
|
ShowFreq(0);
|
||||||
|
store = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ShowNum(freq_in);
|
||||||
|
FrequencySprite.setTextDatum(TR_DATUM);
|
||||||
|
FrequencySprite.fillSprite(BackgroundColor);
|
||||||
|
FrequencySprite.setTextColor(SignificantColor, SignificantColorSmooth, false);
|
||||||
|
FrequencySprite.drawString(String(freq_in) + " ", 218, -6, freqfont);
|
||||||
|
FrequencySprite.pushSprite(46, 46);
|
||||||
|
delay(1000);
|
||||||
ShowFreq(0);
|
ShowFreq(0);
|
||||||
store = true;
|
|
||||||
}
|
}
|
||||||
} else ShowFreq(0);
|
} else ShowFreq(0);
|
||||||
freq_in = 0;
|
freq_in = 0;
|
||||||
|
|||||||
11
src/gui.cpp
11
src/gui.cpp
@@ -824,7 +824,7 @@ void ShowOneLine(byte position, byte item, bool selected) {
|
|||||||
case CONNECTIVITY:
|
case CONNECTIVITY:
|
||||||
FullLineSprite.setTextDatum(TL_DATUM);
|
FullLineSprite.setTextDatum(TL_DATUM);
|
||||||
FullLineSprite.setTextColor(ActiveColor, ActiveColorSmooth, false);
|
FullLineSprite.setTextColor(ActiveColor, ActiveColorSmooth, false);
|
||||||
FullLineSprite.drawString(removeNewline(textUI(48) + (wifi ? " IP: " + String(WiFi.localIP().toString()) : "")), 6, 2);
|
FullLineSprite.drawString(removeNewline(textUI(48) + (wifi && WiFi.status() == WL_CONNECTED ? " IP: " + String(WiFi.localIP().toString()) : "")), 6, 2);
|
||||||
|
|
||||||
FullLineSprite.setTextDatum(TR_DATUM);
|
FullLineSprite.setTextDatum(TR_DATUM);
|
||||||
FullLineSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
|
FullLineSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
|
||||||
@@ -1048,7 +1048,7 @@ void ShowOneLine(byte position, byte item, bool selected) {
|
|||||||
|
|
||||||
FullLineSprite.setTextDatum(TR_DATUM);
|
FullLineSprite.setTextDatum(TR_DATUM);
|
||||||
FullLineSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
|
FullLineSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
|
||||||
FullLineSprite.drawString((wifi ? String(WiFi.localIP()[0]) + "." + String(WiFi.localIP()[1]) + "." + String(WiFi.localIP()[2]) + "." + String(subnetclient, DEC) : "-"), 298, 2);
|
FullLineSprite.drawString((wifi && WiFi.status() == WL_CONNECTED ? String(WiFi.localIP()[0]) + "." + String(WiFi.localIP()[1]) + "." + String(WiFi.localIP()[2]) + "." + String(subnetclient, DEC) : "-"), 298, 2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DXMODE:
|
case DXMODE:
|
||||||
@@ -1901,7 +1901,7 @@ void ShowOneButton(byte position, byte item, bool selected) {
|
|||||||
case CONNECTIVITY:
|
case CONNECTIVITY:
|
||||||
PSSprite.setTextDatum(TC_DATUM);
|
PSSprite.setTextDatum(TC_DATUM);
|
||||||
PSSprite.setTextColor(ActiveColor, ActiveColorSmooth, false);
|
PSSprite.setTextColor(ActiveColor, ActiveColorSmooth, false);
|
||||||
PSSprite.drawString(shortLine(removeNewline(wifi ? " IP: " + String(WiFi.localIP().toString()) : textUI(48))), 75, 1);
|
PSSprite.drawString(shortLine(removeNewline(wifi && WiFi.status() == WL_CONNECTED ? " IP: " + String(WiFi.localIP().toString()) : textUI(48))), 75, 1);
|
||||||
|
|
||||||
PSSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
|
PSSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
|
||||||
PSSprite.drawString((wifi ? textUI(28) : textUI(27)), 75, 15);
|
PSSprite.drawString((wifi ? textUI(28) : textUI(27)), 75, 15);
|
||||||
@@ -2132,7 +2132,7 @@ void ShowOneButton(byte position, byte item, bool selected) {
|
|||||||
PSSprite.drawString(shortLine(removeNewline(textUI(55))), 75, 1);
|
PSSprite.drawString(shortLine(removeNewline(textUI(55))), 75, 1);
|
||||||
|
|
||||||
PSSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
|
PSSprite.setTextColor(PrimaryColor, PrimaryColorSmooth, false);
|
||||||
PSSprite.drawString((wifi ? String(WiFi.localIP()[0]) + "." + String(WiFi.localIP()[1]) + "." + String(WiFi.localIP()[2]) + "." + String(subnetclient, DEC) : "-"), 75, 15);
|
PSSprite.drawString((wifi && WiFi.status() == WL_CONNECTED ? String(WiFi.localIP()[0]) + "." + String(WiFi.localIP()[1]) + "." + String(WiFi.localIP()[2]) + "." + String(subnetclient, DEC) : "-"), 75, 15);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DXMODE:
|
case DXMODE:
|
||||||
@@ -5227,7 +5227,8 @@ void DoMenu() {
|
|||||||
wc.addParameter(&XDRGTK_key_input);
|
wc.addParameter(&XDRGTK_key_input);
|
||||||
setWiFiConnectParam = true;
|
setWiFiConnectParam = true;
|
||||||
}
|
}
|
||||||
wc.startConfigurationPortal();
|
tftPrint(ACENTER, textUI(29), 155, 202, ActiveColor, ActiveColorSmooth, 16);
|
||||||
|
wc.startConfigurationPortal(26);
|
||||||
XDRGTK_key = XDRGTK_key_input.getValue();
|
XDRGTK_key = XDRGTK_key_input.getValue();
|
||||||
EEPROM.writeString(EE_STRING_XDRGTK_KEY, XDRGTK_key);
|
EEPROM.writeString(EE_STRING_XDRGTK_KEY, XDRGTK_key);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
|
|||||||
11
src/main.cpp
11
src/main.cpp
@@ -413,7 +413,7 @@ void setup() {
|
|||||||
if (wifi) {
|
if (wifi) {
|
||||||
console.print("Trying WiFi");
|
console.print("Trying WiFi");
|
||||||
tryWiFi();
|
tryWiFi();
|
||||||
delay(1750);
|
delay(1500);
|
||||||
} else {
|
} else {
|
||||||
Server.end();
|
Server.end();
|
||||||
Udp.stop();
|
Udp.stop();
|
||||||
@@ -454,6 +454,7 @@ void setup() {
|
|||||||
void handleWiFi() {
|
void handleWiFi() {
|
||||||
if (wifi && !menu) {
|
if (wifi && !menu) {
|
||||||
webserver.handleClient();
|
webserver.handleClient();
|
||||||
|
ntpPoll();
|
||||||
|
|
||||||
if (millis() >= udplogtimer + UDP_LOG_INTERVAL_MS) {
|
if (millis() >= udplogtimer + UDP_LOG_INTERVAL_MS) {
|
||||||
sendUDPlog();
|
sendUDPlog();
|
||||||
@@ -830,8 +831,10 @@ void ShowRSSI() {
|
|||||||
if (wifi) rssi = WiFi.RSSI(); else rssi = 0;
|
if (wifi) rssi = WiFi.RSSI(); else rssi = 0;
|
||||||
if (rssiold != rssi) {
|
if (rssiold != rssi) {
|
||||||
if (!wifi && batterydetect) tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi4, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, BackgroundColor);
|
if (!wifi && batterydetect) tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi4, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, BackgroundColor);
|
||||||
else if (rssi == 0) tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi4, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, GreyoutColor);
|
else if (rssi == 0) {
|
||||||
else if (rssi > -50 && rssi < 0) tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi4, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, WifiColorHigh);
|
tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi4, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, GreyoutColor);
|
||||||
|
tft.drawBitmap(282, 3, WiFiX, 30, 25, BarSignificantColor);
|
||||||
|
} else if (rssi > -50 && rssi < 0) tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi4, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, WifiColorHigh);
|
||||||
else if (rssi > -60) {
|
else if (rssi > -60) {
|
||||||
tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi4, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, GreyoutColor);
|
tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi4, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, GreyoutColor);
|
||||||
tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi3, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, WifiColorHigh);
|
tft.drawBitmap(WIFI_ICON_X, WIFI_ICON_Y, WiFi3, WIFI_ICON_WIDTH, WIFI_ICON_HEIGHT, WifiColorHigh);
|
||||||
@@ -1085,6 +1088,8 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wifiPoll(); // He really lost it
|
||||||
|
|
||||||
handleWiFi();
|
handleWiFi();
|
||||||
handleTouch();
|
handleTouch();
|
||||||
Communication();
|
Communication();
|
||||||
|
|||||||
Reference in New Issue
Block a user