michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
411 stars 114 forks source link

[Q42.HueApi] [Version=3.15.4.0] Could not create SSL/TLS secure channel while calling HueBridgeDiscovery::CompleteDiscoveryAsync #251

Closed HsiuWei closed 2 years ago

HsiuWei commented 3 years ago

Hi all,

I am using HueBridgeDiscovery::CompleteDiscoveryAsync to discover my HUE bridge. Minimum code is as follow:

public IEnumerable<LocatedBridge> ScanAvailableBridge()
        {
            Trace.WriteLine("Start scanning Hue bridges...");

            m_bridgeAvail.Clear();
            Task<IEnumerable<LocatedBridge>> bridges = null;
            m_status = HueStatus.SCANNING;
            int count = 0;

            try
            {
                //Run http, MDNS, SSDP, and Net Scans in parallel (API V3.15.4.0)
                bridges = ScanCompleteBridgeAsync();
                count = bridges.Result.Count();
            }
            catch (AggregateException e)
            {
                Trace.WriteLine("Scan abort. Due to " + e.Message + ".");

                foreach (var errInner in e.InnerExceptions)
                {
                    Trace.WriteLine("Scan abort. Due to " + errInner);
                }
            }
            GetAvalibleBridge(bridges.Result);
            return bridges.Result;
        }

private async Task<IEnumerable<LocatedBridge>> ScanCompleteBridgeAsync()
        {
            return await HueBridgeDiscovery.CompleteDiscoveryAsync(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(30));
        }

However, I recevied the following error message from my AggregateException e:

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel. at AuraHueService.HueController.d__31.MoveNext()

My question is about "Could not create SSL/TLS secure channel." Can someone please elaborate on this SSL/TLS secure channel issue? Thanks very much.

michielpost commented 3 years ago

I'm unable to reproduce this. It's probably caused by a device on your network. HueBridgeDiscovery scans your network and does a http request to devices to check if it is a Hue Bridge.

Maybe, during this http request, it throws the SSL error becauses the device does not have a valid SSL certificate.

The best option is to use the full source code of this project and debug your issue. If you can locate the problem, I'm happy to include a fix.