isaacrlevin / presencelight

PresenceLight is a solution to broadcast your various statuses to light bulbs.
MIT License
419 stars 77 forks source link

How to use PresenceLight Custom API Settings with ThingM Blink(1) USB LED. #823

Closed jescodev closed 1 year ago

jescodev commented 1 year ago

I wanted to control the ThingM Blink(1) USB LED via the custom API interface of the PresenceLight Application. The Blink(1) USB LED can be controlled via command line command:

curl http://localhost:8934/blink1/fadeToRGB?rgb=%23ff0000

The Blink(1) API on PC is via the Blink1Control2 application, with the API Server Configuration option set to Start API Server, port 8934, and host set to localhost.

I tried using the PresenceLight Configure Custom API settings: Connect to Custom API = checked. Then set Available: to POST with the string "http://localhost:8934/blink1/fadeToRGB?rgb=%23ff0000" - same as what works at command line with curl.

I tried some other POST strings - with and without the curl command, but am not able to have any control of the USB LED via PresenceLight Custom API. If there are any examples of working Custom API strings for a POST command, that may help or if I am missing something please advise. Thank you!

isaacrlevin commented 1 year ago

Are you able to see what the actual request that gets called with Fiddler?

jescodev commented 1 year ago

Thank you for the suggestion- I will try that!My question is - what is the correct text to use with the Custom API?Do I just provide the http:\.... text or do I need quotes or ???That is why I was looking for a working example so I could see if I have correct format for what the Custom API uses/wants.Thank you.

On Tuesday, May 30, 2023 at 02:00:27 PM PDT, Isaac Levin ***@***.***> wrote:  

Are you able to see what the actual request that gets called with Fiddler?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

isaacrlevin commented 1 year ago

It uses the full URI, so http:// is needed. Here is the code that gets called if you are curious

https://github.com/isaacrlevin/presencelight/blob/7a050672b69417c43558635100239ca1407fa68e/src/PresenceLight.Core/Lights/CustomApiService/CustomApiService.cs#L254

jescodev commented 1 year ago

Awesome, thx for the info.I installed Fiddler- pretty cool to see all the activity.I'll let you know if I can see the communications.

On Tuesday, May 30, 2023 at 02:14:58 PM PDT, Isaac Levin ***@***.***> wrote:  

It uses the full URI, so http:// is needed. Here is the code that gets called if you are curious

https://github.com/isaacrlevin/presencelight/blob/7a050672b69417c43558635100239ca1407fa68e/src/PresenceLight.Core/Lights/CustomApiService/CustomApiService.cs#L254

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

jescodev commented 1 year ago

I am using localhost as the destination, also tried using the system name.http://WIN10-JS:8934/blink1/fadeToRGB?rgb=%23ffffff Both localhost and system name worked at command line using curl.

But I do not see anything from the PresenceLight app when it updates (after I change my teams status).I do see activity in fiddler, including when I change teams status.But nothing from PresenceLight.So I think that PresenceLight is not sending the POST - either the app might be blocked from sending localhost posts or ??. Telerik will not show localhost activity, so that is why I tried name.https://docs.telerik.com/fiddler-everywhere/knowledge-base/capturing-localhost-traffic

I guess I have to prove that Fiddle is showing localhost activity tooo.. I'll try that.May have to get back to this later, but thanks for your direction. I also will try with a non-localhost POST.Have you used postman? Also looks popular. I am new to the world of REST.

On Tuesday, May 30, 2023 at 02:25:42 PM PDT, James Smith ***@***.***> wrote:  

Awesome, thx for the info.I installed Fiddler- pretty cool to see all the activity.I'll let you know if I can see the communications.

On Tuesday, May 30, 2023 at 02:14:58 PM PDT, Isaac Levin ***@***.***> wrote:  

It uses the full URI, so http:// is needed. Here is the code that gets called if you are curious

https://github.com/isaacrlevin/presencelight/blob/7a050672b69417c43558635100239ca1407fa68e/src/PresenceLight.Core/Lights/CustomApiService/CustomApiService.cs#L254

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

isaacrlevin commented 1 year ago

I just tried with your system name url and it shows up in Fiddler. Are you able to clone the code and debug the app in VS?

image
jescodev commented 1 year ago

Cool, at least its getting out. I did not see that when I tried.Can you please send me a screen shot of the Custom API settings you used, maybe it is that simple- there is something different on my custom api setting ? I can try to get setup for VS debug... Saw one on ebay- half price.https://www.ebay.com/itm/134399026825?hash=item1f4ace6689:g:5m0AAOSwR4BjtgOc&amdata=enc%3AAQAIAAAA4Psgr%2B1Bo0dgjF2G1MGhNbB%2B0arDmhIGUWC%2BrJfKkADOa2Nto22XzJRBxmC9RPaL4CYrDl9vVadlh%2Fq3VR1iaJAKdKvMuia1i2tkOYxvOp53zD86fRpCRWL37200ZZTqI2E2ybLzg5xNWFzG%2BWeGFDU5%2B%2FakozTDK5v%2FHyT44Sn153lmq%2BlfQTTiGgUehnNTBSNAI9h%2Bo8uhApyp4O1nuNxmNcaLklf3RTbudr0sjiLhoUcS5nJvOyeucO%2B%2FmcLYKPaxn%2BEO%2FtQDA6pKy%2B3JaWkwOojljXJe2HZTR2JqABSe%7Ctkp%3ABk9SR9qR3bmOYg

On Wednesday, May 31, 2023 at 01:29:38 PM PDT, Isaac Levin ***@***.***> wrote:  

I just tried with your system name url and it shows up in Fiddler. Are you able to clone the code and debug the app in VS?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

isaacrlevin commented 1 year ago

Here are my settings

image
jescodev commented 1 year ago

Thanks-I appreciate the reference to a 'working' setting.Sometimes things are implied- but this looks same as what I set to. I was using POST, not sure if that made a difference.So I thought POST sends commands and GET would request status.I guess I can try GET too.

On Wednesday, May 31, 2023 at 02:02:55 PM PDT, Isaac Levin ***@***.***> wrote:  

Here are my settings

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

jescodev commented 1 year ago

Hi Issac-That seems to be it!!! I had removed the app, but just did a install of the nightly.Then config'd the custom setting to be similar to your example.I used localhost and a GET instead of POST. So I can not control the ThingM Blink(1) LED with the PresenceLight app.Thank you for your patience.-James Sorry in advance...Now- what I really want to do, is have the LED show the status of a different user, so the LED changes color when that other user of teams goes thru different presence status'. I thought this might take some custom coding, where I hard code the user I want to monitor- I am willing to try to code that. But... if you want to add some kind of a text box to allow the PresenceLight to reflect another person's status (which is already available in teams) that would possibly be a popular feature- for example monitoring the boss' status. -James

On Wednesday, May 31, 2023 at 02:02:55 PM PDT, Isaac Levin ***@***.***> wrote:  

Here are my settings

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

isaacrlevin commented 1 year ago

Tracking presence for another user is not supported and will never be supported due to AAD App Registration consent things

jescodev commented 1 year ago

Ok. Good to know.Sounds like a good idea. Anyways-We can close the ticket. Does it make sense to you that the GET worked, but not the POST?It is working great. If you want, I can send you a ThingM Blink(1) device, then you can possibly add built in support for the device even though it is really already supported with the custom API settings. Or maybe just add a WIKI entry for the ThingM Blink(1) LED support, showing working examples and PC config. Thx again!-James On Wednesday, May 31, 2023 at 02:50:33 PM PDT, Isaac Levin @.***> wrote:

Tracking presence for another user is not supported and will never be supported due to AAD App Registration consent things

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

isaacrlevin commented 1 year ago

so when you do a curl XXX, it is a get, you need to change the HTTP method for it to be a post. I know some folks that POST to HA using the CustomAPI for instance.

jescodev commented 1 year ago

You are right- I should have realized that the CURL XXX was a get!I saw it working, and was locked in on POST but it is a GET.Thanks again for straightening me out on this.I mostly do low level ASM/C microprocessors consumer devices. So REST is all new.-James

On Wednesday, May 31, 2023 at 03:21:58 PM PDT, Isaac Levin ***@***.***> wrote:  

so when you do a curl XXX, it is a get, you need to change the HTTP method for it to be a post. I know some folks that POST to HA using the CustomAPI for instance.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

isaacrlevin commented 1 year ago

No worries, going to close this issue