diff --git a/hueplusplus/UPnP.cpp b/hueplusplus/UPnP.cpp new file mode 100644 index 0000000..39d3bac --- /dev/null +++ b/hueplusplus/UPnP.cpp @@ -0,0 +1,29 @@ +#include "UPnP.h" +#include "HttpHandler.h" +#include +#include + +std::vector> UPnP::getDevices() +{ + // send UPnP M-Search request + std::vector foundDevices = HttpHandler().sendMulticast("M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\nMX: 5\r\nST: ssdp:all\r\n\r\n", "239.255.255.250", 1900, 5); + + std::vector> devices; + + // filter out devices + for (const std::string &s : foundDevices) + { + std::pair device; + int start = s.find("LOCATION:") + 10; + std::cout << "Found \"LOCATION:\" at " << start << std::endl; + device.first = s.substr(start, s.find("\r\n", start)-start); + start = s.find("SERVER:") + 8; + device.second = s.substr(start, s.find("\r\n", start) - start); + devices.push_back(device); + } + + // remove duplicates -> maybe include this in device filtering without the need of unique and stuff? + devices.erase(std::unique(devices.begin(), devices.end()), devices.end()); + + return devices; +} diff --git a/hueplusplus/UPnP.h b/hueplusplus/UPnP.h new file mode 100644 index 0000000..ad60297 --- /dev/null +++ b/hueplusplus/UPnP.h @@ -0,0 +1,13 @@ +#ifndef _UPNP_H +#define _UPNP_H + +#include +#include + +class UPnP +{ +public: + std::vector> getDevices(); +}; + +#endif \ No newline at end of file