mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 22:02:17 +01:00
Move the roam check into worthRoaming() and the memStatus routing into heapEmitTarget() in Utils so the native tests reach them. worthRoaming() roams for a gain of at least ROAM_MIN_GAIN_DB, as the comment and the 6 dB commit said. The old check needed one dB more. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
2.1 KiB
C++
69 lines
2.1 KiB
C++
#include <Arduino.h>
|
|
#include <WiFi.h>
|
|
#include "Utils.h"
|
|
|
|
#ifndef ESPNetwork_h
|
|
#define ESPNetwork_h
|
|
|
|
//enum class conn_types_t : byte;
|
|
|
|
#define CONNECT_TIMEOUT 20000
|
|
#define SSID_SCAN_INTERVAL 600000
|
|
// A weak signal moves a dBm or two all the time, so only broadcast real
|
|
// changes and not more often than this.
|
|
#define RSSI_EMIT_MIN_DBM 3
|
|
#define RSSI_EMIT_MIN_MS 10000
|
|
// How often memStatus is broadcast. It is also the one event that is always
|
|
// sent, so it must stay well under Home Assistant's 60s receive timeout.
|
|
#define HEAP_EMIT_MS 30000
|
|
// A roaming scan only moves to another AP at least this much stronger.
|
|
#define ROAM_MIN_GAIN_DB 6
|
|
class ESPNetwork {
|
|
protected:
|
|
unsigned long lastEmit = 0;
|
|
unsigned long lastMDNS = 0;
|
|
RssiBroadcast rssiBroadcast;
|
|
int linkSpeed = 0;
|
|
bool _connecting = false;
|
|
public:
|
|
unsigned long lastWifiScan = 0;
|
|
bool ethStarted = false;
|
|
bool wifiFallback = false;
|
|
bool softAPOpened = false;
|
|
bool openingSoftAP = false;
|
|
bool needsBroadcast = true;
|
|
conn_types_t connType = conn_types_t::unset;
|
|
conn_types_t connTarget = conn_types_t::unset;
|
|
bool connected();
|
|
bool connecting();
|
|
void clearConnecting();
|
|
conn_types_t preferredConnType();
|
|
String ssid;
|
|
String mac;
|
|
int channel;
|
|
int strength;
|
|
int disconnected = 0;
|
|
int connectAttempts = 0;
|
|
uint32_t disconnectTime = 0;
|
|
uint32_t connectStart = 0;
|
|
uint32_t connectTime = 0;
|
|
bool openSoftAP();
|
|
bool connect(conn_types_t ctype);
|
|
bool connectWiFi(const uint8_t *bssid = nullptr, const int32_t channel = -1);
|
|
bool connectWired();
|
|
void setConnected(conn_types_t connType);
|
|
bool getStrongestAP(const char *ssid, uint8_t *bssid, int32_t *channel);
|
|
bool changeAP(const uint8_t *bssid, const int32_t channel);
|
|
//int getStrengthByMac(const char *mac);
|
|
//int getStrengthBySSID(const char *ssid);
|
|
void updateHostname();
|
|
bool setup();
|
|
void loop();
|
|
void end();
|
|
void emitSockets();
|
|
void emitSockets(uint8_t num);
|
|
void emitHeap(uint8_t num = 255);
|
|
uint32_t getChipId();
|
|
static void networkEvent(WiFiEvent_t event);
|
|
};
|
|
#endif
|