mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
add Ethernet
This commit is contained in:
@@ -21,8 +21,13 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <Network.h>
|
||||
|
||||
NativeConsole Serial;
|
||||
|
||||
ETHClass ETH;
|
||||
WiFiClass WiFi;
|
||||
|
||||
/* millis() on C++ native could be
|
||||
for non-Arduino
|
||||
millis():
|
||||
|
||||
@@ -53,10 +53,10 @@ int digitalRead(uint8_t pin);
|
||||
|
||||
#define PROGMEM
|
||||
#define PGM_P const char *
|
||||
#define PSTR(s) \
|
||||
(__extension__({ \
|
||||
static const char __c[] = (s); \
|
||||
&__c[0]; \
|
||||
#define PSTR(s) \
|
||||
(__extension__({ \
|
||||
static const char __c[] = (s); \
|
||||
&__c[0]; \
|
||||
}))
|
||||
|
||||
class __FlashStringHelper;
|
||||
@@ -193,7 +193,11 @@ class NativeConsole : public Stream {
|
||||
unsigned char peek_data_;
|
||||
};
|
||||
|
||||
#include <Network.h>
|
||||
|
||||
extern NativeConsole Serial;
|
||||
extern ETHClass ETH;
|
||||
extern WiFiClass WiFi;
|
||||
|
||||
unsigned long millis();
|
||||
|
||||
|
||||
@@ -26,12 +26,12 @@ struct AsyncMqttClientMessageProperties {
|
||||
|
||||
namespace AsyncMqttClientInternals {
|
||||
|
||||
typedef std::function<void(bool sessionPresent)> OnConnectUserCallback;
|
||||
typedef std::function<void(AsyncMqttClientDisconnectReason reason)> OnDisconnectUserCallback;
|
||||
typedef std::function<void(uint16_t packetId, uint8_t qos)> OnSubscribeUserCallback;
|
||||
typedef std::function<void(uint16_t packetId)> OnUnsubscribeUserCallback;
|
||||
typedef std::function<void(bool sessionPresent)> OnConnectUserCallback;
|
||||
typedef std::function<void(AsyncMqttClientDisconnectReason reason)> OnDisconnectUserCallback;
|
||||
typedef std::function<void(uint16_t packetId, uint8_t qos)> OnSubscribeUserCallback;
|
||||
typedef std::function<void(uint16_t packetId)> OnUnsubscribeUserCallback;
|
||||
typedef std::function<void(char * topic, char * payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total)> OnMessageUserCallback;
|
||||
typedef std::function<void(uint16_t packetId)> OnPublishUserCallback;
|
||||
typedef std::function<void(uint16_t packetId)> OnPublishUserCallback;
|
||||
}; // namespace AsyncMqttClientInternals
|
||||
|
||||
class AsyncMqttClient {
|
||||
@@ -115,4 +115,4 @@ class AsyncMqttClient {
|
||||
bool _willRetain;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <SecurityManager.h>
|
||||
#include <SecuritySettingsService.h>
|
||||
#include <StatefulService.h>
|
||||
#include <Network.h>
|
||||
|
||||
class DummySettings {
|
||||
public:
|
||||
@@ -44,6 +45,7 @@ class DummySettings {
|
||||
String staticIPConfig = "";
|
||||
String dnsIP1 = "";
|
||||
String dnsIP2 = "";
|
||||
uint8_t ethernet_profile = 0;
|
||||
uint16_t publish_time_boiler = 10;
|
||||
uint16_t publish_time_thermostat = 10;
|
||||
uint16_t publish_time_solar = 10;
|
||||
@@ -66,11 +68,9 @@ class DummySettingsService : public StatefulService<DummySettings> {
|
||||
|
||||
void begin();
|
||||
void loop();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#define WiFiSettings DummySettings
|
||||
#define NetworkSettings DummySettings
|
||||
#define SecuritySettings DummySettings
|
||||
#define MqttSettings DummySettings
|
||||
|
||||
@@ -91,7 +91,7 @@ class ESP8266React {
|
||||
return _mqttClient;
|
||||
}
|
||||
|
||||
StatefulService<DummySettings> * getWiFiSettingsService() {
|
||||
StatefulService<DummySettings> * getNetworkSettingsService() {
|
||||
return &_settings;
|
||||
}
|
||||
|
||||
@@ -113,10 +113,7 @@ class ESP8266React {
|
||||
class EMSESPSettingsService {
|
||||
public:
|
||||
EMSESPSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager);
|
||||
|
||||
void begin();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class JsonUtils {
|
||||
|
||||
@@ -33,5 +33,4 @@
|
||||
#define FT_UPLOAD_FIRMWARE 0
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
180
lib_standalone/Network.h
Normal file
180
lib_standalone/Network.h
Normal file
@@ -0,0 +1,180 @@
|
||||
#ifndef Network_h
|
||||
#define Network_h
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <functional>
|
||||
|
||||
#define WiFiMode_t wifi_mode_t
|
||||
#define WIFI_OFF WIFI_MODE_NULL
|
||||
#define WIFI_STA WIFI_MODE_STA
|
||||
#define WIFI_AP WIFI_MODE_AP
|
||||
#define WIFI_AP_STA WIFI_MODE_APSTA
|
||||
|
||||
typedef enum {
|
||||
SYSTEM_EVENT_WIFI_READY = 0, /**< ESP32 WiFi ready */
|
||||
SYSTEM_EVENT_SCAN_DONE, /**< ESP32 finish scanning AP */
|
||||
SYSTEM_EVENT_STA_START, /**< ESP32 station start */
|
||||
SYSTEM_EVENT_STA_STOP, /**< ESP32 station stop */
|
||||
SYSTEM_EVENT_STA_CONNECTED, /**< ESP32 station connected to AP */
|
||||
SYSTEM_EVENT_STA_DISCONNECTED, /**< ESP32 station disconnected from AP */
|
||||
SYSTEM_EVENT_STA_AUTHMODE_CHANGE, /**< the auth mode of AP connected by ESP32 station changed */
|
||||
SYSTEM_EVENT_STA_GOT_IP, /**< ESP32 station got IP from connected AP */
|
||||
SYSTEM_EVENT_STA_LOST_IP, /**< ESP32 station lost IP and the IP is reset to 0 */
|
||||
SYSTEM_EVENT_STA_WPS_ER_SUCCESS, /**< ESP32 station wps succeeds in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_FAILED, /**< ESP32 station wps fails in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_TIMEOUT, /**< ESP32 station wps timeout in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_PIN, /**< ESP32 station wps pin code in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_PBC_OVERLAP, /*!< ESP32 station wps overlap in enrollee mode */
|
||||
SYSTEM_EVENT_AP_START, /**< ESP32 soft-AP start */
|
||||
SYSTEM_EVENT_AP_STOP, /**< ESP32 soft-AP stop */
|
||||
SYSTEM_EVENT_AP_STACONNECTED, /**< a station connected to ESP32 soft-AP */
|
||||
SYSTEM_EVENT_AP_STADISCONNECTED, /**< a station disconnected from ESP32 soft-AP */
|
||||
SYSTEM_EVENT_AP_STAIPASSIGNED, /**< ESP32 soft-AP assign an IP to a connected station */
|
||||
SYSTEM_EVENT_AP_PROBEREQRECVED, /**< Receive probe request packet in soft-AP interface */
|
||||
SYSTEM_EVENT_GOT_IP6, /**< ESP32 station or ap or ethernet interface v6IP addr is preferred */
|
||||
SYSTEM_EVENT_ETH_START, /**< ESP32 ethernet start */
|
||||
SYSTEM_EVENT_ETH_STOP, /**< ESP32 ethernet stop */
|
||||
SYSTEM_EVENT_ETH_CONNECTED, /**< ESP32 ethernet phy link up */
|
||||
SYSTEM_EVENT_ETH_DISCONNECTED, /**< ESP32 ethernet phy link down */
|
||||
SYSTEM_EVENT_ETH_GOT_IP, /**< ESP32 ethernet got IP from connected AP */
|
||||
SYSTEM_EVENT_MAX
|
||||
} system_event_id_t;
|
||||
|
||||
typedef enum {
|
||||
WIFI_AUTH_OPEN = 0, /**< authenticate mode : open */
|
||||
WIFI_AUTH_WEP, /**< authenticate mode : WEP */
|
||||
WIFI_AUTH_WPA_PSK, /**< authenticate mode : WPA_PSK */
|
||||
WIFI_AUTH_WPA2_PSK, /**< authenticate mode : WPA2_PSK */
|
||||
WIFI_AUTH_WPA_WPA2_PSK, /**< authenticate mode : WPA_WPA2_PSK */
|
||||
WIFI_AUTH_WPA2_ENTERPRISE, /**< authenticate mode : WPA2_ENTERPRISE */
|
||||
WIFI_AUTH_MAX
|
||||
} wifi_auth_mode_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t status; /**< status of scanning APs */
|
||||
uint8_t number;
|
||||
uint8_t scan_id;
|
||||
} system_event_sta_scan_done_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t ssid[32]; /**< SSID of connected AP */
|
||||
uint8_t ssid_len; /**< SSID length of connected AP */
|
||||
uint8_t bssid[6]; /**< BSSID of connected AP*/
|
||||
uint8_t channel; /**< channel of connected AP*/
|
||||
wifi_auth_mode_t authmode;
|
||||
} system_event_sta_connected_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t ssid[32]; /**< SSID of disconnected AP */
|
||||
uint8_t ssid_len; /**< SSID length of disconnected AP */
|
||||
uint8_t bssid[6]; /**< BSSID of disconnected AP */
|
||||
uint8_t reason; /**< reason of disconnection */
|
||||
} system_event_sta_disconnected_t;
|
||||
|
||||
typedef struct {
|
||||
wifi_auth_mode_t old_mode; /**< the old auth mode of AP */
|
||||
wifi_auth_mode_t new_mode; /**< the new auth mode of AP */
|
||||
} system_event_sta_authmode_change_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t pin_code[8]; /**< PIN code of station in enrollee mode */
|
||||
} system_event_sta_wps_er_pin_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t mac[6]; /**< MAC address of the station connected to ESP32 soft-AP */
|
||||
uint8_t aid; /**< the aid that ESP32 soft-AP gives to the station connected to */
|
||||
} system_event_ap_staconnected_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t mac[6]; /**< MAC address of the station disconnects to ESP32 soft-AP */
|
||||
uint8_t aid; /**< the aid that ESP32 soft-AP gave to the station disconnects to */
|
||||
} system_event_ap_stadisconnected_t;
|
||||
|
||||
typedef struct {
|
||||
int rssi; /**< Received probe request signal strength */
|
||||
uint8_t mac[6]; /**< MAC address of the station which send probe request */
|
||||
} system_event_ap_probe_req_rx_t;
|
||||
|
||||
typedef enum {
|
||||
WPS_FAIL_REASON_NORMAL = 0, /**< ESP32 WPS normal fail reason */
|
||||
WPS_FAIL_REASON_RECV_M2D, /**< ESP32 WPS receive M2D frame */
|
||||
WPS_FAIL_REASON_MAX
|
||||
} system_event_sta_wps_fail_reason_t;
|
||||
|
||||
typedef union {
|
||||
system_event_sta_connected_t connected; /**< ESP32 station connected to AP */
|
||||
system_event_sta_disconnected_t disconnected; /**< ESP32 station disconnected to AP */
|
||||
system_event_sta_scan_done_t scan_done; /**< ESP32 station scan (APs) done */
|
||||
system_event_sta_authmode_change_t auth_change; /**< the auth mode of AP ESP32 station connected to changed */
|
||||
system_event_sta_wps_fail_reason_t sta_er_fail_reason; /**< ESP32 station WPS enrollee mode failed reason code received */
|
||||
system_event_ap_staconnected_t sta_connected; /**< a station connected to ESP32 soft-AP */
|
||||
system_event_ap_stadisconnected_t sta_disconnected; /**< a station disconnected to ESP32 soft-AP */
|
||||
system_event_ap_probe_req_rx_t ap_probereqrecved; /**< ESP32 soft-AP receive probe request packet */
|
||||
} system_event_info_t;
|
||||
|
||||
typedef struct {
|
||||
system_event_id_t event_id; /**< event ID */
|
||||
system_event_info_t event_info; /**< event information */
|
||||
} system_event_t;
|
||||
|
||||
#define WiFiEvent_t system_event_id_t
|
||||
#define WiFiEventInfo_t system_event_info_t
|
||||
#define WiFiEventId_t wifi_event_id_t
|
||||
|
||||
typedef enum {
|
||||
WL_NO_SHIELD = 255, // for compatibility with WiFi Shield library
|
||||
WL_IDLE_STATUS = 0,
|
||||
WL_NO_SSID_AVAIL = 1,
|
||||
WL_SCAN_COMPLETED = 2,
|
||||
WL_CONNECTED = 3,
|
||||
WL_CONNECT_FAILED = 4,
|
||||
WL_CONNECTION_LOST = 5,
|
||||
WL_DISCONNECTED = 6
|
||||
} wl_status_t;
|
||||
|
||||
typedef void (*WiFiEventCb)(system_event_id_t event);
|
||||
typedef std::function<void(system_event_id_t event, system_event_info_t info)> WiFiEventFuncCb;
|
||||
typedef void (*WiFiEventSysCb)(system_event_t * event);
|
||||
typedef size_t wifi_event_id_t;
|
||||
|
||||
class WiFiClass {
|
||||
public:
|
||||
wifi_event_id_t onEvent(WiFiEventCb cbEvent, system_event_id_t event = SYSTEM_EVENT_MAX) {
|
||||
return 0;
|
||||
};
|
||||
wifi_event_id_t onEvent(WiFiEventFuncCb cbEvent, system_event_id_t event = SYSTEM_EVENT_MAX) {
|
||||
return 0;
|
||||
};
|
||||
wifi_event_id_t onEvent(WiFiEventSysCb cbEvent, system_event_id_t event = SYSTEM_EVENT_MAX) {
|
||||
return 0;
|
||||
};
|
||||
|
||||
char * getHostname() {
|
||||
return nullptr;
|
||||
}
|
||||
char * localIP() {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
class ETHClass {
|
||||
public:
|
||||
bool begin() {
|
||||
return false;
|
||||
};
|
||||
|
||||
void setHostname(const char * s){};
|
||||
char * getHostname() {
|
||||
return nullptr;
|
||||
}
|
||||
char * localIP() {
|
||||
return nullptr;
|
||||
}
|
||||
int linkSpeed() {
|
||||
return 100;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -56,7 +56,6 @@ inline bool operator==(const std::string & lhs, const ::String & rhs) {
|
||||
return lhs == rhs.c_str();
|
||||
}
|
||||
|
||||
|
||||
size_t strlcpy(char * __restrict dst, const char * __restrict src, size_t dsize);
|
||||
size_t strlcat(char * dst, const char * src, size_t siz);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user