// server private IRemoteAcuriteData HttpSendAsync(Options options) { var http = new HttpAcuriteData(options.Port, options.Protocol, listenLocal: false); AcuriteData current = new AcuriteData(); // get the latest data OnPolled += (data) => { current = data; }; // serialize upon request http.OnSend += () => { // reset the stopwatch and restart LastNetQuery.Reset(); LastNetQuery.Start(); // serialize the most current data var json = System.Text.Json.JsonSerializer.Serialize <AcuriteData>(current); return(json); }; // start listening http.SendAsync(); return(http); }
// // Http // // client private async void HttpReceiveAsync(Options options) { var http = new HttpAcuriteData(options.Port, options.Protocol, listenLocal: true); try { while (true) { var payload = await http.ReceiveAsync(options.Hostname); var data = System.Text.Json.JsonSerializer.Deserialize <AcuriteData>(payload); Console.WriteLine($"{DateTime.Now:o}: Channel: {data.channel} SensorId: {data.sensorId} Signal: {data.signal} Battery: {data.lowBattery} WindSpeed: {data.windSpeed} WindDirection: {data.windDirection} RainTotal: {data.rainTotal} OutTemperature: {data.outTemperature} OutHumitiy: {data.outHumidity} Pressure: {data.pressure} InTemperature: {data.inTemperature}"); Console.WriteLine($"{payload}"); System.Threading.Thread.Sleep(options.Interval); } } finally { if (http != null) { http.Close(); } } }