// See https://aka.ms/new-console-template for more information using Newtonsoft.Json; using Shelly; using Shelly.Clients; using Shelly.Options; using System.Diagnostics; Console.WriteLine("Start shelly test!"); //// caffè //var shellyAddr = "10.74.81.72"; //APC var shellyAddr = "10.74.81.71"; Shelly1PmOptions options = new Shelly1PmOptions() { DefaultTimeout = TimeSpan.FromSeconds(5), ServerUri = new Uri($"http://{shellyAddr}/rpc") }; var shelly = new Shelly1PmClient(new HttpClient(), options); Stopwatch sw = new Stopwatch(); while (true) { sw.Restart(); var response = await shelly.GetStatus(CancellationToken.None); sw.Stop(); try { Console.WriteLine($"Success: {response.IsSuccess}"); if (response.Value != null) { //Console.WriteLine($"Switch | Power: {response.Value.Switch.Power} | Current: {response.Value.Switch.Current} | Voltage: {response.Value.Switch.Voltage}"); //Console.WriteLine($"ActEnergy.Total: {response.Value.Switch.ActEnergy.Total}"); //Console.WriteLine($"Input: {response.Value.Input.Id} | state {response.Value.Input.State}"); //Console.WriteLine($"Cloud: {response.Value.ShellyCloud.Connected}"); //Console.WriteLine(); Console.WriteLine(JsonConvert.SerializeObject(response.Value, Formatting.Indented)); Console.WriteLine($"Elapsed: {sw.Elapsed.TotalMilliseconds:N3}ms"); Console.WriteLine(); } else { Console.WriteLine("Empty value!"); } } catch { } Thread.Sleep(TimeSpan.FromSeconds(1)); sw.Restart(); var respSwitch = await shelly.GetSwitchStatus(CancellationToken.None, 0); sw.Stop(); Console.WriteLine($"Success: {respSwitch.IsSuccess}"); Console.WriteLine(JsonConvert.SerializeObject(respSwitch.Value, Formatting.Indented)); Console.WriteLine($"Elapsed: {sw.Elapsed.TotalMilliseconds:N3}ms"); Console.WriteLine(); Thread.Sleep(TimeSpan.FromSeconds(3)); }