oatpp / example-iot-hue-ssdp

Oat++ Example to emulate a Hue bridge using SSDP and HTTP
https://oatpp.io/
Apache License 2.0
17 stars 2 forks source link

unable to register device using echo #1

Open DavidHamburg opened 3 years ago

DavidHamburg commented 3 years ago

Hi,

I try to connect these example app running on a raspberry pi 3b+ with an echo v4. I can see some M-Search requests and calls in the HueDeviceController, but the echo always tells me that no device has been discovered. Also the alexa app (ios) is not able to find the example app. Do you have any idea?

 D |2021-01-01 13:08:34 1609502914027967| SsdpController:'M-SEARCH *' Received
 D |2021-01-01 13:08:34 1609502914032943| SsdpController:'M-SEARCH *' Received
 D |2021-01-01 13:08:34 1609502914033414| SsdpController:'M-SEARCH *' Received
 D |2021-01-01 13:08:34 1609502914033865| SsdpController:'M-SEARCH *' Received
 D |2021-01-01 13:08:34 1609502914034296| SsdpController:'M-SEARCH *' Received
 D |2021-01-01 13:08:34 1609502914034724| SsdpController:'M-SEARCH *' Received
 D |2021-01-01 13:08:34 1609502914041353| HueDeviceController:Request for description
 D |2021-01-01 13:08:34 1609502914069043| HueDeviceController:POST on /api with empty user, generated 'OatppSsdpHueDefaultUserfa37JncCHryDsbzay'
 D |2021-01-01 13:08:34 1609502914069130| HueDeviceController:Devicetype: Echo
 D |2021-01-01 13:08:34 1609502914095009| HueDeviceController:GET on /api/{username}/lights
 D |2021-01-01 13:08:34 1609502914137050| HueDeviceController:GET on /api/OatppSsdpHueDefaultUserpPIhMFSv8kP07U20o/lights/1
 D |2021-01-01 13:08:34 1609502914163191| HueDeviceController:POST on /api with empty user, generated 'OatppSsdpHueDefaultUsery4cBWDxS22JjzhMai'
 D |2021-01-01 13:08:34 1609502914163276| HueDeviceController:Devicetype: Echo
 D |2021-01-01 13:08:34 1609502914171557| HueDeviceController:GET on /api/{username}/lights
lganzzzo commented 3 years ago

Hey @bamkrs , can you please assist with this issue.

bamkrs commented 3 years ago

Hey @DavidHamburg please be Patient. I'll fire up the example on my machine again with newest Oat++ and report back shortly.

But as a first try, have you set your IP-Address correclty? https://github.com/oatpp/example-iot-hue-ssdp/blob/ce533b6764b334c61a0347d1e176851913dde9bc/src/DeviceDescriptorComponent.hpp#L21

Have you checked your device list in your Alexa app? I've noticed that some times the app tells you "nothing" but the device was silently registered anyhow.

DavidHamburg commented 3 years ago

Thank you for your quick response!

But as a first try, have you set your IP-Address correclty?

https://github.com/oatpp/example-iot-hue-ssdp/blob/ce533b6764b334c61a0347d1e176851913dde9bc/src/DeviceDescriptorComponent.hpp#L21

yes, I have changed the IP address and double checked it in the swagger ui. The echo device also seems to call the proper routes from the HueDeviceController. What looks kinda strange is the second call of /api/{username}/lights in the log output.

Have you checked your device list in your Alexa app? I've noticed that some times the app tells you "nothing" but the device was silently registered anyhow.

No, unfortunately not.

bamkrs commented 3 years ago

Hey @DavidHamburg I'll need a bit longer. I've updated my macOS to Big Sur and am unable to receive multicast messages anymore. I'll have to look into this before I can can start working on the actual problem. Sorry for that, I'll try my best tomorrow.

DavidHamburg commented 3 years ago

Sure, there is no rush!

bamkrs commented 3 years ago

Hey @DavidHamburg I'm working on the issue and can confirm your problem. It seems that in some unknown update to Alexa there were some silent changes to the discovery process (it seems to be unhappy about some parts of the response).

DavidHamburg commented 3 years ago

Thank you for the hint. It seems that the unique id format has been changed in the last weeks (see https://github.com/bwssytems/ha-bridge/issues/1272). I have updated the uniqueid in https://github.com/oatpp/example-iot-hue-ssdp/blob/ce533b6764b334c61a0347d1e176851913dde9bc/src/db/Database.cpp#L65 and now alexa is able to find my device.

Many thanks for your fast support!

bamkrs commented 3 years ago

Hey @DavidHamburg awesome that you have created an PR! Are you sure that is the issue? I was already looking at the fauxmoESP and other sources and have seen this change. I Implemented it locally but I still have no luck finding new devices.

DavidHamburg commented 3 years ago

Are you sure that is the issue? I was already looking at the fauxmoESP and other sources and have seen this change. I Implemented it locally but I still have no luck finding new devices.

Quite sure, I was able to find the devices with alexa several times after removing the "-". Maybe your string is too short? You must have an 0001 at the end of the device id. I have updated the pull request, can you try it again with my changes?

Also ensure the port is 80, all others did not work for me.

bamkrs commented 3 years ago

Hey @DavidHamburg yes I found the new id scheme and now it works for me, too. In my experiments I implemented a few other functions and fixed some more bugs. Is it ok if I close your PR and push all my fixes including the new naming? However, I can understand if you want your PR merged, at least you found the bug 👍

DavidHamburg commented 3 years ago

In my experiments I implemented a few other functions and fixed some more bugs. Is it ok if I close your PR and push all my fixes including the new naming?

Sure, you can close my PR.

bamkrs commented 3 years ago

Hey @DavidHamburg I closed your PR and at least mentioned you in my commit. Thanks again for finding the issue! In the newest version of the example, Alexa now shows the correct symbol in the app (a lightbulb) and you can set the brightness and color temperature, too. Setting a custom color works too, but Alexa will show you an error and does not confirm nor show which color you have set. Still need to figure out why.

DavidHamburg commented 3 years ago

Thank you for the fixes. I have removed the device again from the alexa app and tried to re-register. With the latest commit alexa is not able to find the device again. Maybe the uniqueid (b97febe6d19c7d6e00000000) is too long?

bamkrs commented 3 years ago

Thats odd. I double checked that it works on my Echo (Gen2). Maybe the Gen4 has other constraints. At least we know BE570A70CAFEx worked for your Gen4. So maybe they limited it to 16 characters? Could you test the following scheme with your Gen4?

oatpp::Object<HueDeviceDto> Database::deserializeToDto(const HueDevice& hueDevice){
  auto dto = HueDeviceDto::createShared();
  size_t namehash = std::hash<std::string>{}(hueDevice.name->std_str());
  char idstr[16] = {0};
  snprintf(idstr, 16, "%08zx%04d", namehash & 0xffffffff, hueDevice.id);
  dto->uniqueid = idstr;
  dto->name = hueDevice.name;
  dto->state->bri = hueDevice.bri;
  dto->state->on = hueDevice.on;
  dto->state->ct = hueDevice.ct;
  dto->state->hue = hueDevice.hue;
  dto->state->sat = hueDevice.sat;
  dto->state->colormode = hueDevice.mode;
  return dto;
}

This would reduce the length to 12 characters like BE570A70CAFE was without the numbering.