Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get it to work #6

Open
toomasz opened this issue Oct 7, 2020 · 4 comments
Open

Cannot get it to work #6

toomasz opened this issue Oct 7, 2020 · 4 comments

Comments

@toomasz
Copy link

toomasz commented Oct 7, 2020

Hi, im not able to configure esp8266 with your library while it works with with https://www.nuget.org/packages/EspTouchSmartConfigXamarin/1.0.3

I'm on 2.4 Ghz network and i'm passig my phone wifi IP in LocalAddress

Any ideas?

private async Task<IPAddress> SmartConfigNew(string networkName, string bssid, string password, IPAddress ip)
        {
            var provider = new EspSmartConfigProvider();

            var ctx = provider.CreateContext();

            IPAddress ipAddress = null;
            ctx.DeviceDiscoveredEvent += (s, e) =>
            {
                ipAddress = e.Device.IPAddress;
            };
            var bssidStr = bssid.ToUpper().Replace(':', '-');
            var scArgs = new SmartConfigArguments
            {
                Ssid = networkName,
                Bssid = PhysicalAddress.Parse(bssidStr),
                Password = password,
                LocalAddress = ip
            };
            var argsStr = $"bssid: {scArgs.Bssid.ToString()} ip: {scArgs.LocalAddress}";
            try
            {            
                using (var job = new SmartConfigJob())
                {
                    job.Elapsed += Job_Elapsed;
                    await job.ExecuteAsync(ctx, scArgs, CancellationToken.None);
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex); 
            }
            return ipAddress;
        }
@oldrev
Copy link
Owner

oldrev commented Oct 12, 2020

Sorry for the inconvenience. I'll dig into it as soon as possible.

@willhuo
Copy link

willhuo commented Dec 2, 2020

Hi, im not able to configure esp8266 with your library while it works with with https://www.nuget.org/packages/EspTouchSmartConfigXamarin/1.0.3

I'm on 2.4 Ghz network and i'm passig my phone wifi IP in LocalAddress

Any ideas?

private async Task<IPAddress> SmartConfigNew(string networkName, string bssid, string password, IPAddress ip)
        {
            var provider = new EspSmartConfigProvider();

            var ctx = provider.CreateContext();

            IPAddress ipAddress = null;
            ctx.DeviceDiscoveredEvent += (s, e) =>
            {
                ipAddress = e.Device.IPAddress;
            };
            var bssidStr = bssid.ToUpper().Replace(':', '-');
            var scArgs = new SmartConfigArguments
            {
                Ssid = networkName,
                Bssid = PhysicalAddress.Parse(bssidStr),
                Password = password,
                LocalAddress = ip
            };
            var argsStr = $"bssid: {scArgs.Bssid.ToString()} ip: {scArgs.LocalAddress}";
            try
            {            
                using (var job = new SmartConfigJob())
                {
                    job.Elapsed += Job_Elapsed;
                    await job.ExecuteAsync(ctx, scArgs, CancellationToken.None);
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex); 
            }
            return ipAddress;
        }

it can work with a little modify.

class Program
{
    static CancellationTokenSource cts;

    static void Main(string[] args)
    {
        var provider = new EspSmartConfigProvider();
        SmartConfigContext sccontext = provider.CreateContext();
        sccontext.DeviceDiscoveredEvent += Ctx_DeviceDiscoveredEvent;
        SmartConfigArguments scArgs = new SmartConfigArguments()
        {
            Ssid = "qqbcxb",
            Bssid = PhysicalAddress.Parse("8C-78-D7-B6-11-D7"),
            Password = "qqb2187321",
            LocalAddress = IPAddress.Parse("192.168.0.119")
        };

        var job = new SmartConfigJob(TimeSpan.FromSeconds(20));
        job.Elapsed += Job_Elapsed;
        cts = new CancellationTokenSource();
        var flag = job.ExecuteAsync(sccontext, scArgs, cts.Token);
        flag.Wait();           
        Console.WriteLine("程序联网引导结束");
        Console.ReadLine();
    }

    private static void Ctx_DeviceDiscoveredEvent(object sender, DeviceDiscoveredEventArgs e)
    {
        Console.WriteLine($"Found device: IP={e.Device.IPAddress} MAC={e.Device.MacAddress},Port={e.Device.IPEndPoint.Port}");
        cts.Cancel();
    }

    private static void Job_Elapsed(object sender, SmartConfigTimerEventArgs e)
    {
        Console.WriteLine($"引导时长:{e.Timeout.TotalSeconds},当前耗时:{e.ExecutedTime.TotalSeconds}");
    }
}

@oldrev
Copy link
Owner

oldrev commented Dec 12, 2020

@toomasz Hello, there was a bug that caused the library to broadcast on a wrong network interface when you have more than one connection.

Please try the new 1.1.x version or just clone the source code and run the CliDemoApp. Thanks.

@toomasz
Copy link
Author

toomasz commented Dec 12, 2020

@oldrev Amazing, thanks for fixing! Will try it soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants