Commit a49f68ca0fb8a74dd4db6e72d395aa3885d6b296
Committed by
GitHub
1 parent
7ab27edf
Add missing UPnP class
Showing
2 changed files
with
42 additions
and
0 deletions
hueplusplus/UPnP.cpp
0 → 100644
| 1 | +#include "UPnP.h" | |
| 2 | +#include "HttpHandler.h" | |
| 3 | +#include <algorithm> | |
| 4 | +#include <iostream> | |
| 5 | + | |
| 6 | +std::vector<std::pair<std::string, std::string>> UPnP::getDevices() | |
| 7 | +{ | |
| 8 | + // send UPnP M-Search request | |
| 9 | + std::vector<std::string> 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); | |
| 10 | + | |
| 11 | + std::vector<std::pair<std::string, std::string>> devices; | |
| 12 | + | |
| 13 | + // filter out devices | |
| 14 | + for (const std::string &s : foundDevices) | |
| 15 | + { | |
| 16 | + std::pair<std::string, std::string> device; | |
| 17 | + int start = s.find("LOCATION:") + 10; | |
| 18 | + std::cout << "Found \"LOCATION:\" at " << start << std::endl; | |
| 19 | + device.first = s.substr(start, s.find("\r\n", start)-start); | |
| 20 | + start = s.find("SERVER:") + 8; | |
| 21 | + device.second = s.substr(start, s.find("\r\n", start) - start); | |
| 22 | + devices.push_back(device); | |
| 23 | + } | |
| 24 | + | |
| 25 | + // remove duplicates -> maybe include this in device filtering without the need of unique and stuff? | |
| 26 | + devices.erase(std::unique(devices.begin(), devices.end()), devices.end()); | |
| 27 | + | |
| 28 | + return devices; | |
| 29 | +} | ... | ... |