38 lines
1018 B
Plaintext
38 lines
1018 B
Plaintext
#include <WiFi.h>
|
|
#include <WiFiUdp.h>
|
|
#define SSDP_MULTICAST_IP IPAddress("239.255.255.250")
|
|
#define SSDP_PORT 1900
|
|
#define UPNP_HTTP_PORT 5000 // Most routers use 5000, but it can vary
|
|
#define SEARCH_TIMEOUT 5000 // 2 seconds timeout
|
|
|
|
class CUpnpClient {
|
|
private:
|
|
IPAddress routerIP;
|
|
String routerIPString;
|
|
uint16_t routerPort;
|
|
|
|
IPAddress publicIP;
|
|
uint16_t publicPort;
|
|
|
|
uint32_t lastDiscoveryTime;
|
|
String routerLocation;
|
|
String controlURL;
|
|
char buffer[1024]; // Stack-based buffer for responses
|
|
|
|
public:
|
|
CUpnpClient() : publicPort(0), lastDiscoveryTime(0) {}
|
|
|
|
bool registerUPnP(uint32_t *pip, uint16_t *pport);
|
|
|
|
private:
|
|
String fetchUPnPDescription(const String &location);
|
|
String parseXML(const String &xml);
|
|
int sendSoapRequest(const char *request, char *response, size_t responseSize);
|
|
|
|
bool discoverUPnP();
|
|
bool requestPortMappingEntry();
|
|
bool requestPortForwarding();
|
|
bool requestExternalIP();
|
|
bool requestExternalPort();
|
|
};
|