コード例 #1
0
ファイル: Program.cs プロジェクト: speedyjeff/tides
        //
        // Udp
        //

        // client
        private IRemoteAcuriteData UdpReceiveAsync(Options options)
        {
            // wait to receive data from the server
            var remote = new UdtAcuriteData(options.Port);

            remote.OnReceived += (payload) =>
            {
                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}");
            };
            remote.ReceiveAsync();
            return(remote);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: speedyjeff/tides
        // server
        private IRemoteAcuriteData UdpSendAsync(Options options)
        {
            // setup to send data via udp
            var remote = new UdtAcuriteData(options.Port);

            // subscribe to notifications when data is polled
            OnPolled += async(data) =>
            {
                // reset the stopwatch and restart
                LastNetQuery.Reset();
                LastNetQuery.Start();

                // serialize the most current data
                var json = System.Text.Json.JsonSerializer.Serialize <AcuriteData>(data);
                await remote.SendAsync(json);
            };

            return(remote);
        }