Esempio n. 1
0
        private static string SkyDoc(string address)
        {
            string       table;
            SkyEventArgs args = null;

            table  = "<tr><th colspan=\"5\">WeatherFlow Smart Weather Station Sky</th></tr>";
            table += "<tr><th>Value</th><th>Name</th><th>Custom Notification</th><th>Value</th><th>Notes</th></tr>";
            if (WeatherFlowNS.NS.NodeData.ContainsKey(address))
            {
                args   = (SkyEventArgs)WeatherFlowNS.NS.NodeData[address];
                table += TableRow("Last Update", address, "0", "", "Time in seconds since last update");
                table += TableRow("Illumination", address, "1", args.Illumination, "");
                table += TableRow("UV Index", address, "2", args.UV, "");
                table += TableRow("Solar Radiation", address, "3", args.SolarRadiation, "");
                table += TableRow("Wind Speed", address, "4", args.WindSpeed, "");
                table += TableRow("Gust Speed", address, "5", args.GustSpeed, "");
                table += TableRow("Wind Lull", address, "6", args.WindLull, "");
                table += TableRow("Wind Direction", address, "7", args.WindDirection, "");
                table += TableRow("Rain Rate", address, "8", args.RainRate, "");
                table += TableRow("Daily Rainfall", address, "9", args.Rain, "");
                table += TableRow("Battery", address, "10", args.Battery, "");
                table += TableRow("Rain Type", address, "11", args.PrecipitationType, "");
            }
            else
            {
                table += TableRow("Last Update", address, "0", "", "Time in seconds since last update");
                table += TableRow("Illumination", address, "1", "###", "");
                table += TableRow("UV Index", address, "2", "###", "");
                table += TableRow("Solar Radiation", address, "3", "###", "");
                table += TableRow("Wind Speed", address, "4", "###", "");
                table += TableRow("Gust Speed", address, "5", "###", "");
                table += TableRow("Wind Lull", address, "6", "###", "");
                table += TableRow("Wind Direction", address, "7", "###", "");
                table += TableRow("Rain Rate", address, "8", "###", "");
                table += TableRow("Daily Rainfall", address, "9", "###", "");
                table += TableRow("Battery", address, "10", "###", "");
                table += TableRow("Rain Type", address, "11", "###", "");
            }
            table += "<tr><th colspan=\"5\">&nbsp;</th></tr>";

            return(table);
        }
Esempio n. 2
0
        private void SkyObservations(string json)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            try {
                SkyObj       = serializer.Deserialize <SkyData>(json);
                SkyObj.valid = true;

                WFNodeServer.SkyEventArgs evnt = new SkyEventArgs(SkyObj);
                evnt.SetDaily = CalcDailyPrecipitation();
                evnt.Raw      = json;

                try {
                    WeatherFlowNS.NS.RaiseSkyEvent(this, evnt);
                } catch (Exception ex) {
                    WFLogging.Warning("Failed to process Sky event. " + ex.Message);
                }
                WeatherFlowNS.NS.RaiseUpdateEvent(this, new UpdateEventArgs((int)SkyObj.obs[0][0].GetValueOrDefault(), SkyObj.serial_number, DataType.SKY));
            } catch (Exception ex) {
                WFLogging.Error("Deserialization failed for sky data: " + ex.Message);
                WFLogging.Verbose(json);
                return;
            }
        }
Esempio n. 3
0
        internal void WSObservations(string json)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            ObsData obs;
            double  elevation = 0;

            try {
                try {
                    obs = serializer.Deserialize <ObsData>(json);
                } catch (Exception ex) {
                    WFLogging.Error("Deserialization failed for WebSocket data: " + ex.Message);
                    WFLogging.Error(json);
                    return;
                }
                if (json.Contains("obs_sky"))
                {
                    //SkyObj = new SkyData();
                    // The first websocket packet seems to be cached data and it
                    // doesn't include some things like the device serial number.
                    // Without the serial number, we can't really process it
                    if (obs.source == "cache")
                    {
                        return;
                    }
                    SkyObj.device_id         = obs.device_id;
                    SkyObj.firmware_revision = obs.firmware_revision;
                    SkyObj.hub_sn            = obs.hub_sn;
                    SkyObj.obs           = obs.obs;
                    SkyObj.serial_number = obs.serial_number;
                    SkyObj.type          = obs.type;
                    SkyObj.valid         = true;

                    WFNodeServer.SkyEventArgs evnt = new SkyEventArgs(SkyObj);
                    evnt.SetDaily = CalcDailyPrecipitation();
                    evnt.Raw      = json;

                    // This fails the first time, why?
                    WeatherFlowNS.NS.RaiseSkyEvent(this, evnt);
                    WeatherFlowNS.NS.RaiseUpdateEvent(this, new UpdateEventArgs((int)SkyObj.obs[0][0], SkyObj.serial_number, DataType.SKY));
                }
                else if (json.Contains("obs_air"))
                {
                    //AirObj = new AirData();
                    if (obs.source == "cache")
                    {
                        return;
                    }
                    AirObj.device_id         = obs.device_id;
                    AirObj.firmware_revision = obs.firmware_revision;
                    AirObj.hub_sn            = obs.hub_sn;
                    AirObj.obs           = obs.obs;
                    AirObj.serial_number = obs.serial_number;
                    AirObj.type          = obs.type;
                    AirObj.valid         = true;

                    // Look up elevation
                    StationInfo si = wf_station.FindStationAir(AirObj.serial_number);
                    if (si != null)
                    {
                        elevation = si.elevation;
                    }

                    AirEventArgs evnt = new AirEventArgs(AirObj);
                    evnt.SetDewpoint     = 0;
                    evnt.SetApparentTemp = 0;
                    evnt.SetTrend        = 1;
                    evnt.SetSeaLevel     = SeaLevelPressure(AirObj.obs[0][(int)AirIndex.PRESSURE].GetValueOrDefault(), elevation);
                    evnt.Raw             = json;
                    if (SkyObj.valid)
                    {
                        try {
                            evnt.SetDewpoint     = CalcDewPoint();
                            evnt.SetApparentTemp = FeelsLike(AirObj.obs[0][(int)AirIndex.TEMPURATURE].GetValueOrDefault(),
                                                             AirObj.obs[0][(int)AirIndex.HUMIDITY].GetValueOrDefault(),
                                                             SkyObj.obs[0][(int)SkyIndex.WIND_SPEED].GetValueOrDefault());
                            // Trend is -1, 0, 1 while event wants 0, 1, 2
                            evnt.SetTrend = PressureTrend() + 1;
                            // Heat index & Windchill ??
                        } catch {
                        }
                    }
                    else
                    {
                    }

                    WeatherFlowNS.NS.RaiseAirEvent(this, evnt);
                    WeatherFlowNS.NS.RaiseUpdateEvent(this, new UpdateEventArgs((int)AirObj.obs[0][0], AirObj.serial_number, DataType.AIR));
                }
            } catch (Exception ex) {
                WFLogging.Error("Failed to process websocket observation data: " + ex.Message);
                return;
            }
        }