Beispiel #1
0
        public string GetStationAlpacaFormData()
        {
            // Build the settings data, convert to JSON, and return it
            var options = new JsonStationSettingsOptions()
            {
                usezerobearing         = cumulus.UseZeroBearing,
                calcwindaverage        = cumulus.UseWind10MinAve,
                usespeedforavg         = cumulus.UseSpeedForAvgCalc,
                use100for98hum         = cumulus.Humidity98Fix,
                calculatedewpoint      = cumulus.CalculatedDP,
                calculatewindchill     = cumulus.CalculatedWC,
                syncstationclock       = cumulus.SyncTime,
                cumuluspresstrendnames = cumulus.UseCumulusPresstrendstr,
                vp1minbarupdate        = cumulus.ForceVPBarUpdate,
                extrasensors           = cumulus.LogExtraSensors,
                ignorelacrosseclock    = cumulus.WS2300IgnoreStationClock,
                roundwindspeeds        = cumulus.RoundWindSpeed,
                synchroniseforeads     = cumulus.SyncFOReads,
                debuglogging           = cumulus.logging,
                datalogging            = cumulus.DataLogging,
                stopsecondinstance     = cumulus.WarnMultiple,
                readreceptionstats     = cumulus.DavisReadReceptionStats
            };

            var units = new JsonStationSettingsUnits()
            {
                wind     = cumulus.WindUnit,
                pressure = cumulus.PressUnit,
                temp     = cumulus.TempUnit,
                rain     = cumulus.RainUnit
            };

            var tcpsettings = new JsonStationSettingsTCPsettings()
            {
                ipaddress    = cumulus.VP2IPAddr,
                tcpport      = cumulus.VP2TCPPort,
                disconperiod = cumulus.VP2PeriodicDisconnectInterval
            };

            var davisconn = new JsonStationSettingsDavisConn()
            {
                conntype = cumulus.VP2ConnectionType, tcpsettings = tcpsettings
            };

            var gw1000 = new JSonStationSettingsGw1000Conn()
            {
                ipaddress = cumulus.Gw1000IpAddress, autoDiscover = cumulus.Gw1000AutoUpdateIpAddress
            };

            var logrollover = new JsonStationSettingsLogRollover()
            {
                time = "midnight", summer10am = cumulus.Use10amInSummer
            };

            if (cumulus.RolloverHour == 9)
            {
                logrollover.time = "9am";
            }

            int    deg, min, sec;
            string hem;

            LatToDMS(cumulus.Latitude, out deg, out min, out sec, out hem);

            var Latitude = new JsonStationSettingsLatLong()
            {
                degrees = deg, minutes = min, seconds = sec, hemisphere = hem
            };

            LongToDMS(cumulus.Longitude, out deg, out min, out sec, out hem);

            var Longitude = new JsonStationSettingsLatLong()
            {
                degrees = deg, minutes = min, seconds = sec, hemisphere = hem
            };

            var Location = new JsonStationSettingsLocation()
            {
                altitude     = (int)cumulus.Altitude,
                altitudeunit = "metres",
                description  = cumulus.LocationDesc,
                Latitude     = Latitude,
                Longitude    = Longitude,
                sitename     = cumulus.LocationName
            };

            if (cumulus.AltitudeInFeet)
            {
                Location.altitudeunit = "feet";
            }

            var forecast = new JsonStationSettingsForecast()
            {
                highpressureextreme = cumulus.FChighpress,
                lowpressureextreme  = cumulus.FClowpress,
                pressureunit        = "mb/hPa",
                updatehourly        = cumulus.HourlyForecast,
                usecumulusforecast  = cumulus.UseCumulusForecast
            };

            if (!cumulus.FCpressinMB)
            {
                forecast.pressureunit = "inHg";
            }

            var solar = new JsonStationSettingsSolar()
            {
                solarmin       = cumulus.SolarMinimum,
                transfactor    = cumulus.RStransfactor,
                sunthreshold   = cumulus.SunThreshold,
                useblakelarsen = cumulus.UseBlakeLarsen,
                solarcalc      = cumulus.SolarCalc,
                turbidity      = cumulus.BrasTurbidity
            };

            var annualrainfall = new JsonStationSettingsAnnualRainfall()
            {
                rainseasonstart = cumulus.RainSeasonStart, ytdamount = cumulus.YTDrain, ytdyear = cumulus.YTDrainyear
            };

            var graphs = new JsonStationSettingsGraphs()
            {
                graphdays         = cumulus.GraphDays,
                graphhours        = cumulus.GraphHours,
                graphTempVis      = cumulus.GraphOptions.TempVisible,
                graphInTempVis    = cumulus.GraphOptions.InTempVisible,
                graphHeatIndexVis = cumulus.GraphOptions.HIVisible,
                graphDewPointVis  = cumulus.GraphOptions.DPVisible,
                graphWindChillVis = cumulus.GraphOptions.WCVisible,
                graphAppTempVis   = cumulus.GraphOptions.AppTempVisible,
                graphFeelsLikeVis = cumulus.GraphOptions.FeelsLikeVisible,
                graphHumidexVis   = cumulus.GraphOptions.HumidexVisible,
                graphHumVis       = cumulus.GraphOptions.OutHumVisible,
                graphInHumVis     = cumulus.GraphOptions.InHumVisible,
                graphUvVis        = cumulus.GraphOptions.UVVisible
            };

            var wllNetwork = new JsonStationSettingsWLLNetwork()
            {
                autoDiscover = cumulus.WLLAutoUpdateIpAddress
            };

            var wllApi = new JsonStationSettingsWLLApi()
            {
                apiKey       = cumulus.WllApiKey,
                apiSecret    = cumulus.WllApiSecret,
                apiStationId = cumulus.WllStationId
            };

            var wllPrimary = new JsonStationSettingsWllPrimary()
            {
                wind    = cumulus.WllPrimaryWind,
                temphum = cumulus.WllPrimaryTempHum,
                rain    = cumulus.WllPrimaryRain,
                solar   = cumulus.WllPrimarySolar,
                uv      = cumulus.WllPrimaryUV
            };

            var wllExtraSoilTemp = new JsonStationSettingsWllSoilTemp()
            {
                soilTempTx1  = cumulus.WllExtraSoilTempTx1,
                soilTempIdx1 = cumulus.WllExtraSoilTempIdx1,
                soilTempTx2  = cumulus.WllExtraSoilTempTx2,
                soilTempIdx2 = cumulus.WllExtraSoilTempIdx2,
                soilTempTx3  = cumulus.WllExtraSoilTempTx3,
                soilTempIdx3 = cumulus.WllExtraSoilTempIdx3,
                soilTempTx4  = cumulus.WllExtraSoilTempTx4,
                soilTempIdx4 = cumulus.WllExtraSoilTempIdx4
            };

            var wllExtraSoilMoist = new JsonStationSettingsWllSoilMoist()
            {
                soilMoistTx1  = cumulus.WllExtraSoilMoistureTx1,
                soilMoistIdx1 = cumulus.WllExtraSoilMoistureIdx1,
                soilMoistTx2  = cumulus.WllExtraSoilMoistureTx2,
                soilMoistIdx2 = cumulus.WllExtraSoilMoistureIdx2,
                soilMoistTx3  = cumulus.WllExtraSoilMoistureTx3,
                soilMoistIdx3 = cumulus.WllExtraSoilMoistureIdx3,
                soilMoistTx4  = cumulus.WllExtraSoilMoistureTx4,
                soilMoistIdx4 = cumulus.WllExtraSoilMoistureIdx4
            };

            var wllExtraLeaf = new JsonStationSettingsWllExtraLeaf()
            {
                leafTx1  = cumulus.WllExtraLeafTx1,
                leafIdx1 = cumulus.WllExtraLeafIdx1,
                leafTx2  = cumulus.WllExtraLeafTx2,
                leafIdx2 = cumulus.WllExtraLeafIdx2
            };

            var wllSoilLeaf = new JsonStationSettingsWllSoilLeaf()
            {
                extraSoilTemp  = wllExtraSoilTemp,
                extraSoilMoist = wllExtraSoilMoist,
                extraLeaf      = wllExtraLeaf
            };

            var wllExtraTemp = new JsonStationSettingsWllExtraTemp();

            for (int i = 1; i <= 8; i++)
            {
                PropertyInfo propInfo = wllExtraTemp.GetType().GetProperty("extraTempTx" + i);
                propInfo.SetValue(wllExtraTemp, Convert.ChangeType(cumulus.WllExtraTempTx[i - 1], propInfo.PropertyType), null);

                propInfo = wllExtraTemp.GetType().GetProperty("extraHumTx" + i);
                propInfo.SetValue(wllExtraTemp, Convert.ChangeType(cumulus.WllExtraHumTx[i - 1], propInfo.PropertyType), null);
            }
            ;

            var wll = new JsonStationSettingsWLL()
            {
                network   = wllNetwork,
                api       = wllApi,
                primary   = wllPrimary,
                soilLeaf  = wllSoilLeaf,
                extraTemp = wllExtraTemp
            };

            var data = new JsonStationSettingsData()
            {
                stationtype    = cumulus.StationType,
                units          = units,
                davisconn      = davisconn,
                daviswll       = wll,
                gw1000         = gw1000,
                comportname    = cumulus.ComportName,
                loginterval    = cumulus.DataLogInterval,
                logrollover    = logrollover,
                Location       = Location,
                Options        = options,
                Forecast       = forecast,
                Solar          = solar,
                AnnualRainfall = annualrainfall,
                Graphs         = graphs
            };

            return(JsonConvert.SerializeObject(data));
        }
Beispiel #2
0
        public string GetAlpacaFormData()
        {
            var location = new JsonWizardLocation()
            {
                sitename     = cumulus.LocationName,
                description  = cumulus.LocationDesc,
                latitude     = cumulus.Latitude,
                longitude    = cumulus.Longitude,
                altitude     = (int)cumulus.Altitude,
                altitudeunit = cumulus.AltitudeInFeet ? "feet" : "metres",
            };

            var units = new JsonWizardUnits()
            {
                wind     = cumulus.Units.Wind,
                pressure = cumulus.Units.Press,
                temp     = cumulus.Units.Temp,
                rain     = cumulus.Units.Rain
            };

            var logs = new JsonWizardLogs()
            {
                loginterval = cumulus.DataLogInterval,
                logrollover = new JsonStationSettingsLogRollover()
                {
                    time       = cumulus.RolloverHour == 9 ? "9am" : "midnight",
                    summer10am = cumulus.Use10amInSummer
                }
            };

            var davisvp = new JsonWizardDavisVp()
            {
                conntype    = cumulus.DavisOptions.ConnectionType,
                comportname = cumulus.ComportName,
                tcpsettings = new JsonStationSettingsTCPsettings()
                {
                    ipaddress    = cumulus.DavisOptions.IPAddr,
                    disconperiod = cumulus.DavisOptions.PeriodicDisconnectInterval
                }
            };

            var daviswll = new JsonWizardDavisWll()
            {
                network = new JsonStationSettingsWLLNetwork()
                {
                    autoDiscover = cumulus.WLLAutoUpdateIpAddress,
                    ipaddress    = cumulus.DavisOptions.IPAddr
                },
                api = new JsonStationSettingsWLLApi()
                {
                    apiKey       = cumulus.WllApiKey,
                    apiSecret    = cumulus.WllApiSecret,
                    apiStationId = cumulus.WllStationId
                },
                primary = new JsonStationSettingsWllPrimary()
                {
                    wind    = cumulus.WllPrimaryWind,
                    temphum = cumulus.WllPrimaryTempHum,
                    rain    = cumulus.WllPrimaryRain,
                    solar   = cumulus.WllPrimarySolar,
                    uv      = cumulus.WllPrimaryUV
                }
            };

            var weatherflow = new JsonStationSettingsWeatherFlow()
            {
                deviceid = cumulus.WeatherFlowOptions.WFDeviceId, tcpport = cumulus.WeatherFlowOptions.WFTcpPort, token = cumulus.WeatherFlowOptions.WFToken, dayshistory = cumulus.WeatherFlowOptions.WFDaysHist
            };

            var gw1000 = new JSonStationSettingsGw1000Conn()
            {
                ipaddress    = cumulus.Gw1000IpAddress,
                autoDiscover = cumulus.Gw1000AutoUpdateIpAddress,
                macaddress   = cumulus.Gw1000MacAddress
            };

            var fineoffset = new JsonWizardFineOffset()
            {
                syncreads = cumulus.FineOffsetOptions.SyncReads,
                readavoid = cumulus.FineOffsetOptions.ReadAvoidPeriod
            };

            var easyweather = new JsonWizardEasyWeather()
            {
                interval = cumulus.EwOptions.Interval,
                filename = cumulus.EwOptions.Filename
            };

            var imet = new JsonWizardImet()
            {
                comportname = cumulus.ComportName,
                baudrate    = cumulus.ImetOptions.BaudRate
            };

            var wmr = new JsonStationSettingsWMR928()
            {
                comportname = cumulus.ComportName
            };


            var station = new JsonWizardStation()
            {
                stationtype  = cumulus.StationType,
                stationmodel = cumulus.StationModel,
                davisvp2     = davisvp,
                daviswll     = daviswll,
                gw1000       = gw1000,
                fineoffset   = fineoffset,
                easyw        = easyweather,
                imet         = imet,
                wmr928       = wmr,
                weatherflow  = weatherflow
            };

            var copy = new JsonWizardInternetCopy()
            {
                localcopy       = cumulus.FtpOptions.LocalCopyEnabled,
                localcopyfolder = cumulus.FtpOptions.LocalCopyFolder,
            };

            var ftp = new JsonWizardInternetFtp()
            {
                enabled   = cumulus.FtpOptions.Enabled,
                directory = cumulus.FtpOptions.Directory,
                ftpport   = cumulus.FtpOptions.Port,
                sslftp    = (int)cumulus.FtpOptions.FtpMode,
                hostname  = cumulus.FtpOptions.Hostname,
                password  = cumulus.FtpOptions.Password,
                username  = cumulus.FtpOptions.Username,
                sshAuth   = cumulus.FtpOptions.SshAuthen,
                pskFile   = cumulus.FtpOptions.SshPskFile
            };
            var internet = new JsonWizardInternet()
            {
                copy = copy,
                ftp  = ftp
            };

            var website = new JsonWizardWebSite()
            {
                interval = new JsonWizardWebInterval()
                {
                    enabled           = cumulus.WebIntervalEnabled,
                    enableintervalftp = cumulus.FtpOptions.IntervalEnabled,
                    ftpinterval       = cumulus.UpdateInterval
                },
                realtime = new JsonWizardWebRealtime()
                {
                    enabled           = cumulus.RealtimeIntervalEnabled,
                    enablerealtimeftp = cumulus.FtpOptions.RealtimeEnabled,
                    realtimeinterval  = cumulus.RealtimeInterval / 1000
                }
            };

            var settings = new JsonWizard()
            {
                location = location,
                units    = units,
                station  = station,
                logs     = logs,
                internet = internet,
                website  = website
            };

            return(JsonSerializer.SerializeToString(settings));
        }