mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 14:18:57 +08:00
update with latest version of SSDP
This commit is contained in:
parent
36ff302558
commit
e671169f2d
@ -111,7 +111,7 @@ struct SSDPTimer {
|
|||||||
|
|
||||||
SSDPClass::SSDPClass() :
|
SSDPClass::SSDPClass() :
|
||||||
_server(0),
|
_server(0),
|
||||||
_timer(new SSDPTimer),
|
_timer(0),
|
||||||
_port(80),
|
_port(80),
|
||||||
_ttl(SSDP_MULTICAST_TTL),
|
_ttl(SSDP_MULTICAST_TTL),
|
||||||
_respondToPort(0),
|
_respondToPort(0),
|
||||||
@ -134,30 +134,53 @@ _notify_time(0)
|
|||||||
}
|
}
|
||||||
|
|
||||||
SSDPClass::~SSDPClass(){
|
SSDPClass::~SSDPClass(){
|
||||||
delete _timer;
|
end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SSDPClass::end(){
|
||||||
|
if(!_server) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#ifdef DEBUG_SSDP
|
||||||
|
DEBUG_SSDP.printf_P(PSTR("SSDP end ... "));
|
||||||
|
#endif
|
||||||
|
// undo all initializations done in begin(), in reverse order
|
||||||
|
_stopTimer();
|
||||||
|
_server->stop();
|
||||||
|
delete (_server);
|
||||||
|
_server = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPAddress SSDPClass::localIP(){
|
||||||
|
tcpip_adapter_ip_info_t ip;
|
||||||
|
if (WiFi.getMode() == WIFI_STA) {
|
||||||
|
if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip)) {
|
||||||
|
return IPAddress();
|
||||||
|
}
|
||||||
|
} else if (WiFi.getMode() == WIFI_OFF) {
|
||||||
|
if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip)) {
|
||||||
|
return IPAddress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return IPAddress(ip.ip.addr);
|
||||||
|
}
|
||||||
|
|
||||||
bool SSDPClass::begin(){
|
bool SSDPClass::begin(){
|
||||||
_pending = false;
|
_pending = false;
|
||||||
|
end();
|
||||||
uint32_t chipId = ((uint16_t) (ESP.getEfuseMac() >> 32));
|
uint32_t chipId = ((uint16_t) (ESP.getEfuseMac() >> 32));
|
||||||
sprintf(_uuid, "38323636-4558-4dda-9188-cda0e6%02x%02x%02x",
|
sprintf(_uuid, "38323636-4558-4dda-9188-cda0e6%02x%02x%02x",
|
||||||
(uint16_t) ((chipId >> 16) & 0xff),
|
(uint16_t) ((chipId >> 16) & 0xff),
|
||||||
(uint16_t) ((chipId >> 8) & 0xff),
|
(uint16_t) ((chipId >> 8) & 0xff),
|
||||||
(uint16_t) chipId & 0xff );
|
(uint16_t) chipId & 0xff );
|
||||||
|
assert(nullptr == _server);
|
||||||
|
_server = new WiFiUDP;
|
||||||
#ifdef DEBUG_SSDP
|
#ifdef DEBUG_SSDP
|
||||||
DEBUG_SSDP.printf("SSDP UUID: %s\n", (char *)_uuid);
|
DEBUG_SSDP.printf("SSDP UUID: %s\n", (char *)_uuid);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (_server) {
|
|
||||||
delete (_server);
|
|
||||||
_server = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
_server = new WiFiUDP;
|
_server = new WiFiUDP;
|
||||||
|
|
||||||
if (!(_server->beginMulticast(IPAddress(SSDP_MULTICAST_ADDR), SSDP_PORT))) {
|
if (!(_server->beginMulticast(IPAddress(SSDP_MULTICAST_ADDR), SSDP_PORT))) {
|
||||||
#ifdef DEBUG_SSDP
|
#ifdef DEBUG_SSDP
|
||||||
DEBUG_SSDP.println("Error begin");
|
DEBUG_SSDP.println("Error begin");
|
||||||
@ -172,7 +195,7 @@ bool SSDPClass::begin(){
|
|||||||
|
|
||||||
void SSDPClass::_send(ssdp_method_t method){
|
void SSDPClass::_send(ssdp_method_t method){
|
||||||
char buffer[1460];
|
char buffer[1460];
|
||||||
IPAddress ip = WiFi.localIP();
|
IPAddress ip = localIP();
|
||||||
|
|
||||||
char valueBuffer[strlen_P(_ssdp_notify_template)+1];
|
char valueBuffer[strlen_P(_ssdp_notify_template)+1];
|
||||||
strcpy_P(valueBuffer, (method == NONE)?_ssdp_response_template:_ssdp_notify_template);
|
strcpy_P(valueBuffer, (method == NONE)?_ssdp_response_template:_ssdp_notify_template);
|
||||||
@ -187,7 +210,7 @@ void SSDPClass::_send(ssdp_method_t method){
|
|||||||
_deviceType,
|
_deviceType,
|
||||||
ip[0], ip[1], ip[2], ip[3], _port, _schemaURL
|
ip[0], ip[1], ip[2], ip[3], _port, _schemaURL
|
||||||
);
|
);
|
||||||
|
if(len < 0) return;
|
||||||
IPAddress remoteAddr;
|
IPAddress remoteAddr;
|
||||||
uint16_t remotePort;
|
uint16_t remotePort;
|
||||||
if(method == NONE) {
|
if(method == NONE) {
|
||||||
@ -214,7 +237,7 @@ void SSDPClass::_send(ssdp_method_t method){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SSDPClass::schema(WiFiClient client){
|
void SSDPClass::schema(WiFiClient client){
|
||||||
IPAddress ip = WiFi.localIP();
|
IPAddress ip = localIP();
|
||||||
char buffer[strlen_P(_ssdp_schema_template)+1];
|
char buffer[strlen_P(_ssdp_schema_template)+1];
|
||||||
strcpy_P(buffer, _ssdp_schema_template);
|
strcpy_P(buffer, _ssdp_schema_template);
|
||||||
client.printf(buffer,
|
client.printf(buffer,
|
||||||
@ -234,7 +257,7 @@ void SSDPClass::schema(WiFiClient client){
|
|||||||
|
|
||||||
void SSDPClass::_update(){
|
void SSDPClass::_update(){
|
||||||
int nbBytes =0;
|
int nbBytes =0;
|
||||||
char * packetBuffer = NULL;
|
char * packetBuffer = nullptr;
|
||||||
|
|
||||||
if(!_pending && _server) {
|
if(!_pending && _server) {
|
||||||
ssdp_method_t method = NONE;
|
ssdp_method_t method = NONE;
|
||||||
@ -430,6 +453,8 @@ void SSDPClass::_onTimerStatic(SSDPClass* self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SSDPClass::_startTimer() {
|
void SSDPClass::_startTimer() {
|
||||||
|
_stopTimer();
|
||||||
|
_timer= new SSDPTimer();
|
||||||
ETSTimer* tm = &(_timer->timer);
|
ETSTimer* tm = &(_timer->timer);
|
||||||
const int interval = 1000;
|
const int interval = 1000;
|
||||||
ets_timer_disarm(tm);
|
ets_timer_disarm(tm);
|
||||||
@ -437,6 +462,16 @@ void SSDPClass::_startTimer() {
|
|||||||
ets_timer_arm(tm, interval, 1 /* repeat */);
|
ets_timer_arm(tm, interval, 1 /* repeat */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SSDPClass::_stopTimer() {
|
||||||
|
if(!_timer){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ETSTimer* tm = &(_timer->timer);
|
||||||
|
ets_timer_disarm(tm);
|
||||||
|
delete _timer;
|
||||||
|
_timer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SSDP)
|
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SSDP)
|
||||||
SSDPClass SSDP;
|
SSDPClass SSDP;
|
||||||
#endif
|
#endif
|
||||||
|
@ -60,6 +60,7 @@ class SSDPClass{
|
|||||||
~SSDPClass();
|
~SSDPClass();
|
||||||
|
|
||||||
bool begin();
|
bool begin();
|
||||||
|
void end();
|
||||||
|
|
||||||
void schema(WiFiClient client);
|
void schema(WiFiClient client);
|
||||||
|
|
||||||
@ -91,8 +92,9 @@ class SSDPClass{
|
|||||||
void _send(ssdp_method_t method);
|
void _send(ssdp_method_t method);
|
||||||
void _update();
|
void _update();
|
||||||
void _startTimer();
|
void _startTimer();
|
||||||
|
void _stopTimer();
|
||||||
static void _onTimerStatic(SSDPClass* self);
|
static void _onTimerStatic(SSDPClass* self);
|
||||||
|
IPAddress localIP();
|
||||||
WiFiUDP *_server;
|
WiFiUDP *_server;
|
||||||
SSDPTimer* _timer;
|
SSDPTimer* _timer;
|
||||||
uint16_t _port;
|
uint16_t _port;
|
||||||
|
@ -36,6 +36,7 @@ void setup() {
|
|||||||
SSDP.setModelURL("http://www.meethue.com");
|
SSDP.setModelURL("http://www.meethue.com");
|
||||||
SSDP.setManufacturer("Royal Philips Electronics");
|
SSDP.setManufacturer("Royal Philips Electronics");
|
||||||
SSDP.setManufacturerURL("http://www.philips.com");
|
SSDP.setManufacturerURL("http://www.philips.com");
|
||||||
|
SSDP.setDeviceType("upnp:rootdevice"); //to appear as root device
|
||||||
SSDP.begin();
|
SSDP.begin();
|
||||||
|
|
||||||
Serial.printf("Ready!\n");
|
Serial.printf("Ready!\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user