mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-11 05:59:02 +08:00
Update ESP32SSDP library to access started state and ethernet fix
Add SSDP ad mDNS to ESP420 report| Add waiting loop to get the ethernet IP in DHCP in STA mode to be sure network services start with proper IP Change debug log to verbose log Bump version
This commit is contained in:
parent
d6a58d5574
commit
3bb05c9881
2
.github/ci/prepare-libs.sh
vendored
2
.github/ci/prepare-libs.sh
vendored
@ -6,7 +6,7 @@ shopt -s globstar
|
||||
ls $HOME
|
||||
# Make sure we are inside the github workspace
|
||||
cd $GITHUB_WORKSPACE
|
||||
cp -r ./libraries/ESP32SSDP-2.0.2 $HOME/arduino_ide/libraries/
|
||||
cp -r ./libraries/ESP32SSDP-2.0.3 $HOME/arduino_ide/libraries/
|
||||
cp -r ./libraries/arduinoWebSockets-2.6.1 $HOME/arduino_ide/libraries/
|
||||
cp -r ./libraries/DHT_sensor_library_for_ESPx-1.0.6 $HOME/arduino_ide/libraries/
|
||||
cp -r ./libraries/esp8266-oled-ssd1306-4.3.0 $HOME/arduino_ide/libraries/
|
||||
|
@ -126,7 +126,7 @@
|
||||
/* Use Ethernet
|
||||
* Enable ethernet communications
|
||||
*/
|
||||
//#define ETH_FEATURE
|
||||
#define ETH_FEATURE
|
||||
|
||||
// Ethernet type (Check ETH.h eth_phy_type_t)
|
||||
// TYPE_ETH_PHY_LAN8720
|
||||
@ -137,7 +137,7 @@
|
||||
// TYPE_ETH_PHY_KSZ8041
|
||||
// TYPE_ETH_PHY_KSZ8081
|
||||
// TYPE_ETH_PHY_W5500
|
||||
//#define ESP3D_ETH_PHY_TYPE TYPE_ETH_PHY_W5500
|
||||
#define ESP3D_ETH_PHY_TYPE TYPE_ETH_PHY_W5500
|
||||
|
||||
// Ethernet board Clock mode
|
||||
// MODE_ETH_CLOCK_GPIO0_IN
|
||||
@ -153,15 +153,15 @@
|
||||
// These are the pins for the W5500 chip using SPI
|
||||
#define ETHERNET_SPI_USE_SPI 1
|
||||
#define ETHERNET_SPI_USE_SPI2 0
|
||||
#define ETH_SPI_SCK 8
|
||||
#define ETH_SPI_SCK 18
|
||||
#define ETH_SPI_MISO 23
|
||||
#define ETH_SPI_MOSI 19
|
||||
#define ETH_PHY_CS 5
|
||||
#define ETH_PHY_IRQ 33
|
||||
#define ETH_PHY_IRQ -1
|
||||
#define ETH_PHY_RST 4
|
||||
|
||||
// Address of ethernet board
|
||||
#define ESP3D_ETH_PHY_ADDR 0
|
||||
#define ESP3D_ETH_PHY_ADDR 1
|
||||
|
||||
/* Use Bluetooth
|
||||
* Enable serial bluetooth communications
|
||||
@ -372,7 +372,7 @@
|
||||
/* Enable global filesystem
|
||||
* Allows to access to all filesystems from same location
|
||||
*/
|
||||
#define GLOBAL_FILESYSTEM_FEATURE
|
||||
//#define GLOBAL_FILESYSTEM_FEATURE
|
||||
|
||||
/* WebDav access
|
||||
* Use WebDav to access to your filesystem
|
||||
@ -380,7 +380,7 @@
|
||||
* FS_FLASH //mount Flash FS
|
||||
* FS_SD mount SD FS
|
||||
*/
|
||||
#define WEBDAV_FEATURE FS_ROOT
|
||||
//#define WEBDAV_FEATURE FS_ROOT
|
||||
|
||||
/* FTP access
|
||||
* Use FTP to access to your filesystem (1 connection only)
|
||||
@ -463,8 +463,8 @@
|
||||
* Wire address of display
|
||||
*/
|
||||
#define DISPLAY_I2C_ADDR 0x3c
|
||||
//#define ESP_SDA_PIN 21
|
||||
//#define ESP_SCL_PIN 22
|
||||
#define ESP_SDA_PIN 21
|
||||
#define ESP_SCL_PIN 22
|
||||
|
||||
/* Display reset pin
|
||||
* The pin used to reset the screen (optional)
|
||||
|
@ -81,6 +81,12 @@
|
||||
#if defined(AUTHENTICATION_FEATURE)
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
#endif // AUTHENTICATION_FEATURE
|
||||
#if defined(SSDP_FEATURE)
|
||||
#include <ESP32SSDP.h>
|
||||
#endif // SSDP_FEATURE
|
||||
#if defined(MDNS_FEATURE)
|
||||
#include "../../modules/mDNS/mDNS.h"
|
||||
#endif // MDNS_FEATURE
|
||||
|
||||
#if defined(USB_SERIAL_FEATURE)
|
||||
#include "../../modules/usb-serial/usb_serial_service.h"
|
||||
@ -304,6 +310,21 @@ void ESP3DCommands::ESP420(int cmd_params_pos, ESP3DMessage* msg) {
|
||||
false)) {
|
||||
return;
|
||||
}
|
||||
#if defined (SSDP_FEATURE)
|
||||
// SSDP enabled
|
||||
tmpstr = SSDP.started() ? "ON (" + String(SSDP.localIP().toString()) + ")" : "OFF";
|
||||
if (!dispatchIdValue(json, "SSDP", tmpstr.c_str(), target, requestId, false)) {
|
||||
return;
|
||||
}
|
||||
#endif // SSDP_FEATURE
|
||||
|
||||
#if defined (MDNS_FEATURE)
|
||||
// MDNS enabled
|
||||
tmpstr = esp3d_mDNS.started() ? "ON" : "OFF";
|
||||
if (!dispatchIdValue(json, "MDNS", tmpstr.c_str(), target, requestId, false)) {
|
||||
return;
|
||||
}
|
||||
#endif // MDNS_FEATURE
|
||||
|
||||
#if defined(HTTP_FEATURE)
|
||||
if (HTTP_Server::started()) {
|
||||
|
@ -1227,7 +1227,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg, uint8_t *sbuf, size_t len) {
|
||||
// check is need \n at the end of the command
|
||||
if (msg->type == ESP3DMessageType::unique ||
|
||||
msg->type == ESP3DMessageType::tail) {
|
||||
esp3d_log_d("unique or tail message :*%s*", (char *)sbuf);
|
||||
esp3d_log("unique or tail message :*%s*", (char *)sbuf);
|
||||
if (!formatCommand((char *)sbuf, len)) {
|
||||
esp3d_log("format command failed");
|
||||
String tmpstr = "";
|
||||
@ -1244,7 +1244,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg, uint8_t *sbuf, size_t len) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
esp3d_log_d("format command success, no need to update");
|
||||
esp3d_log("format command success, no need to update");
|
||||
if (!esp3d_message_manager.setDataContent(msg, sbuf, len)) {
|
||||
esp3d_log_e("set data content failed");
|
||||
esp3d_message_manager.deleteMsg(msg);
|
||||
@ -1254,7 +1254,7 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg, uint8_t *sbuf, size_t len) {
|
||||
} else {
|
||||
esp3d_log("not unique or tail message");
|
||||
if (msg->type == ESP3DMessageType::realtimecmd){
|
||||
esp3d_log_d("realtime command");
|
||||
esp3d_log("realtime command");
|
||||
}
|
||||
if (!esp3d_message_manager.setDataContent(msg, sbuf, len)) {
|
||||
esp3d_log_e("set data content failed");
|
||||
|
@ -22,7 +22,7 @@
|
||||
#define _VERSION_ESP3D_H
|
||||
|
||||
// version and sources location
|
||||
#define FW_VERSION "3.0.0.a246"
|
||||
#define FW_VERSION "3.0.0.a247"
|
||||
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
|
||||
|
||||
#endif //_VERSION_ESP3D_H
|
||||
|
@ -35,7 +35,7 @@
|
||||
#endif // ETHERNET_SPI_USE_SPI
|
||||
#if ETHERNET_SPI_USE_SPI2
|
||||
#define ETH_SPI SPI2
|
||||
#endif // ETHERNET_SPI_USE_SPI2
|
||||
#endif // ETHERNET_SPI_USE_SPI2
|
||||
#ifndef ETH_SPI
|
||||
#define ETH_SPI SPI
|
||||
#endif // ETH_SPI
|
||||
@ -102,9 +102,9 @@ bool EthConfig::begin(int8_t& espMode) {
|
||||
phytype = ETH_PHY_KSZ8081;
|
||||
}
|
||||
esp3d_log("ETH PHY Type %d", phytype);
|
||||
_started = ETH.begin(phytype, ESP3D_ETH_PHY_ADDR,
|
||||
ESP3D_ETH_PHY_POWER_PIN, ESP3D_ETH_PHY_MDC_PIN,
|
||||
ESP3D_ETH_PHY_MDIO_PIN, ESP3D_ETH_CLK_MODE_PIN);
|
||||
_started = ETH.begin(phytype, ESP3D_ETH_PHY_ADDR, ESP3D_ETH_PHY_POWER_PIN,
|
||||
ESP3D_ETH_PHY_MDC_PIN, ESP3D_ETH_PHY_MDIO_PIN,
|
||||
ESP3D_ETH_CLK_MODE_PIN);
|
||||
#endif // ESP3D_ETH_PHY_TYPE == TYPE_ETH_PHY_TLK110 || ESP3D_ETH_PHY_TYPE ==
|
||||
// TYPE_ETH_PHY_RTL8201 || ESP3D_ETH_PHY_TYPE == TYPE_ETH_PHY_DP83848 ||
|
||||
// ESP3D_ETH_PHY_TYPE == TYPE_ETH_PHY_KSZ8041 || ESP3D_ETH_PHY_TYPE ==
|
||||
@ -113,7 +113,7 @@ bool EthConfig::begin(int8_t& espMode) {
|
||||
esp3d_log("ETH spi PHY Type %d", ESP3D_ETH_PHY_TYPE);
|
||||
ETH_SPI.begin(ETH_SPI_SCK, ETH_SPI_MISO, ETH_SPI_MOSI);
|
||||
_started = ETH.begin(ETH_PHY_W5500, ESP3D_ETH_PHY_ADDR, ETH_PHY_CS,
|
||||
ETH_PHY_IRQ, ETH_PHY_RST, ETH_SPI);
|
||||
ETH_PHY_IRQ, ETH_PHY_RST, ETH_SPI);
|
||||
#endif // ESP3D_ETH_PHY_TYPE == TYPE_ETH_PHY_W5500
|
||||
|
||||
if (_started) {
|
||||
@ -155,16 +155,34 @@ bool EthConfig::begin(int8_t& espMode) {
|
||||
ESP3DClientType::system,
|
||||
ESP3DAuthenticationLevel::admin);
|
||||
}
|
||||
|
||||
res = true;
|
||||
}
|
||||
}
|
||||
// Static IP or DHCP client ?
|
||||
if ((ESP3DSettings::readByte(ESP_ETH_STA_IP_MODE) != DHCP_MODE)) {
|
||||
esp3d_log("Show IP");
|
||||
esp3d_commands.dispatch(ETH.localIP().toString().c_str(),
|
||||
ESP3DClientType::all_clients, no_id,
|
||||
ESP3DMessageType::unique, ESP3DClientType::system,
|
||||
ESP3DAuthenticationLevel::admin);
|
||||
if (res) {
|
||||
// Static IP or DHCP client ?
|
||||
if ((ESP3DSettings::readByte(ESP_ETH_STA_IP_MODE) == DHCP_MODE)) {
|
||||
uint64_t start = millis();
|
||||
String ip = ETH.localIP().toString();
|
||||
esp3d_log("IP");
|
||||
esp3d_log("Waiting for IP");
|
||||
while (millis() - start < 10000 && ip == "0.0.0.0") {
|
||||
ip = ETH.localIP().toString();
|
||||
ESP3DHal::wait(100);
|
||||
}
|
||||
if (ip != "0.0.0.0") {
|
||||
esp3d_log("Show IP");
|
||||
esp3d_commands.dispatch(
|
||||
ETH.localIP().toString().c_str(), ESP3DClientType::all_clients,
|
||||
no_id, ESP3DMessageType::unique, ESP3DClientType::system,
|
||||
ESP3DAuthenticationLevel::admin);
|
||||
} else {
|
||||
esp3d_log_e("Failed to get IP");
|
||||
res = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
esp3d_log_e("Failed starting ethernet");
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -46,33 +46,33 @@ void HTTP_Server::handle_web_command() {
|
||||
bool isRealTimeCommand = false;
|
||||
if (_webserver->hasArg("cmd")) {
|
||||
cmd = _webserver->arg("cmd");
|
||||
esp3d_log_d("Command is %s", cmd.c_str());
|
||||
esp3d_log("Command is %s", cmd.c_str());
|
||||
if (!cmd.endsWith("\n")) {
|
||||
esp3d_log_d("Command is not ending with \\n");
|
||||
esp3d_log("Command is not ending with \\n");
|
||||
if (ESP3DSettings::GetFirmwareTarget() == GRBL || ESP3DSettings::GetFirmwareTarget() == GRBLHAL) {
|
||||
uint len = cmd.length();
|
||||
if (!((len == 1 && esp3d_string::isRealTimeCommand(cmd[0])) ||
|
||||
(len == 2 && esp3d_string::isRealTimeCommand(cmd[1])))) {
|
||||
cmd += "\n";
|
||||
esp3d_log_d("Command is not realtime, adding \\n");
|
||||
esp3d_log("Command is not realtime, adding \\n");
|
||||
} else { // no need \n for realtime command
|
||||
esp3d_log_d("Command is realtime, no need to add \\n");
|
||||
esp3d_log("Command is realtime, no need to add \\n");
|
||||
isRealTimeCommand = true;
|
||||
// remove the 0XC2 that should not be there
|
||||
if (len == 2 && esp3d_string::isRealTimeCommand(cmd[1]) && cmd[1] == 0xC2) {
|
||||
cmd[0] = cmd[1];
|
||||
cmd[1] = 0x0;
|
||||
esp3d_log_d("Command is realtime, removing 0xC2");
|
||||
esp3d_log("Command is realtime, removing 0xC2");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
esp3d_log_d("Command is not realtime, adding \\n");
|
||||
esp3d_log("Command is not realtime, adding \\n");
|
||||
cmd += "\n"; // need to validate command
|
||||
}
|
||||
} else {
|
||||
esp3d_log_d("Command is ending with \\n");
|
||||
esp3d_log("Command is ending with \\n");
|
||||
}
|
||||
esp3d_log_d("Message type is %s for %s", isRealTimeCommand ? "realtimecmd" : "unique", cmd.c_str());
|
||||
esp3d_log("Message type is %s for %s", isRealTimeCommand ? "realtimecmd" : "unique", cmd.c_str());
|
||||
if (esp3d_commands.is_esp_command((uint8_t *)cmd.c_str(), cmd.length())) {
|
||||
ESP3DMessage *msg = esp3d_message_manager.newMsg(
|
||||
ESP3DClientType::http, esp3d_commands.getOutputClient(),
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=ESP32SSDP
|
||||
version=2.0.2
|
||||
version=2.0.3
|
||||
author=Me-No-Dev
|
||||
maintainer=luc-github
|
||||
sentence=Simple SSDP library for ESP32
|
@ -144,6 +144,7 @@ SSDPClass::SSDPClass() : _replySlots{NULL}, _respondToAddr{0, 0, 0, 0} {
|
||||
SSDPClass::~SSDPClass() { end(); }
|
||||
|
||||
void SSDPClass::end() {
|
||||
_started = false;
|
||||
if (_schema) {
|
||||
free(_schema);
|
||||
_schema = nullptr;
|
||||
@ -175,17 +176,16 @@ IPAddress SSDPClass::localIP() {
|
||||
// Arduino ESP32 3.x board version
|
||||
esp_netif_ip_info_t ip;
|
||||
if (WiFi.getMode() == WIFI_STA) {
|
||||
if (esp_netif_get_ip_info(get_esp_interface_netif(ESP_IF_WIFI_STA), &ip)) {
|
||||
if (esp_netif_get_ip_info(get_esp_interface_netif(ESP_IF_WIFI_STA), &ip)!=ESP_OK) {
|
||||
return IPAddress();
|
||||
}
|
||||
} else if (WiFi.getMode() == WIFI_OFF) {
|
||||
if (esp_netif_get_ip_info(get_esp_interface_netif(ESP_IF_ETH), &ip)) {
|
||||
if (esp_netif_get_ip_info(esp_netif_get_handle_from_ifkey("ETH_DEF"), &ip)!=ESP_OK) {
|
||||
return IPAddress();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return IPAddress(ip.ip.addr);
|
||||
}
|
||||
|
||||
@ -230,7 +230,7 @@ bool SSDPClass::begin() {
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
_started = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ class SSDPClass {
|
||||
|
||||
bool begin();
|
||||
void end();
|
||||
bool started() { return _started; }
|
||||
|
||||
const char* getSchema();
|
||||
|
||||
@ -105,13 +106,13 @@ class SSDPClass {
|
||||
void setUUID(const char* uuid, bool rootonly = true);
|
||||
void setServices(const char* services) { _services = services; }
|
||||
void setIcons(const char* icons) { _icons = icons; }
|
||||
|
||||
IPAddress localIP();
|
||||
protected:
|
||||
typedef enum { NONE, SEARCH, NOTIFY } ssdp_method_t;
|
||||
|
||||
void _onPacket(AsyncUDPPacket& packet);
|
||||
void _send(ssdp_method_t method);
|
||||
IPAddress localIP();
|
||||
|
||||
uint16_t _port;
|
||||
uint32_t _ttl;
|
||||
uint32_t _interval;
|
||||
@ -122,6 +123,7 @@ class SSDPClass {
|
||||
|
||||
bool _pending;
|
||||
bool _stmatch;
|
||||
bool _started;
|
||||
short _delay;
|
||||
unsigned long _process_time;
|
||||
unsigned long _notify_time;
|
Loading…
x
Reference in New Issue
Block a user