コード例 #1
0
        //public string UpdateCalibrationConfig(HttpListenerContext context)
        public string UpdateCalibrationConfig(IHttpContext context)
        {
            try
            {
                var InvC = new CultureInfo("");
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                var json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                var settings = JsonConvert.DeserializeObject <JsonCalibrationSettingsData>(json);
                // process the settings
                cumulus.LogMessage("Updating calibration settings");

                // offsets
                cumulus.PressOffset   = Convert.ToDouble(settings.offsets.pressure, InvC);
                cumulus.TempOffset    = Convert.ToDouble(settings.offsets.temperature, InvC);
                cumulus.InTempoffset  = Convert.ToDouble(settings.offsets.indoortemp, InvC);
                cumulus.HumOffset     = settings.offsets.humidity;
                cumulus.WindDirOffset = settings.offsets.winddir;
                cumulus.UVOffset      = Convert.ToDouble(settings.offsets.uv, InvC);
                cumulus.WetBulbOffset = Convert.ToDouble(settings.offsets.wetbulb, InvC);

                // multipliers
                cumulus.WindSpeedMult = Convert.ToDouble(settings.multipliers.windspeed, InvC);
                cumulus.WindGustMult  = Convert.ToDouble(settings.multipliers.windgust, InvC);
                cumulus.TempMult      = Convert.ToDouble(settings.multipliers.outdoortemp, InvC);
                cumulus.HumMult       = Convert.ToDouble(settings.multipliers.humidity, InvC);
                cumulus.RainMult      = Convert.ToDouble(settings.multipliers.rainfall, InvC);
                cumulus.UVMult        = Convert.ToDouble(settings.multipliers.uv, InvC);
                cumulus.WetBulbMult   = Convert.ToDouble(settings.multipliers.wetbulb, InvC);

                // spike removal
                cumulus.EWtempdiff           = Convert.ToDouble(settings.spikeremoval.outdoortemp, InvC);
                cumulus.EWhumiditydiff       = Convert.ToDouble(settings.spikeremoval.humidity, InvC);
                cumulus.EWwinddiff           = Convert.ToDouble(settings.spikeremoval.windspeed, InvC);
                cumulus.EWgustdiff           = Convert.ToDouble(settings.spikeremoval.windgust, InvC);
                cumulus.EWmaxHourlyRain      = Convert.ToDouble(settings.spikeremoval.maxhourlyrain, InvC);
                cumulus.EWmaxRainRate        = Convert.ToDouble(settings.spikeremoval.maxrainrate, InvC);
                cumulus.EWpressurediff       = Convert.ToDouble(settings.spikeremoval.pressure, InvC);
                cumulus.ErrorLogSpikeRemoval = settings.spikeremoval.log;

                // Save the settings
                cumulus.WriteIniFile();

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                cumulus.LogMessage(ex.Message);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }
            return("success");
        }
コード例 #2
0
ファイル: ProgramSettings.cs プロジェクト: DerekK19/CumulusMX
        public string UpdateProgramConfig(IHttpContext context)
        {
            var errorMsg = "";

            context.Response.StatusCode = 200;
            // get the response
            try
            {
                cumulus.LogMessage("Updating program settings");

                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                var json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                var settings = JsonSerializer.DeserializeFromString <JsonProgramSettingsOptions>(json);

                // process the settings
                try
                {
                    cumulus.ProgramOptions.StartupPingHost       = settings.startuphostping;
                    cumulus.ProgramOptions.StartupPingEscapeTime = settings.startuppingescape;
                    cumulus.ProgramOptions.StartupDelaySecs      = settings.startupdelay;
                    cumulus.ProgramOptions.StartupDelayMaxUptime = settings.startupdelaymaxuptime;
                    cumulus.ProgramOptions.DebugLogging          = settings.debuglogging;
                    cumulus.ProgramOptions.DataLogging           = settings.datalogging;
                    cumulus.ProgramOptions.WarnMultiple          = settings.stopsecondinstance;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Program Options: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Save the settings
                cumulus.WriteIniFile();
            }
            catch (Exception ex)
            {
                cumulus.LogMessage(ex.Message);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }

            return(context.Response.StatusCode == 200 ? "success" : errorMsg);
        }
コード例 #3
0
        //public string UpdateStationConfig(HttpListenerContext context)
        public string UpdateStationConfig(IHttpContext context)
        {
            var ErrorMsg = "";

            context.Response.StatusCode = 200;
            // get the response
            try
            {
                cumulus.LogMessage("Updating station settings");

                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                var json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                var settings = JsonConvert.DeserializeObject <JsonStationSettingsData>(json);
                // process the settings

                // Graph Config
                try
                {
                    cumulus.GraphHours = settings.Graphs.graphhours;
                    cumulus.GraphDays  = settings.Graphs.graphdays;
                    cumulus.GraphOptions.TempVisible      = settings.Graphs.graphTempVis;
                    cumulus.GraphOptions.InTempVisible    = settings.Graphs.graphInTempVis;
                    cumulus.GraphOptions.HIVisible        = settings.Graphs.graphHeatIndexVis;
                    cumulus.GraphOptions.DPVisible        = settings.Graphs.graphDewPointVis;
                    cumulus.GraphOptions.WCVisible        = settings.Graphs.graphWindChillVis;
                    cumulus.GraphOptions.AppTempVisible   = settings.Graphs.graphAppTempVis;
                    cumulus.GraphOptions.FeelsLikeVisible = settings.Graphs.graphFeelsLikeVis;
                    cumulus.GraphOptions.HumidexVisible   = settings.Graphs.graphHumidexVis;
                    cumulus.GraphOptions.OutHumVisible    = settings.Graphs.graphHumVis;
                    cumulus.GraphOptions.InHumVisible     = settings.Graphs.graphInHumVis;
                    cumulus.GraphOptions.UVVisible        = settings.Graphs.graphUvVis;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Graph hours: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Annual Rainfall
                try
                {
                    cumulus.RainSeasonStart = settings.AnnualRainfall.rainseasonstart;
                    cumulus.YTDrain         = settings.AnnualRainfall.ytdamount;
                    cumulus.YTDrainyear     = settings.AnnualRainfall.ytdyear;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Rainfall settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Solar
                try
                {
                    cumulus.SolarMinimum   = settings.Solar.solarmin;
                    cumulus.RStransfactor  = settings.Solar.transfactor;
                    cumulus.SunThreshold   = settings.Solar.sunthreshold;
                    cumulus.UseBlakeLarsen = settings.Solar.useblakelarsen;
                    cumulus.SolarCalc      = settings.Solar.solarcalc;
                    cumulus.BrasTurbidity  = settings.Solar.turbidity;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Solar settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Forecast
                try
                {
                    cumulus.FChighpress        = settings.Forecast.highpressureextreme;
                    cumulus.FClowpress         = settings.Forecast.lowpressureextreme;
                    cumulus.HourlyForecast     = settings.Forecast.updatehourly;
                    cumulus.UseCumulusForecast = settings.Forecast.usecumulusforecast;
                    cumulus.FCpressinMB        = (settings.Forecast.pressureunit == "mb/hPa");
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Forecast settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Location
                try
                {
                    cumulus.Altitude       = settings.Location.altitude;
                    cumulus.AltitudeInFeet = (settings.Location.altitudeunit == "feet");
                    cumulus.LocationName   = settings.Location.sitename ?? string.Empty;
                    cumulus.LocationDesc   = settings.Location.description ?? string.Empty;

                    cumulus.Latitude = settings.Location.Latitude.degrees + (settings.Location.Latitude.minutes / 60.0) + (settings.Location.Latitude.seconds / 3600.0);
                    if (settings.Location.Latitude.hemisphere == "South")
                    {
                        cumulus.Latitude = -cumulus.Latitude;
                    }

                    cumulus.LatTxt = String.Format("{0}&nbsp;{1:D2}&deg;&nbsp;{2:D2}&#39;&nbsp;{3:D2}&quot;", settings.Location.Latitude.hemisphere[0], settings.Location.Latitude.degrees, settings.Location.Latitude.minutes,
                                                   settings.Location.Latitude.seconds);

                    cumulus.Longitude = settings.Location.Longitude.degrees + (settings.Location.Longitude.minutes / 60.0) + (settings.Location.Longitude.seconds / 3600.0);
                    if (settings.Location.Longitude.hemisphere == "West")
                    {
                        cumulus.Longitude = -cumulus.Longitude;
                    }

                    cumulus.LonTxt = String.Format("{0}&nbsp;{1:D2}&deg;&nbsp;{2:D2}&#39;&nbsp;{3:D2}&quot;", settings.Location.Longitude.hemisphere[0], settings.Location.Longitude.degrees, settings.Location.Longitude.minutes,
                                                   settings.Location.Longitude.seconds);
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Location settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Options
                try
                {
                    cumulus.UseZeroBearing           = settings.Options.usezerobearing;
                    cumulus.UseWind10MinAve          = settings.Options.calcwindaverage;
                    cumulus.UseSpeedForAvgCalc       = settings.Options.usespeedforavg;
                    cumulus.Humidity98Fix            = settings.Options.use100for98hum;
                    cumulus.CalculatedDP             = settings.Options.calculatedewpoint;
                    cumulus.CalculatedWC             = settings.Options.calculatewindchill;
                    cumulus.SyncTime                 = settings.Options.syncstationclock;
                    cumulus.UseCumulusPresstrendstr  = settings.Options.cumuluspresstrendnames;
                    cumulus.ForceVPBarUpdate         = settings.Options.vp1minbarupdate;
                    cumulus.LogExtraSensors          = settings.Options.extrasensors;
                    cumulus.WS2300IgnoreStationClock = settings.Options.ignorelacrosseclock;
                    cumulus.RoundWindSpeed           = settings.Options.roundwindspeeds;
                    cumulus.SyncFOReads              = settings.Options.synchroniseforeads;
                    cumulus.logging                 = settings.Options.debuglogging;
                    cumulus.DataLogging             = settings.Options.datalogging;
                    cumulus.WarnMultiple            = settings.Options.stopsecondinstance;
                    cumulus.DavisReadReceptionStats = settings.Options.readreceptionstats;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Options settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Log rollover
                try
                {
                    if (settings.logrollover.time == "9am")
                    {
                        cumulus.RolloverHour = 9;
                    }
                    else
                    {
                        cumulus.RolloverHour = 0;
                    }

                    cumulus.Use10amInSummer = settings.logrollover.summer10am;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Log rollover settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // WLL
                try
                {
                    cumulus.WLLAutoUpdateIpAddress = settings.daviswll.network.autoDiscover;
                    cumulus.WllApiKey    = settings.daviswll.api.apiKey;
                    cumulus.WllApiSecret = settings.daviswll.api.apiSecret;
                    cumulus.WllStationId = settings.daviswll.api.apiStationId == "-1" ? "" : settings.daviswll.api.apiStationId;

                    cumulus.WllPrimaryRain    = settings.daviswll.primary.rain;
                    cumulus.WllPrimarySolar   = settings.daviswll.primary.solar;
                    cumulus.WllPrimaryTempHum = settings.daviswll.primary.temphum;
                    cumulus.WllPrimaryUV      = settings.daviswll.primary.uv;
                    cumulus.WllPrimaryWind    = settings.daviswll.primary.wind;

                    cumulus.WllExtraLeafTx1  = settings.daviswll.soilLeaf.extraLeaf.leafTx1;
                    cumulus.WllExtraLeafTx2  = settings.daviswll.soilLeaf.extraLeaf.leafTx2;
                    cumulus.WllExtraLeafIdx1 = settings.daviswll.soilLeaf.extraLeaf.leafIdx1;
                    cumulus.WllExtraLeafIdx2 = settings.daviswll.soilLeaf.extraLeaf.leafIdx2;

                    cumulus.WllExtraSoilMoistureIdx1 = settings.daviswll.soilLeaf.extraSoilMoist.soilMoistIdx1;
                    cumulus.WllExtraSoilMoistureIdx2 = settings.daviswll.soilLeaf.extraSoilMoist.soilMoistIdx2;
                    cumulus.WllExtraSoilMoistureIdx3 = settings.daviswll.soilLeaf.extraSoilMoist.soilMoistIdx3;
                    cumulus.WllExtraSoilMoistureIdx4 = settings.daviswll.soilLeaf.extraSoilMoist.soilMoistIdx4;
                    cumulus.WllExtraSoilMoistureTx1  = settings.daviswll.soilLeaf.extraSoilMoist.soilMoistTx1;
                    cumulus.WllExtraSoilMoistureTx2  = settings.daviswll.soilLeaf.extraSoilMoist.soilMoistTx2;
                    cumulus.WllExtraSoilMoistureTx3  = settings.daviswll.soilLeaf.extraSoilMoist.soilMoistTx3;
                    cumulus.WllExtraSoilMoistureTx4  = settings.daviswll.soilLeaf.extraSoilMoist.soilMoistTx4;

                    cumulus.WllExtraSoilTempIdx1 = settings.daviswll.soilLeaf.extraSoilTemp.soilTempIdx1;
                    cumulus.WllExtraSoilTempIdx2 = settings.daviswll.soilLeaf.extraSoilTemp.soilTempIdx2;
                    cumulus.WllExtraSoilTempIdx3 = settings.daviswll.soilLeaf.extraSoilTemp.soilTempIdx3;
                    cumulus.WllExtraSoilTempIdx4 = settings.daviswll.soilLeaf.extraSoilTemp.soilTempIdx4;
                    cumulus.WllExtraSoilTempTx1  = settings.daviswll.soilLeaf.extraSoilTemp.soilTempTx1;
                    cumulus.WllExtraSoilTempTx2  = settings.daviswll.soilLeaf.extraSoilTemp.soilTempTx2;
                    cumulus.WllExtraSoilTempTx3  = settings.daviswll.soilLeaf.extraSoilTemp.soilTempTx3;
                    cumulus.WllExtraSoilTempTx4  = settings.daviswll.soilLeaf.extraSoilTemp.soilTempTx4;

                    cumulus.WllExtraTempTx[0] = settings.daviswll.extraTemp.extraTempTx1;
                    cumulus.WllExtraTempTx[1] = settings.daviswll.extraTemp.extraTempTx2;
                    cumulus.WllExtraTempTx[2] = settings.daviswll.extraTemp.extraTempTx3;
                    cumulus.WllExtraTempTx[3] = settings.daviswll.extraTemp.extraTempTx4;
                    cumulus.WllExtraTempTx[4] = settings.daviswll.extraTemp.extraTempTx5;
                    cumulus.WllExtraTempTx[5] = settings.daviswll.extraTemp.extraTempTx6;
                    cumulus.WllExtraTempTx[6] = settings.daviswll.extraTemp.extraTempTx7;
                    cumulus.WllExtraTempTx[7] = settings.daviswll.extraTemp.extraTempTx8;

                    cumulus.WllExtraHumTx[0] = settings.daviswll.extraTemp.extraHumTx1;
                    cumulus.WllExtraHumTx[1] = settings.daviswll.extraTemp.extraHumTx2;
                    cumulus.WllExtraHumTx[2] = settings.daviswll.extraTemp.extraHumTx3;
                    cumulus.WllExtraHumTx[3] = settings.daviswll.extraTemp.extraHumTx4;
                    cumulus.WllExtraHumTx[4] = settings.daviswll.extraTemp.extraHumTx5;
                    cumulus.WllExtraHumTx[5] = settings.daviswll.extraTemp.extraHumTx6;
                    cumulus.WllExtraHumTx[6] = settings.daviswll.extraTemp.extraHumTx7;
                    cumulus.WllExtraHumTx[7] = settings.daviswll.extraTemp.extraHumTx8;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing WLL settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // log interval
                try
                {
                    cumulus.DataLogInterval = settings.loginterval;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Log interval setting: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }


                // com port
                try
                {
                    cumulus.ComportName = settings.comportname ?? string.Empty;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing COM port setting: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Davis connection details
                try
                {
                    cumulus.VP2ConnectionType             = settings.davisconn.conntype;
                    cumulus.VP2IPAddr                     = settings.davisconn.tcpsettings.ipaddress ?? string.Empty;
                    cumulus.VP2TCPPort                    = settings.davisconn.tcpsettings.tcpport;
                    cumulus.VP2PeriodicDisconnectInterval = settings.davisconn.tcpsettings.disconperiod;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Davis settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // GW1000 connection details
                try
                {
                    cumulus.Gw1000IpAddress           = settings.gw1000.ipaddress;
                    cumulus.Gw1000AutoUpdateIpAddress = settings.gw1000.autoDiscover;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing GW1000 settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Units
                try
                {
                    cumulus.WindUnit  = settings.units.wind;
                    cumulus.PressUnit = settings.units.pressure;
                    cumulus.TempUnit  = settings.units.temp;
                    cumulus.RainUnit  = settings.units.rain;
                    cumulus.SetupUnitText();
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Units settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Station type
                try
                {
                    if (cumulus.StationType != settings.stationtype)
                    {
                        cumulus.LogMessage("Station type changed, restart required");
                        cumulus.LogConsoleMessage("*** Station type changed, restart required ***");
                    }
                    cumulus.StationType = settings.stationtype;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Station Type setting: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Save the settings
                cumulus.WriteIniFile();
            }
            catch (Exception ex)
            {
                cumulus.LogMessage(ex.Message);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }

            if (context.Response.StatusCode == 200)
            {
                return("success");
            }
            else
            {
                return(ErrorMsg);
            }
        }
コード例 #4
0
        public string UpdateConfig(IHttpContext context)
        {
            var        errorMsg = "";
            var        json     = "";
            JsonWizard settings;

            cumulus.LogMessage("Updating settings from the First Time Wizard");

            context.Response.StatusCode = 200;

            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                settings = json.FromJson <JsonWizard>();
            }
            catch (Exception ex)
            {
                var msg = "Error de-serializing Set-up Wizard Settings JSON: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("Wizard Data: " + json);
                context.Response.StatusCode = 500;
                return(msg);
            }

            // process the settings
            try
            {
                cumulus.LogMessage("Updating internet settings");

                // website settings
                try
                {
                    cumulus.FtpOptions.Enabled = settings.internet.ftp.enabled;
                    if (cumulus.FtpOptions.Enabled)
                    {
                        cumulus.FtpOptions.Directory  = settings.internet.ftp.directory ?? string.Empty;
                        cumulus.FtpOptions.Port       = settings.internet.ftp.ftpport;
                        cumulus.FtpOptions.Hostname   = settings.internet.ftp.hostname ?? string.Empty;
                        cumulus.FtpOptions.FtpMode    = (Cumulus.FtpProtocols)settings.internet.ftp.sslftp;
                        cumulus.FtpOptions.Password   = settings.internet.ftp.password ?? string.Empty;
                        cumulus.FtpOptions.Username   = settings.internet.ftp.username ?? string.Empty;
                        cumulus.FtpOptions.SshAuthen  = settings.internet.ftp.sshAuth ?? string.Empty;
                        cumulus.FtpOptions.SshPskFile = settings.internet.ftp.pskFile ?? string.Empty;
                    }

                    cumulus.FtpOptions.LocalCopyEnabled = settings.internet.copy.localcopy;
                    if (cumulus.FtpOptions.LocalCopyEnabled)
                    {
                        cumulus.FtpOptions.LocalCopyFolder = settings.internet.copy.localcopyfolder;
                    }

                    // Now flag all the standard files to FTP/Copy or not
                    // do not process last entry = wxnow.txt, it is not used by the standard site
                    for (var i = 0; i < cumulus.StdWebFiles.Length - 1; i++)
                    {
                        cumulus.StdWebFiles[i].Create = cumulus.FtpOptions.Enabled || cumulus.FtpOptions.LocalCopyEnabled;
                        cumulus.StdWebFiles[i].FTP    = cumulus.FtpOptions.Enabled;
                        cumulus.StdWebFiles[i].Copy   = cumulus.FtpOptions.LocalCopyEnabled;
                    }
                    // and graph data files
                    for (var i = 0; i < cumulus.GraphDataFiles.Length; i++)
                    {
                        cumulus.GraphDataFiles[i].Create = cumulus.FtpOptions.Enabled || cumulus.FtpOptions.LocalCopyEnabled;
                        cumulus.GraphDataFiles[i].FTP    = cumulus.FtpOptions.Enabled;
                        cumulus.GraphDataFiles[i].Copy   = cumulus.FtpOptions.LocalCopyEnabled;
                    }
                    // and EOD data files
                    for (var i = 0; i < cumulus.GraphDataEodFiles.Length; i++)
                    {
                        cumulus.GraphDataEodFiles[i].Create = cumulus.FtpOptions.Enabled || cumulus.FtpOptions.LocalCopyEnabled;
                        cumulus.GraphDataEodFiles[i].FTP    = cumulus.FtpOptions.Enabled;
                        cumulus.GraphDataEodFiles[i].Copy   = cumulus.FtpOptions.LocalCopyEnabled;
                    }
                    // and Realtime files

                    // realtime.txt is not used by the standard site
                    //cumulus.RealtimeFiles[0].Create = cumulus.FtpOptions.Enabled || cumulus.FtpOptions.LocalCopyEnabled;
                    //cumulus.RealtimeFiles[0].FTP = cumulus.FtpOptions.Enabled;
                    //cumulus.RealtimeFiles[0].Copy = cumulus.FtpOptions.LocalCopyEnabled;

                    // realtimegauges.txt IS used by the standard site
                    cumulus.RealtimeFiles[1].Create = cumulus.FtpOptions.Enabled || cumulus.FtpOptions.LocalCopyEnabled;
                    cumulus.RealtimeFiles[1].FTP    = cumulus.FtpOptions.Enabled;
                    cumulus.RealtimeFiles[1].Copy   = cumulus.FtpOptions.LocalCopyEnabled;

                    // and Moon image
                    cumulus.MoonImage.Enabled = cumulus.FtpOptions.Enabled || cumulus.FtpOptions.LocalCopyEnabled;
                    cumulus.MoonImage.Ftp     = cumulus.FtpOptions.Enabled;
                    cumulus.MoonImage.Copy    = cumulus.FtpOptions.LocalCopyEnabled;
                    if (cumulus.MoonImage.Enabled)
                    {
                        cumulus.MoonImage.CopyDest = cumulus.FtpOptions.LocalCopyFolder + "images" + cumulus.DirectorySeparator + "moon.png";
                    }

                    // and NOAA reports
                    cumulus.NOAAconf.Create   = cumulus.FtpOptions.Enabled || cumulus.FtpOptions.LocalCopyEnabled;
                    cumulus.NOAAconf.AutoFtp  = cumulus.FtpOptions.Enabled;
                    cumulus.NOAAconf.AutoCopy = cumulus.FtpOptions.LocalCopyEnabled;
                    if (cumulus.NOAAconf.AutoCopy)
                    {
                        cumulus.NOAAconf.CopyFolder = cumulus.FtpOptions.LocalCopyFolder + "Reports";
                    }
                    if (cumulus.NOAAconf.AutoFtp)
                    {
                        cumulus.NOAAconf.FtpFolder = cumulus.FtpOptions.Directory + (cumulus.FtpOptions.Directory.EndsWith("/") ? "" : "/") + "Reports";
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing internet settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // web settings
                try
                {
                    cumulus.RealtimeIntervalEnabled = settings.website.realtime.enabled;
                    if (cumulus.RealtimeIntervalEnabled)
                    {
                        cumulus.FtpOptions.RealtimeEnabled = settings.website.realtime.enablerealtimeftp;
                        cumulus.RealtimeInterval           = settings.website.realtime.realtimeinterval * 1000;
                        if (cumulus.RealtimeTimer.Interval != cumulus.RealtimeInterval)
                        {
                            cumulus.RealtimeTimer.Interval = cumulus.RealtimeInterval;
                        }
                    }
                    cumulus.RealtimeTimer.Enabled = cumulus.RealtimeIntervalEnabled;
                    if (!cumulus.RealtimeTimer.Enabled || !cumulus.FtpOptions.RealtimeEnabled)
                    {
                        cumulus.RealtimeTimer.Stop();
                        cumulus.RealtimeFTPDisconnect();
                    }

                    cumulus.WebIntervalEnabled = settings.website.interval.enabled;
                    if (cumulus.WebIntervalEnabled)
                    {
                        cumulus.FtpOptions.IntervalEnabled = settings.website.interval.enableintervalftp;
                        cumulus.UpdateInterval             = settings.website.interval.ftpinterval;
                        if (cumulus.WebTimer.Interval != cumulus.UpdateInterval * 60 * 1000)
                        {
                            cumulus.WebTimer.Interval = cumulus.UpdateInterval * 60 * 1000;
                        }
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing web settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Location
                try
                {
                    cumulus.Altitude       = settings.location.altitude;
                    cumulus.AltitudeInFeet = (settings.location.altitudeunit == "feet");
                    cumulus.LocationName   = settings.location.sitename ?? string.Empty;
                    cumulus.LocationDesc   = settings.location.description ?? string.Empty;

                    cumulus.Latitude = settings.location.latitude;

                    cumulus.LatTxt = degToString(cumulus.Latitude, true);

                    cumulus.Longitude = settings.location.longitude;

                    cumulus.LonTxt = degToString(cumulus.Longitude, false);
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Location settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Units
                try
                {
                    if (cumulus.Units.Wind != settings.units.wind)
                    {
                        cumulus.Units.Wind = settings.units.wind;
                        cumulus.ChangeWindUnits();
                        cumulus.WindDPlaces    = cumulus.StationOptions.RoundWindSpeed ? 0 : cumulus.WindDPlaceDefaults[cumulus.Units.Wind];
                        cumulus.WindAvgDPlaces = cumulus.WindDPlaces;
                    }
                    if (cumulus.Units.Press != settings.units.pressure)
                    {
                        cumulus.Units.Press = settings.units.pressure;
                        cumulus.ChangePressureUnits();
                        cumulus.PressDPlaces = cumulus.PressDPlaceDefaults[cumulus.Units.Press];
                    }
                    if (cumulus.Units.Temp != settings.units.temp)
                    {
                        cumulus.Units.Temp = settings.units.temp;
                        cumulus.ChangeTempUnits();
                    }
                    if (cumulus.Units.Rain != settings.units.rain)
                    {
                        cumulus.Units.Rain = settings.units.rain;
                        cumulus.ChangeRainUnits();
                        cumulus.RainDPlaces = cumulus.RainDPlaceDefaults[cumulus.Units.Rain];
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Units settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // data logging
                try
                {
                    cumulus.DataLogInterval = settings.logs.loginterval;
                    cumulus.RolloverHour    = settings.logs.logrollover.time == "9am" ? 9 : 0;
                    if (cumulus.RolloverHour == 9)
                    {
                        cumulus.Use10amInSummer = settings.logs.logrollover.summer10am;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Logging setting: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Station type
                try
                {
                    if (cumulus.StationType != settings.station.stationtype)
                    {
                        cumulus.LogMessage("Station type changed, restart required");
                        cumulus.LogConsoleMessage("*** Station type changed, restart required ***", ConsoleColor.Yellow);
                    }
                    cumulus.StationType  = settings.station.stationtype;
                    cumulus.StationModel = settings.station.stationmodel;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Station Type setting: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Davis VP/VP2/Vue
                try
                {
                    if (settings.station.davisvp2 != null)
                    {
                        cumulus.DavisOptions.ConnectionType = settings.station.davisvp2.conntype;
                        if (settings.station.davisvp2.tcpsettings != null)
                        {
                            cumulus.DavisOptions.IPAddr = settings.station.davisvp2.tcpsettings.ipaddress ?? string.Empty;
                            cumulus.DavisOptions.PeriodicDisconnectInterval = settings.station.davisvp2.tcpsettings.disconperiod;
                        }
                        if (cumulus.DavisOptions.ConnectionType == 0)
                        {
                            cumulus.ComportName = settings.station.davisvp2.comportname;
                        }

                        // set defaults for Davis
                        cumulus.UVdecimals = 1;

                        if (settings.units.rain == 1)
                        {
                            cumulus.RainDPlaces = 2;
                        }
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Davis VP/VP2/Vue settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // WLL
                try
                {
                    if (settings.station.daviswll != null)
                    {
                        cumulus.DavisOptions.ConnectionType = 2;                         // Always TCP/IP for WLL
                        cumulus.WLLAutoUpdateIpAddress      = settings.station.daviswll.network.autoDiscover;
                        cumulus.DavisOptions.IPAddr         = settings.station.daviswll.network.ipaddress ?? string.Empty;

                        cumulus.WllApiKey    = settings.station.daviswll.api.apiKey;
                        cumulus.WllApiSecret = settings.station.daviswll.api.apiSecret;
                        cumulus.WllStationId = settings.station.daviswll.api.apiStationId;

                        cumulus.WllPrimaryRain    = settings.station.daviswll.primary.rain;
                        cumulus.WllPrimarySolar   = settings.station.daviswll.primary.solar;
                        cumulus.WllPrimaryTempHum = settings.station.daviswll.primary.temphum;
                        cumulus.WllPrimaryUV      = settings.station.daviswll.primary.uv;
                        cumulus.WllPrimaryWind    = settings.station.daviswll.primary.wind;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing WLL settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // GW1000 connection details
                try
                {
                    if (settings.station.gw1000 != null)
                    {
                        cumulus.Gw1000IpAddress           = settings.station.gw1000.ipaddress;
                        cumulus.Gw1000AutoUpdateIpAddress = settings.station.gw1000.autoDiscover;
                        cumulus.Gw1000MacAddress          = settings.station.gw1000.macaddress;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing GW1000 settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // weatherflow connection details
                try
                {
                    if (settings.station.weatherflow != null)
                    {
                        cumulus.WeatherFlowOptions.WFDeviceId = settings.station.weatherflow.deviceid;
                        cumulus.WeatherFlowOptions.WFTcpPort  = settings.station.weatherflow.tcpport;
                        cumulus.WeatherFlowOptions.WFToken    = settings.station.weatherflow.token;
                        cumulus.WeatherFlowOptions.WFDaysHist = settings.station.weatherflow.dayshistory;
                    }
                }
                catch (Exception ex)
                {
                    var msg = $"Error processing WeatherFlow settings: {ex.Message}";
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // FineOffset
                try
                {
                    if (settings.station.fineoffset != null)
                    {
                        cumulus.FineOffsetOptions.SyncReads       = settings.station.fineoffset.syncreads;
                        cumulus.FineOffsetOptions.ReadAvoidPeriod = settings.station.fineoffset.readavoid;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Fine Offset settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // EasyWeather
                try
                {
                    if (settings.station.easyw != null)
                    {
                        cumulus.EwOptions.Interval = settings.station.easyw.interval;
                        cumulus.EwOptions.Filename = settings.station.easyw.filename;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing EasyWeather settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Instromet
                try
                {
                    if (settings.station.imet != null)
                    {
                        cumulus.ComportName          = settings.station.imet.comportname ?? cumulus.ComportName;
                        cumulus.ImetOptions.BaudRate = settings.station.imet.baudrate;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Instromet settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // WMR928
                try
                {
                    if (settings.station.wmr928 != null)
                    {
                        cumulus.ComportName = settings.station.wmr928.comportname ?? cumulus.ComportName;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing WMR928 settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Save the settings
                cumulus.WriteIniFile();
            }
            catch (Exception ex)
            {
                var msg = "Error processing Wizard settings: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("Station Data: " + json);
                errorMsg += msg;
                context.Response.StatusCode = 500;
            }

            return(context.Response.StatusCode == 200 ? "success" : errorMsg);
        }
コード例 #5
0
        public string UpdateConfig(IHttpContext context)
        {
            var errorMsg = "";
            var json     = "";
            JsonProgramSettings settings;

            context.Response.StatusCode = 200;

            // get the response
            try
            {
                cumulus.LogMessage("Updating Program settings");

                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                settings = JsonSerializer.DeserializeFromString <JsonProgramSettings>(json);
            }
            catch (Exception ex)
            {
                var msg = "Error de-serializing Program Settings JSON: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("Program Data: " + json);
                context.Response.StatusCode = 500;
                return(msg);
            }

            // process the settings
            try
            {
                cumulus.ProgramOptions.EnableAccessibility   = settings.accessible;
                cumulus.ProgramOptions.StartupPingHost       = settings.startup.startuphostping;
                cumulus.ProgramOptions.StartupPingEscapeTime = settings.startup.startuppingescape;
                cumulus.ProgramOptions.StartupDelaySecs      = settings.startup.startupdelay;
                cumulus.ProgramOptions.StartupDelayMaxUptime = settings.startup.startupdelaymaxuptime;

                cumulus.ProgramOptions.DataStoppedExit = settings.shutdown.datastoppedexit;
                cumulus.ProgramOptions.DataStoppedMins = settings.shutdown.datastoppedmins;

                cumulus.ProgramOptions.DebugLogging = settings.logging.debuglogging;
                cumulus.ProgramOptions.DataLogging  = settings.logging.datalogging;
                cumulus.SmtpOptions.Logging         = settings.logging.emaillogging;
                cumulus.ErrorLogSpikeRemoval        = settings.logging.spikelogging;

                cumulus.ProgramOptions.WarnMultiple = settings.options.stopsecondinstance;
                cumulus.ProgramOptions.ListWebTags  = settings.options.listwebtags;
                cumulus.ProgramOptions.Culture.RemoveSpaceFromDateSeparator = settings.culture.removespacefromdateseparator;

                if (cumulus.ProgramOptions.Culture.RemoveSpaceFromDateSeparator && CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator.Contains(" "))
                {
                    // get the existing culture
                    var newCulture = CultureInfo.CurrentCulture;
                    // change the date separator
                    newCulture.DateTimeFormat.DateSeparator = CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator.Replace(" ", "");
                    // set current thread culture
                    Thread.CurrentThread.CurrentCulture = newCulture;
                    // set the default culture for other threads
                    CultureInfo.DefaultThreadCurrentCulture = newCulture;
                }
                else
                {
                    var newCulture = CultureInfo.GetCultureInfo(CultureInfo.CurrentCulture.Name);

                    if (!cumulus.ProgramOptions.Culture.RemoveSpaceFromDateSeparator && newCulture.DateTimeFormat.DateSeparator.Contains(" ") && !CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator.Contains(" "))
                    {
                        // set current thread culture
                        Thread.CurrentThread.CurrentCulture = newCulture;
                        // set the default culture for other threads
                        CultureInfo.DefaultThreadCurrentCulture = newCulture;
                    }
                }

                if (settings.logging.ftplogging != cumulus.FtpOptions.Logging)
                {
                    cumulus.FtpOptions.Logging = settings.logging.ftplogging;
                    cumulus.SetFtpLogging(cumulus.FtpOptions.Logging);
                }
            }
            catch (Exception ex)
            {
                var msg = "Error processing Program Options: " + ex.Message;
                cumulus.LogMessage(msg);
                errorMsg += msg + "\n\n";
                context.Response.StatusCode = 500;
            }

            // Save the settings
            cumulus.WriteIniFile();

            return(context.Response.StatusCode == 200 ? "success" : errorMsg);
        }
コード例 #6
0
        public string UpdateConfig(IHttpContext context)
        {
            var errorMsg = "";
            var json     = "";
            JsonThirdPartySettings settings;

            context.Response.StatusCode = 200;

            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                settings = json.FromJson <JsonThirdPartySettings>();
            }
            catch (Exception ex)
            {
                var msg = "Error de-serializing 3rdParty Settings JSON: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("3rdParty Data: " + json);
                context.Response.StatusCode = 500;
                return(msg);
            }


            // process the settings
            try
            {
                cumulus.LogMessage("Updating third party settings");

                // wunderground
                try
                {
                    cumulus.Wund.Enabled = settings.wunderground.enabled;
                    if (cumulus.Wund.Enabled)
                    {
                        cumulus.Wund.SendIndoor         = settings.wunderground.includeindoor;
                        cumulus.Wund.SendSolar          = settings.wunderground.includesolar;
                        cumulus.Wund.SendUV             = settings.wunderground.includeuv;
                        cumulus.Wund.SendAirQuality     = settings.wunderground.includeaq;
                        cumulus.Wund.Interval           = settings.wunderground.interval;
                        cumulus.Wund.PW                 = settings.wunderground.password ?? string.Empty;
                        cumulus.Wund.RapidFireEnabled   = settings.wunderground.rapidfire;
                        cumulus.Wund.SendAverage        = settings.wunderground.sendavgwind;
                        cumulus.Wund.ID                 = settings.wunderground.stationid ?? string.Empty;
                        cumulus.Wund.CatchUp            = settings.wunderground.catchup;
                        cumulus.Wund.SynchronisedUpdate = (!cumulus.Wund.RapidFireEnabled) && (60 % cumulus.Wund.Interval == 0);

                        cumulus.WundTimer.Interval = cumulus.Wund.RapidFireEnabled ? 5000 : cumulus.Wund.Interval * 60 * 1000;
                        cumulus.WundTimer.Enabled  = cumulus.Wund.Enabled && !cumulus.Wund.SynchronisedUpdate && !string.IsNullOrWhiteSpace(cumulus.Wund.ID) && !string.IsNullOrWhiteSpace(cumulus.Wund.PW);
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing wunderground settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Windy
                try
                {
                    cumulus.Windy.Enabled = settings.windy.enabled;
                    if (cumulus.Windy.Enabled)
                    {
                        //cumulus.WindySendSolar = settings.windy.includesolar;
                        cumulus.Windy.SendUV     = settings.windy.includeuv;
                        cumulus.Windy.Interval   = settings.windy.interval;
                        cumulus.Windy.ApiKey     = settings.windy.apikey;
                        cumulus.Windy.StationIdx = settings.windy.stationidx;
                        cumulus.Windy.CatchUp    = settings.windy.catchup;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Windy settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Awekas
                try
                {
                    cumulus.AWEKAS.Enabled = settings.awekas.enabled;
                    if (cumulus.AWEKAS.Enabled)
                    {
                        cumulus.AWEKAS.Interval           = settings.awekas.interval;
                        cumulus.AWEKAS.Lang               = settings.awekas.lang;
                        cumulus.AWEKAS.PW                 = settings.awekas.password ?? string.Empty;
                        cumulus.AWEKAS.ID                 = settings.awekas.user ?? string.Empty;
                        cumulus.AWEKAS.SendSolar          = settings.awekas.includesolar;
                        cumulus.AWEKAS.SendUV             = settings.awekas.includeuv;
                        cumulus.AWEKAS.SendSoilTemp       = settings.awekas.includesoiltemp;
                        cumulus.AWEKAS.SendSoilMoisture   = settings.awekas.includesoilmoisture;
                        cumulus.AWEKAS.SendLeafWetness    = settings.awekas.includeleafwetness;
                        cumulus.AWEKAS.SendIndoor         = settings.awekas.includeindoor;
                        cumulus.AWEKAS.SendAirQuality     = settings.awekas.includeaq;
                        cumulus.AWEKAS.SynchronisedUpdate = (cumulus.AWEKAS.Interval % 60 == 0);

                        cumulus.AwekasTimer.Interval = cumulus.AWEKAS.Interval * 1000;
                        cumulus.AwekasTimer.Enabled  = cumulus.AWEKAS.Enabled && !cumulus.AWEKAS.SynchronisedUpdate && !string.IsNullOrWhiteSpace(cumulus.AWEKAS.ID) && !string.IsNullOrWhiteSpace(cumulus.AWEKAS.PW);
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing AWEKAS settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // WeatherCloud
                try
                {
                    cumulus.WCloud.Enabled = settings.weathercloud.enabled;
                    if (cumulus.WCloud.Enabled)
                    {
                        cumulus.WCloud.ID                 = settings.weathercloud.wid ?? string.Empty;
                        cumulus.WCloud.PW                 = settings.weathercloud.key ?? string.Empty;
                        cumulus.WCloud.Interval           = settings.weathercloud.interval;
                        cumulus.WCloud.SendSolar          = settings.weathercloud.includesolar;
                        cumulus.WCloud.SendUV             = settings.weathercloud.includeuv;
                        cumulus.WCloud.SendAirQuality     = settings.weathercloud.includeaqi;
                        cumulus.WCloud.SendSoilMoisture   = settings.weathercloud.includesoilmoist;
                        cumulus.WCloud.SoilMoistureSensor = settings.weathercloud.moistsensor;
                        cumulus.WCloud.SendLeafWetness    = settings.weathercloud.includeleafwet;
                        cumulus.WCloud.LeafWetnessSensor  = settings.weathercloud.leafwetsensor;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing WeatherCloud settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // PWS weather
                try
                {
                    cumulus.PWS.Enabled = settings.pwsweather.enabled;
                    if (cumulus.PWS.Enabled)
                    {
                        cumulus.PWS.Interval  = settings.pwsweather.interval;
                        cumulus.PWS.SendSolar = settings.pwsweather.includesolar;
                        cumulus.PWS.SendUV    = settings.pwsweather.includeuv;
                        cumulus.PWS.PW        = settings.pwsweather.password ?? string.Empty;
                        cumulus.PWS.ID        = settings.pwsweather.stationid ?? string.Empty;
                        cumulus.PWS.CatchUp   = settings.pwsweather.catchup;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing PWS weather settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // WOW
                try
                {
                    cumulus.WOW.Enabled = settings.wow.enabled;
                    if (cumulus.WOW.Enabled)
                    {
                        cumulus.WOW.SendSolar      = settings.wow.includesolar;
                        cumulus.WOW.SendUV         = settings.wow.includeuv;
                        cumulus.WOW.SendSoilTemp   = settings.wow.includesoiltemp;
                        cumulus.WOW.SoilTempSensor = settings.wow.soiltempsensor;
                        cumulus.WOW.Interval       = settings.wow.interval;
                        cumulus.WOW.PW             = settings.wow.password ?? string.Empty;
                        cumulus.WOW.ID             = settings.wow.stationid ?? string.Empty;
                        cumulus.WOW.CatchUp        = settings.wow.catchup;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing WOW settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // CWOP
                try
                {
                    cumulus.APRS.Enabled = settings.cwop.enabled;
                    if (cumulus.APRS.Enabled)
                    {
                        cumulus.APRS.ID        = settings.cwop.id ?? string.Empty;;
                        cumulus.APRS.Interval  = settings.cwop.interval;
                        cumulus.APRS.SendSolar = settings.cwop.includesolar;
                        cumulus.APRS.PW        = settings.cwop.password ?? string.Empty;;
                        cumulus.APRS.Port      = settings.cwop.port;
                        cumulus.APRS.Server    = settings.cwop.server ?? string.Empty;;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing CWOP settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // OpenWeatherMap
                try
                {
                    cumulus.OpenWeatherMap.Enabled = settings.openweathermap.enabled;
                    if (cumulus.OpenWeatherMap.Enabled)
                    {
                        cumulus.OpenWeatherMap.CatchUp  = settings.openweathermap.catchup;
                        cumulus.OpenWeatherMap.PW       = settings.openweathermap.apikey;
                        cumulus.OpenWeatherMap.ID       = settings.openweathermap.stationid;
                        cumulus.OpenWeatherMap.Interval = settings.openweathermap.interval;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing OpenWeatherMap settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Wind Guru
                try
                {
                    cumulus.WindGuru.Enabled = settings.windguru.enabled;
                    if (cumulus.WindGuru.Enabled)
                    {
                        cumulus.WindGuru.ID       = settings.windguru.uid;
                        cumulus.WindGuru.PW       = settings.windguru.password;
                        cumulus.WindGuru.SendRain = settings.windguru.includerain;
                        cumulus.WindGuru.Interval = settings.windguru.interval;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing WindGuru settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Custom HTTP
                try
                {
                    // custom seconds
                    cumulus.CustomHttpSecondsEnabled       = settings.customhttp.customseconds.enabled;
                    cumulus.CustomHttpSecondsTimer.Enabled = cumulus.CustomHttpSecondsEnabled;
                    if (cumulus.CustomHttpSecondsEnabled)
                    {
                        cumulus.CustomHttpSecondsStrings[0] = settings.customhttp.customseconds.url[0] ?? string.Empty;
                        for (var i = 1; i < 10; i++)
                        {
                            if (i < settings.customhttp.customseconds.url.Length)
                            {
                                cumulus.CustomHttpSecondsStrings[i] = settings.customhttp.customseconds.url[i] ?? null;
                            }
                            else
                            {
                                cumulus.CustomHttpSecondsStrings[i] = null;
                            }
                        }

                        cumulus.CustomHttpSecondsInterval       = settings.customhttp.customseconds.interval;
                        cumulus.CustomHttpSecondsTimer.Interval = cumulus.CustomHttpSecondsInterval * 1000;
                    }
                    // custom minutes
                    cumulus.CustomHttpMinutesEnabled = settings.customhttp.customminutes.enabled;
                    if (cumulus.CustomHttpMinutesEnabled)
                    {
                        cumulus.CustomHttpMinutesStrings[0] = settings.customhttp.customminutes.url[0] ?? string.Empty;
                        for (var i = 1; i < 10; i++)
                        {
                            if (i < settings.customhttp.customseconds.url.Length)
                            {
                                cumulus.CustomHttpMinutesStrings[i] = settings.customhttp.customminutes.url[i] ?? null;
                            }
                            else
                            {
                                cumulus.CustomHttpMinutesStrings[i] = null;
                            }
                        }

                        cumulus.CustomHttpMinutesIntervalIndex = settings.customhttp.customminutes.intervalindex;
                        if (cumulus.CustomHttpMinutesIntervalIndex >= 0 && cumulus.CustomHttpMinutesIntervalIndex < cumulus.FactorsOf60.Length)
                        {
                            cumulus.CustomHttpMinutesInterval = cumulus.FactorsOf60[cumulus.CustomHttpMinutesIntervalIndex];
                        }
                        else
                        {
                            cumulus.CustomHttpMinutesInterval = 10;
                        }
                    }
                    // custom roll-over
                    cumulus.CustomHttpRolloverEnabled = settings.customhttp.customrollover.enabled;
                    if (cumulus.CustomHttpRolloverEnabled)
                    {
                        cumulus.CustomHttpRolloverStrings[0] = settings.customhttp.customrollover.url[0] ?? string.Empty;
                        for (var i = 1; i < 10; i++)
                        {
                            if (i < settings.customhttp.customrollover.url.Length)
                            {
                                cumulus.CustomHttpMinutesStrings[i] = settings.customhttp.customrollover.url[i] ?? null;
                            }
                            else
                            {
                                cumulus.CustomHttpMinutesStrings[i] = null;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Custom settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Save the settings
                cumulus.WriteIniFile();

                // Do OpenWeatherMap set-up
                cumulus.EnableOpenWeatherMap();
            }
            catch (Exception ex)
            {
                var msg = "Error processing Third Party settings: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("Third Party data: " + json);
                errorMsg += msg;
                context.Response.StatusCode = 500;
            }

            return(context.Response.StatusCode == 200 ? "success" : errorMsg);
        }
コード例 #7
0
ファイル: MysqlSettings.cs プロジェクト: gdevic/CumulusMX
        //public object UpdateMysqlConfig(HttpListenerContext context)
        public object UpdateMysqlConfig(IHttpContext context)
        {
            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                var json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                var settings = json.FromJson <JsonMysqlSettings>();
                // process the settings
                cumulus.LogMessage("Updating MySQL settings");

                // server
                cumulus.MySqlHost = settings.server.host;
                if (settings.server.port > 0 && settings.server.port < 65536)
                {
                    cumulus.MySqlPort = settings.server.port;
                }
                else
                {
                    cumulus.MySqlPort = 3306;
                }
                cumulus.MySqlDatabase = settings.server.database;
                cumulus.MySqlUser     = settings.server.user;
                cumulus.MySqlPass     = settings.server.pass;
                //monthly
                cumulus.MonthlyMySqlEnabled = settings.monthly.enabled;
                cumulus.MySqlMonthlyTable   = String.IsNullOrWhiteSpace(settings.monthly.table) ? "Monthly" : settings.monthly.table;
                //realtime
                cumulus.RealtimeMySqlEnabled   = settings.realtime.enabled;
                cumulus.MySqlRealtimeRetention = settings.realtime.retention;
                cumulus.MySqlRealtimeTable     = String.IsNullOrWhiteSpace(settings.realtime.table) ? "Realtime" : settings.realtime.table;
                //dayfile
                cumulus.DayfileMySqlEnabled = settings.dayfile.enabled;
                cumulus.MySqlDayfileTable   = String.IsNullOrWhiteSpace(settings.dayfile.table) ? "Dayfile" : settings.dayfile.table;
                // custom seconds
                cumulus.CustomMySqlSecondsCommandString = settings.customseconds.command;
                cumulus.CustomMySqlSecondsEnabled       = settings.customseconds.enabled;
                cumulus.CustomMySqlSecondsInterval      = settings.customseconds.interval;
                // custom minutes
                cumulus.CustomMySqlMinutesCommandString = settings.customminutes.command;
                cumulus.CustomMySqlMinutesEnabled       = settings.customminutes.enabled;
                cumulus.CustomMySqlMinutesIntervalIndex = settings.customminutes.intervalindex;
                if (cumulus.CustomMySqlMinutesIntervalIndex >= 0 && cumulus.CustomMySqlMinutesIntervalIndex < cumulus.FactorsOf60.Length)
                {
                    cumulus.CustomMySqlMinutesInterval = cumulus.FactorsOf60[cumulus.CustomMySqlMinutesIntervalIndex];
                }
                else
                {
                    cumulus.CustomMySqlMinutesInterval = 10;
                }
                // custom rollover
                cumulus.CustomMySqlRolloverCommandString = settings.customrollover.command;
                cumulus.CustomMySqlRolloverEnabled       = settings.customrollover.enabled;

                // Save the settings
                cumulus.WriteIniFile();

                cumulus.MonthlyMySqlConn.Host     = cumulus.MySqlHost;
                cumulus.MonthlyMySqlConn.Port     = cumulus.MySqlPort;
                cumulus.MonthlyMySqlConn.UserId   = cumulus.MySqlUser;
                cumulus.MonthlyMySqlConn.Password = cumulus.MySqlPass;
                cumulus.MonthlyMySqlConn.Database = cumulus.MySqlDatabase;

                cumulus.SetMonthlySqlCreateString();
                cumulus.SetStartOfMonthlyInsertSQL();

                cumulus.SetDayfileSqlCreateString();
                cumulus.SetStartOfDayfileInsertSQL();

                cumulus.RealtimeSqlConn.Host     = cumulus.MySqlHost;
                cumulus.RealtimeSqlConn.Port     = cumulus.MySqlPort;
                cumulus.RealtimeSqlConn.UserId   = cumulus.MySqlUser;
                cumulus.RealtimeSqlConn.Password = cumulus.MySqlPass;
                cumulus.RealtimeSqlConn.Database = cumulus.MySqlDatabase;

                cumulus.SetRealtimeSqlCreateString();
                cumulus.SetStartOfRealtimeInsertSQL();

                cumulus.CustomMysqlSecondsConn.Host      = cumulus.MySqlHost;
                cumulus.CustomMysqlSecondsConn.Port      = cumulus.MySqlPort;
                cumulus.CustomMysqlSecondsConn.UserId    = cumulus.MySqlUser;
                cumulus.CustomMysqlSecondsConn.Password  = cumulus.MySqlPass;
                cumulus.CustomMysqlSecondsConn.Database  = cumulus.MySqlDatabase;
                cumulus.CustomMysqlSecondsTimer.Interval = cumulus.CustomMySqlSecondsInterval * 1000;
                cumulus.CustomMysqlSecondsTimer.Enabled  = cumulus.CustomMySqlSecondsEnabled;

                cumulus.CustomMysqlMinutesConn.Host     = cumulus.MySqlHost;
                cumulus.CustomMysqlMinutesConn.Port     = cumulus.MySqlPort;
                cumulus.CustomMysqlMinutesConn.UserId   = cumulus.MySqlUser;
                cumulus.CustomMysqlMinutesConn.Password = cumulus.MySqlPass;
                cumulus.CustomMysqlMinutesConn.Database = cumulus.MySqlDatabase;

                cumulus.CustomMysqlRolloverConn.Host     = cumulus.MySqlHost;
                cumulus.CustomMysqlRolloverConn.Port     = cumulus.MySqlPort;
                cumulus.CustomMysqlRolloverConn.UserId   = cumulus.MySqlUser;
                cumulus.CustomMysqlRolloverConn.Password = cumulus.MySqlPass;
                cumulus.CustomMysqlRolloverConn.Database = cumulus.MySqlDatabase;

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                cumulus.LogMessage(ex.Message);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }
            return("success");
        }
コード例 #8
0
        public string UpdateConfig(IHttpContext context)
        {
            var errorMsg = "";
            var json     = "";
            JsonExtraSensorSettings settings;

            context.Response.StatusCode = 200;

            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                settings = json.FromJson <JsonExtraSensorSettings>();
            }
            catch (Exception ex)
            {
                var msg = "Error de-serializing ExtraSensor Settings JSON: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("ExtraSensor Data: " + json);
                context.Response.StatusCode = 500;
                return(msg);
            }

            // process the settings
            try
            {
                cumulus.LogMessage("Updating extra sensor settings");

                // General settings
                try
                {
                    cumulus.StationOptions.PrimaryAqSensor = settings.airquality.primaryaqsensor;
                    cumulus.airQualityIndex = settings.airquality.aqi;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing General settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // AirLink settings
                try
                {
                    cumulus.AirLinkIsNode              = settings.airLink.isNode;
                    cumulus.AirLinkApiKey              = settings.airLink.apiKey;
                    cumulus.AirLinkApiSecret           = settings.airLink.apiSecret;
                    cumulus.AirLinkAutoUpdateIpAddress = settings.airLink.autoUpdateIp;

                    cumulus.AirLinkInEnabled = settings.airLink.indoor.enabled;
                    if (cumulus.AirLinkInEnabled)
                    {
                        cumulus.AirLinkInIPAddr    = settings.airLink.indoor.ipAddress;
                        cumulus.AirLinkInHostName  = settings.airLink.indoor.hostname;
                        cumulus.AirLinkInStationId = settings.airLink.indoor.stationId;
                        if (cumulus.AirLinkInStationId < 10 && cumulus.AirLinkIsNode)
                        {
                            cumulus.AirLinkInStationId = cumulus.WllStationId;
                        }
                    }
                    cumulus.AirLinkOutEnabled = settings.airLink.outdoor.enabled;
                    if (cumulus.AirLinkOutEnabled)
                    {
                        cumulus.AirLinkOutIPAddr    = settings.airLink.outdoor.ipAddress;
                        cumulus.AirLinkOutHostName  = settings.airLink.outdoor.hostname;
                        cumulus.AirLinkOutStationId = settings.airLink.outdoor.stationId;
                        if (cumulus.AirLinkOutStationId < 10 && cumulus.AirLinkIsNode)
                        {
                            cumulus.AirLinkOutStationId = cumulus.WllStationId;
                        }
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing AirLink settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Ecowitt Extra settings
                try
                {
                    if (settings.httpSensors.extraStation == 0)
                    {
                        cumulus.EcowittExtraEnabled    = true;
                        cumulus.EcowittExtraUseSolar   = settings.httpSensors.ecowitt.useSolar;
                        cumulus.EcowittExtraUseUv      = settings.httpSensors.ecowitt.useUv;
                        cumulus.EcowittExtraUseTempHum = settings.httpSensors.ecowitt.useTempHum;
                        //cumulus.EcowittExtraUseSoilTemp = settings.httpSensors.ecowitt.useSoilTemp;
                        cumulus.EcowittExtraUseSoilMoist = settings.httpSensors.ecowitt.useSoilMoist;
                        cumulus.EcowittExtraUseLeafWet   = settings.httpSensors.ecowitt.useLeafWet;
                        cumulus.EcowittExtraUseUserTemp  = settings.httpSensors.ecowitt.useUserTemp;
                        cumulus.EcowittExtraUseAQI       = settings.httpSensors.ecowitt.useAQI;
                        cumulus.EcowittExtraUseCo2       = settings.httpSensors.ecowitt.useCo2;
                        cumulus.EcowittExtraUseLightning = settings.httpSensors.ecowitt.useLightning;
                        cumulus.EcowittExtraUseLeak      = settings.httpSensors.ecowitt.useLeak;

                        cumulus.EcowittExtraSetCustomServer = settings.httpSensors.ecowitt.setcustom;
                        cumulus.EcowittExtraGatewayAddr     = settings.httpSensors.ecowitt.gwaddr;
                        cumulus.EcowittExtraLocalAddr       = settings.httpSensors.ecowitt.localaddr;
                        cumulus.EcowittExtraCustomInterval  = settings.httpSensors.ecowitt.interval;

                        cumulus.Gw1000PrimaryTHSensor = settings.httpSensors.ecowitt.mappings.primaryTHsensor;

                        if (cumulus.EcowittMapWN34[1] != settings.httpSensors.ecowitt.mappings.wn34chan1)
                        {
                            if (cumulus.EcowittMapWN34[1] == 0)
                            {
                                station.UserTemp[1] = 0;
                            }
                            else
                            {
                                station.SoilTemp[cumulus.EcowittMapWN34[1]] = 0;
                            }

                            cumulus.EcowittMapWN34[1] = settings.httpSensors.ecowitt.mappings.wn34chan1;
                        }

                        if (cumulus.EcowittMapWN34[2] != settings.httpSensors.ecowitt.mappings.wn34chan2)
                        {
                            if (cumulus.EcowittMapWN34[2] == 0)
                            {
                                station.UserTemp[2] = 0;
                            }
                            else
                            {
                                station.SoilTemp[cumulus.EcowittMapWN34[2]] = 0;
                            }

                            cumulus.EcowittMapWN34[2] = settings.httpSensors.ecowitt.mappings.wn34chan2;
                        }

                        if (cumulus.EcowittMapWN34[3] != settings.httpSensors.ecowitt.mappings.wn34chan3)
                        {
                            if (cumulus.EcowittMapWN34[3] == 0)
                            {
                                station.UserTemp[3] = 0;
                            }
                            else
                            {
                                station.SoilTemp[cumulus.EcowittMapWN34[3]] = 0;
                            }

                            cumulus.EcowittMapWN34[3] = settings.httpSensors.ecowitt.mappings.wn34chan3;
                        }

                        if (cumulus.EcowittMapWN34[4] != settings.httpSensors.ecowitt.mappings.wn34chan4)
                        {
                            if (cumulus.EcowittMapWN34[4] == 0)
                            {
                                station.UserTemp[4] = 0;
                            }
                            else
                            {
                                station.SoilTemp[cumulus.EcowittMapWN34[4]] = 0;
                            }

                            cumulus.EcowittMapWN34[4] = settings.httpSensors.ecowitt.mappings.wn34chan4;
                        }

                        if (cumulus.EcowittMapWN34[5] != settings.httpSensors.ecowitt.mappings.wn34chan5)
                        {
                            if (cumulus.EcowittMapWN34[5] == 0)
                            {
                                station.UserTemp[5] = 0;
                            }
                            else
                            {
                                station.SoilTemp[cumulus.EcowittMapWN34[5]] = 0;
                            }

                            cumulus.EcowittMapWN34[5] = settings.httpSensors.ecowitt.mappings.wn34chan5;
                        }

                        if (cumulus.EcowittMapWN34[6] != settings.httpSensors.ecowitt.mappings.wn34chan6)
                        {
                            if (cumulus.EcowittMapWN34[6] == 0)
                            {
                                station.UserTemp[6] = 0;
                            }
                            else
                            {
                                station.SoilTemp[cumulus.EcowittMapWN34[6]] = 0;
                            }

                            cumulus.EcowittMapWN34[6] = settings.httpSensors.ecowitt.mappings.wn34chan6;
                        }

                        if (cumulus.EcowittMapWN34[7] != settings.httpSensors.ecowitt.mappings.wn34chan7)
                        {
                            if (cumulus.EcowittMapWN34[7] == 0)
                            {
                                station.UserTemp[7] = 0;
                            }
                            else
                            {
                                station.SoilTemp[cumulus.EcowittMapWN34[7]] = 0;
                            }

                            cumulus.EcowittMapWN34[7] = settings.httpSensors.ecowitt.mappings.wn34chan7;
                        }

                        if (cumulus.EcowittMapWN34[8] != settings.httpSensors.ecowitt.mappings.wn34chan8)
                        {
                            if (cumulus.EcowittMapWN34[8] == 0)
                            {
                                station.UserTemp[8] = 0;
                            }
                            else
                            {
                                station.SoilTemp[cumulus.EcowittMapWN34[8]] = 0;
                            }

                            cumulus.EcowittMapWN34[8] = settings.httpSensors.ecowitt.mappings.wn34chan8;
                        }

                        // Also enable extra logging if applicable
                        if (cumulus.EcowittExtraUseTempHum || cumulus.EcowittExtraUseSoilTemp || cumulus.EcowittExtraUseSoilMoist || cumulus.EcowittExtraUseLeafWet || cumulus.EcowittExtraUseUserTemp || cumulus.EcowittExtraUseAQI || cumulus.EcowittExtraUseCo2)
                        {
                            cumulus.StationOptions.LogExtraSensors = true;
                        }
                    }
                    else
                    {
                        cumulus.EcowittExtraEnabled = false;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Ecowitt settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Ambient Extra settings
                try
                {
                    if (settings.httpSensors.extraStation == 1)
                    {
                        cumulus.AmbientExtraEnabled    = true;
                        cumulus.AmbientExtraUseSolar   = settings.httpSensors.ambient.useSolar;
                        cumulus.AmbientExtraUseUv      = settings.httpSensors.ambient.useUv;
                        cumulus.AmbientExtraUseTempHum = settings.httpSensors.ambient.useTempHum;
                        //cumulus.AmbientExtraUseSoilTemp = settings.httpSensors.ambient.useSoilTemp;
                        cumulus.AmbientExtraUseSoilMoist = settings.httpSensors.ambient.useSoilMoist;
                        //cumulus.AmbientExtraUseLeafWet = settings.httpSensors.ambient.useLeafWet;
                        cumulus.AmbientExtraUseAQI       = settings.httpSensors.ambient.useAQI;
                        cumulus.AmbientExtraUseCo2       = settings.httpSensors.ambient.useCo2;
                        cumulus.AmbientExtraUseLightning = settings.httpSensors.ambient.useLightning;
                        cumulus.AmbientExtraUseLeak      = settings.httpSensors.ambient.useLeak;

                        // Also enable extra logging if applicable
                        if (cumulus.AmbientExtraUseTempHum || cumulus.AmbientExtraUseSoilTemp || cumulus.AmbientExtraUseSoilMoist || cumulus.AmbientExtraUseAQI || cumulus.AmbientExtraUseCo2)
                        {
                            cumulus.StationOptions.LogExtraSensors = true;
                        }
                    }
                    else
                    {
                        cumulus.AmbientExtraEnabled = false;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Ambient settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Blake-Larsen settings
                try
                {
                    cumulus.SolarOptions.UseBlakeLarsen = settings.blakeLarsen.enabled;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Blake-Larsen settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // RG-11 settings
                try
                {
                    cumulus.RG11Enabled = settings.rg11.port1.enabled;
                    if (cumulus.RG11Enabled)
                    {
                        cumulus.RG11Port        = settings.rg11.port1.commPort;
                        cumulus.RG11TBRmode     = settings.rg11.port1.tipMode;
                        cumulus.RG11tipsize     = settings.rg11.port1.tipSize;
                        cumulus.RG11IgnoreFirst = settings.rg11.port1.ignoreFirst;
                        cumulus.RG11DTRmode     = settings.rg11.port1.dtrMode;
                    }

                    cumulus.RG11Enabled2 = settings.rg11.port2.enabled;
                    if (cumulus.RG11Enabled2)
                    {
                        cumulus.RG11Port2        = settings.rg11.port2.commPort;
                        cumulus.RG11TBRmode2     = settings.rg11.port2.tipMode;
                        cumulus.RG11tipsize2     = settings.rg11.port2.tipSize;
                        cumulus.RG11IgnoreFirst2 = settings.rg11.port2.ignoreFirst;
                        cumulus.RG11DTRmode2     = settings.rg11.port2.dtrMode;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing RG-11 settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Save the settings
                cumulus.WriteIniFile();
            }
            catch (Exception ex)
            {
                var msg = "Error processing Extra Sensor settings: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("Extra Sensor Data: " + json);
                errorMsg += msg;
                context.Response.StatusCode = 500;
            }

            return(context.Response.StatusCode == 200 ? "success" : errorMsg);
        }
コード例 #9
0
        //public string UpdateCalibrationConfig(HttpListenerContext context)
        public string UpdateCalibrationConfig(IHttpContext context)
        {
            try
            {
                var invC = new CultureInfo("");
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                var json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                var settings = json.FromJson <JsonCalibrationSettingsData>();
                // process the settings
                cumulus.LogMessage("Updating calibration settings");

                // offsets
                cumulus.Calib.Press.Offset   = Convert.ToDouble(settings.offsets.pressure, invC);
                cumulus.Calib.Temp.Offset    = Convert.ToDouble(settings.offsets.temperature, invC);
                cumulus.Calib.InTemp.Offset  = Convert.ToDouble(settings.offsets.indoortemp, invC);
                cumulus.Calib.Hum.Offset     = settings.offsets.humidity;
                cumulus.Calib.WindDir.Offset = settings.offsets.winddir;
                cumulus.Calib.Solar.Offset   = Convert.ToDouble(settings.offsets.solar);
                cumulus.Calib.UV.Offset      = Convert.ToDouble(settings.offsets.uv, invC);
                cumulus.Calib.WetBulb.Offset = Convert.ToDouble(settings.offsets.wetbulb, invC);

                // multipliers
                cumulus.Calib.Press.Mult     = Convert.ToDouble(settings.multipliers.pressure, invC);
                cumulus.Calib.WindSpeed.Mult = Convert.ToDouble(settings.multipliers.windspeed, invC);
                cumulus.Calib.WindGust.Mult  = Convert.ToDouble(settings.multipliers.windgust, invC);
                cumulus.Calib.Temp.Mult      = Convert.ToDouble(settings.multipliers.outdoortemp, invC);
                cumulus.Calib.Temp.Mult2     = Convert.ToDouble(settings.multipliers.outdoortemp2, invC);
                cumulus.Calib.Hum.Mult       = Convert.ToDouble(settings.multipliers.humidity, invC);
                cumulus.Calib.Hum.Mult2      = Convert.ToDouble(settings.multipliers.humidity2, invC);
                cumulus.Calib.Rain.Mult      = Convert.ToDouble(settings.multipliers.rainfall, invC);
                cumulus.Calib.Solar.Mult     = Convert.ToDouble(settings.multipliers.solar, invC);
                cumulus.Calib.UV.Mult        = Convert.ToDouble(settings.multipliers.uv, invC);
                cumulus.Calib.WetBulb.Mult   = Convert.ToDouble(settings.multipliers.wetbulb, invC);

                // spike removal
                cumulus.Spike.TempDiff      = Convert.ToDouble(settings.spikeremoval.outdoortemp, invC);
                cumulus.Spike.HumidityDiff  = Convert.ToDouble(settings.spikeremoval.humidity, invC);
                cumulus.Spike.WindDiff      = Convert.ToDouble(settings.spikeremoval.windspeed, invC);
                cumulus.Spike.GustDiff      = Convert.ToDouble(settings.spikeremoval.windgust, invC);
                cumulus.Spike.MaxHourlyRain = Convert.ToDouble(settings.spikeremoval.maxhourlyrain, invC);
                cumulus.Spike.MaxRainRate   = Convert.ToDouble(settings.spikeremoval.maxrainrate, invC);
                cumulus.Spike.PressDiff     = Convert.ToDouble(settings.spikeremoval.pressure, invC);

                // limits
                cumulus.Limit.TempHigh  = Convert.ToDouble(settings.limits.temphigh, invC);
                cumulus.Limit.TempLow   = Convert.ToDouble(settings.limits.templow, invC);
                cumulus.Limit.DewHigh   = Convert.ToDouble(settings.limits.dewhigh, invC);
                cumulus.Limit.PressHigh = Convert.ToDouble(settings.limits.presshigh, invC);
                cumulus.Limit.PressLow  = Convert.ToDouble(settings.limits.presslow, invC);
                cumulus.Limit.WindHigh  = Convert.ToDouble(settings.limits.windhigh, invC);

                cumulus.ErrorLogSpikeRemoval = settings.log;

                // Save the settings
                cumulus.WriteIniFile();

                // Clear the spike alarm
                cumulus.SpikeAlarm.Triggered = false;

                // Log the new values
                cumulus.LogMessage("Setting new calibration values...");
                cumulus.LogOffsetsMultipliers();

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                cumulus.LogMessage(ex.Message);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }
            return("success");
        }
コード例 #10
0
        //public string UpdateNoaaConfig(HttpListenerContext context)
        public string UpdateAlarmSettings(IHttpContext context)
        {
            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                var json = WebUtility.UrlDecode(data);

                // de-serialize it to the settings structure
                var settings = JsonConvert.DeserializeObject <JsonAlarmSettingsData>(json);
                // process the settings
                cumulus.LogMessage("Updating Alarm settings");
                var InvC = new CultureInfo("");

                cumulus.LowTempAlarmEnabled   = settings.tempBelowEnabled;
                cumulus.LowTempAlarmValue     = settings.tempBelowVal;
                cumulus.LowTempAlarmSound     = settings.tempBelowSoundEnabled;
                cumulus.LowTempAlarmSoundFile = settings.tempBelowSound;

                cumulus.HighTempAlarmEnabled   = settings.tempAboveEnabled;
                cumulus.HighTempAlarmValue     = settings.tempAboveVal;
                cumulus.HighTempAlarmSound     = settings.tempAboveSoundEnabled;
                cumulus.HighTempAlarmSoundFile = settings.tempAboveSound;

                cumulus.TempChangeAlarmEnabled   = settings.tempChangeEnabled;
                cumulus.TempChangeAlarmValue     = settings.tempChangeVal;
                cumulus.TempChangeAlarmSound     = settings.tempChangeSoundEnabled;
                cumulus.TempChangeAlarmSoundFile = settings.tempChangeSound;

                cumulus.LowPressAlarmEnabled   = settings.pressBelowEnabled;
                cumulus.LowPressAlarmValue     = settings.pressBelowVal;
                cumulus.LowPressAlarmSound     = settings.pressBelowSoundEnabled;
                cumulus.LowPressAlarmSoundFile = settings.pressBelowSound;

                cumulus.HighPressAlarmEnabled   = settings.pressAboveEnabled;
                cumulus.HighPressAlarmValue     = settings.pressAboveVal;
                cumulus.HighPressAlarmSound     = settings.pressAboveSoundEnabled;
                cumulus.HighPressAlarmSoundFile = settings.pressAboveSound;

                cumulus.PressChangeAlarmEnabled   = settings.pressChangeEnabled;
                cumulus.PressChangeAlarmValue     = settings.pressChangeVal;
                cumulus.PressChangeAlarmSound     = settings.pressChangeSoundEnabled;
                cumulus.PressChangeAlarmSoundFile = settings.pressChangeSound;

                cumulus.HighRainTodayAlarmEnabled   = settings.rainAboveEnabled;
                cumulus.HighRainTodayAlarmValue     = settings.rainAboveVal;
                cumulus.HighRainTodayAlarmSound     = settings.rainAboveSoundEnabled;
                cumulus.HighRainTodayAlarmSoundFile = settings.rainAboveSound;

                cumulus.HighRainRateAlarmEnabled   = settings.rainRateAboveEnabled;
                cumulus.HighRainRateAlarmValue     = settings.rainRateAboveVal;
                cumulus.HighRainRateAlarmSound     = settings.rainRateAboveSoundEnabled;
                cumulus.HighRainRateAlarmSoundFile = settings.rainRateAboveSound;

                cumulus.HighGustAlarmEnabled   = settings.gustAboveEnabled;
                cumulus.HighGustAlarmValue     = settings.gustAboveVal;
                cumulus.HighGustAlarmSound     = settings.gustAboveSoundEnabled;
                cumulus.HighGustAlarmSoundFile = settings.gustAboveSound;

                cumulus.HighWindAlarmEnabled   = settings.windAboveEnabled;
                cumulus.HighWindAlarmValue     = settings.windAboveVal;
                cumulus.HighWindAlarmSound     = settings.windAboveSoundEnabled;
                cumulus.HighWindAlarmSoundFile = settings.windAboveSound;

                cumulus.SensorAlarmEnabled   = settings.contactLostEnabled;
                cumulus.SensorAlarmSound     = settings.contactLostSoundEnabled;
                cumulus.SensorAlarmSoundFile = settings.contactLostSound;

                cumulus.DataStoppedAlarmEnabled   = settings.dataStoppedEnabled;
                cumulus.DataStoppedAlarmSound     = settings.dataStoppedSoundEnabled;
                cumulus.DataStoppedAlarmSoundFile = settings.dataStoppedSound;

                cumulus.BatteryLowAlarmEnabled   = settings.batteryLowEnabled;
                cumulus.BatteryLowAlarmSound     = settings.batteryLowSoundEnabled;
                cumulus.BatteryLowAlarmSoundFile = settings.batteryLowSound;

                cumulus.SpikeAlarmEnabled   = settings.spikeEnabled;
                cumulus.SpikeAlarmSound     = settings.spikeSoundEnabled;
                cumulus.SpikeAlarmSoundFile = settings.spikeSound;

                // Save the settings
                cumulus.WriteIniFile();

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                cumulus.LogMessage(ex.Message);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }
            return("success");
        }
コード例 #11
0
        //public string UpdateNoaaConfig(HttpListenerContext context)
        public string UpdateConfig(IHttpContext context)
        {
            var json = "";
            JsonNOAASettingsData settings;

            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                settings = json.FromJson <JsonNOAASettingsData>();
            }
            catch (Exception ex)
            {
                var msg = "Error de-serializing NOAA Settings JSON: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("NOAA Data: " + json);
                context.Response.StatusCode = 500;
                return(msg);
            }


            // process the settings
            try
            {
                cumulus.LogMessage("Updating NOAA settings");

                cumulus.NOAAconf.Create = settings.autosave;
                if (cumulus.NOAAconf.Create)
                {
                    cumulus.NOAAconf.Name  = settings.sitedetails.sitename;
                    cumulus.NOAAconf.City  = settings.sitedetails.city;
                    cumulus.NOAAconf.State = settings.sitedetails.state;

                    cumulus.NOAAconf.MonthFile = settings.outputfiles.monthfileformat;
                    cumulus.NOAAconf.YearFile  = settings.outputfiles.yearfileformat;

                    cumulus.NOAAconf.Use12hour     = settings.options.timeformat == 1;
                    cumulus.NOAAconf.UseUtf8       = settings.options.utf8;
                    cumulus.NOAAconf.UseDotDecimal = settings.options.dotdecimal;
                    cumulus.NOAAconf.UseMinMaxAvg  = settings.options.minmaxavg;

                    cumulus.NOAAconf.AutoFtp   = settings.ftp.autotransfer;
                    cumulus.NOAAconf.FtpFolder = settings.ftp.dstfolder;

                    cumulus.NOAAconf.AutoCopy   = settings.copy.autotransfer;
                    cumulus.NOAAconf.CopyFolder = settings.copy.dstfolder;

                    cumulus.NOAAconf.HeatThreshold = settings.thresholds.heatingthreshold;
                    cumulus.NOAAconf.CoolThreshold = settings.thresholds.coolingthreshold;
                    cumulus.NOAAconf.MaxTempComp1  = settings.thresholds.maxtempcomp1;
                    cumulus.NOAAconf.MaxTempComp2  = settings.thresholds.maxtempcomp2;
                    cumulus.NOAAconf.MinTempComp1  = settings.thresholds.mintempcomp1;
                    cumulus.NOAAconf.MinTempComp2  = settings.thresholds.mintempcomp2;
                    cumulus.NOAAconf.RainComp1     = settings.thresholds.raincomp1;
                    cumulus.NOAAconf.RainComp2     = settings.thresholds.raincomp2;
                    cumulus.NOAAconf.RainComp3     = settings.thresholds.raincomp3;

                    // normal mean temps
                    cumulus.NOAAconf.TempNorms[1]  = settings.normalmeantemps.jan;
                    cumulus.NOAAconf.TempNorms[2]  = settings.normalmeantemps.feb;
                    cumulus.NOAAconf.TempNorms[3]  = settings.normalmeantemps.mar;
                    cumulus.NOAAconf.TempNorms[4]  = settings.normalmeantemps.apr;
                    cumulus.NOAAconf.TempNorms[5]  = settings.normalmeantemps.may;
                    cumulus.NOAAconf.TempNorms[6]  = settings.normalmeantemps.jun;
                    cumulus.NOAAconf.TempNorms[7]  = settings.normalmeantemps.jul;
                    cumulus.NOAAconf.TempNorms[8]  = settings.normalmeantemps.aug;
                    cumulus.NOAAconf.TempNorms[9]  = settings.normalmeantemps.sep;
                    cumulus.NOAAconf.TempNorms[10] = settings.normalmeantemps.oct;
                    cumulus.NOAAconf.TempNorms[11] = settings.normalmeantemps.nov;
                    cumulus.NOAAconf.TempNorms[12] = settings.normalmeantemps.dec;

                    // normal rain
                    cumulus.NOAAconf.RainNorms[1]  = settings.normalrain.jan;
                    cumulus.NOAAconf.RainNorms[2]  = settings.normalrain.feb;
                    cumulus.NOAAconf.RainNorms[3]  = settings.normalrain.mar;
                    cumulus.NOAAconf.RainNorms[4]  = settings.normalrain.apr;
                    cumulus.NOAAconf.RainNorms[5]  = settings.normalrain.may;
                    cumulus.NOAAconf.RainNorms[6]  = settings.normalrain.jun;
                    cumulus.NOAAconf.RainNorms[6]  = settings.normalrain.jul;
                    cumulus.NOAAconf.RainNorms[8]  = settings.normalrain.aug;
                    cumulus.NOAAconf.RainNorms[9]  = settings.normalrain.sep;
                    cumulus.NOAAconf.RainNorms[10] = settings.normalrain.oct;
                    cumulus.NOAAconf.RainNorms[11] = settings.normalrain.nov;
                    cumulus.NOAAconf.RainNorms[12] = settings.normalrain.dec;
                }

                // Save the settings
                cumulus.WriteIniFile();

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                var msg = "Error processing NOAA settings: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("NOAA data: " + json);
                context.Response.StatusCode = 500;
                return(msg);
            }
            return("success");
        }
コード例 #12
0
        public string UpdateConfig(IHttpContext context)
        {
            var errorMsg = "";
            var json     = "";
            JsonProgramSettings settings;

            context.Response.StatusCode = 200;

            // get the response
            try
            {
                cumulus.LogMessage("Updating Program settings");

                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                settings = JsonSerializer.DeserializeFromString <JsonProgramSettings>(json);
            }
            catch (Exception ex)
            {
                var msg = "Error de-serializing Program Settings JSON: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("Program Data: " + json);
                context.Response.StatusCode = 500;
                return(msg);
            }

            // process the settings
            try
            {
                cumulus.ProgramOptions.EnableAccessibility   = settings.accessible;
                cumulus.ProgramOptions.StartupPingHost       = settings.startup.startuphostping;
                cumulus.ProgramOptions.StartupPingEscapeTime = settings.startup.startuppingescape;
                cumulus.ProgramOptions.StartupDelaySecs      = settings.startup.startupdelay;
                cumulus.ProgramOptions.StartupDelayMaxUptime = settings.startup.startupdelaymaxuptime;
                cumulus.ProgramOptions.DebugLogging          = settings.logging.debuglogging;
                cumulus.ProgramOptions.DataLogging           = settings.logging.datalogging;
                cumulus.SmtpOptions.Logging         = settings.logging.emaillogging;
                cumulus.ErrorLogSpikeRemoval        = settings.logging.spikelogging;
                cumulus.ProgramOptions.WarnMultiple = settings.options.stopsecondinstance;
                cumulus.ProgramOptions.ListWebTags  = settings.options.listwebtags;

                if (settings.logging.ftplogging != cumulus.FtpOptions.Logging)
                {
                    cumulus.FtpOptions.Logging = settings.logging.ftplogging;
                    cumulus.SetFtpLogging(cumulus.FtpOptions.Logging);
                }
            }
            catch (Exception ex)
            {
                var msg = "Error processing Program Options: " + ex.Message;
                cumulus.LogMessage(msg);
                errorMsg += msg + "\n\n";
                context.Response.StatusCode = 500;
            }

            // Save the settings
            cumulus.WriteIniFile();

            return(context.Response.StatusCode == 200 ? "success" : errorMsg);
        }
コード例 #13
0
        //public object UpdateMysqlConfig(HttpListenerContext context)
        public object UpdateConfig(IHttpContext context)
        {
            string            json = "";
            JsonMysqlSettings settings;

            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                settings = json.FromJson <JsonMysqlSettings>();
            }
            catch (Exception ex)
            {
                var msg = "Error de-serializing MySQL Settings JSON: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("MySQL Data: " + json);
                context.Response.StatusCode = 500;
                return(msg);
            }


            // process the settings
            try
            {
                cumulus.LogMessage("Updating MySQL settings");

                // server
                cumulus.MySqlConnSettings.Server = settings.server.host;
                if (settings.server.port > 0 && settings.server.port < 65536)
                {
                    cumulus.MySqlConnSettings.Port = settings.server.port;
                }
                else
                {
                    cumulus.MySqlConnSettings.Port = 3306;
                }
                cumulus.MySqlConnSettings.Database = settings.server.database;
                cumulus.MySqlConnSettings.UserID   = settings.server.user;
                cumulus.MySqlConnSettings.Password = settings.server.pass;

                // options
                cumulus.MySqlSettings.UpdateOnEdit    = settings.options.updateonedit;
                cumulus.MySqlSettings.BufferOnfailure = settings.options.bufferonerror;

                //monthly
                cumulus.MySqlSettings.Monthly.Enabled = settings.monthly.enabled;
                if (cumulus.MySqlSettings.Monthly.Enabled)
                {
                    cumulus.MySqlSettings.Monthly.TableName = String.IsNullOrWhiteSpace(settings.monthly.table) ? "Monthly" : settings.monthly.table;
                }
                //realtime
                cumulus.MySqlSettings.Realtime.Enabled = settings.realtime.enabled;
                if (cumulus.MySqlSettings.Realtime.Enabled)
                {
                    cumulus.MySqlSettings.RealtimeRetention    = settings.realtime.retentionVal + " " + settings.realtime.retentionUnit;
                    cumulus.MySqlSettings.Realtime.TableName   = String.IsNullOrWhiteSpace(settings.realtime.table) ? "Realtime" : settings.realtime.table;
                    cumulus.MySqlSettings.RealtimeLimit1Minute = settings.realtime.limit1min;
                }
                //dayfile
                cumulus.MySqlSettings.Dayfile.Enabled = settings.dayfile.enabled;
                if (cumulus.MySqlSettings.Dayfile.Enabled)
                {
                    cumulus.MySqlSettings.Dayfile.TableName = String.IsNullOrWhiteSpace(settings.dayfile.table) ? "Dayfile" : settings.dayfile.table;
                }
                // custom seconds
                cumulus.MySqlSettings.CustomSecs.Enabled = settings.customseconds.enabled;
                if (cumulus.MySqlSettings.CustomSecs.Enabled)
                {
                    cumulus.MySqlSettings.CustomSecs.Command  = settings.customseconds.command;
                    cumulus.MySqlSettings.CustomSecs.Interval = settings.customseconds.interval;
                }
                // custom minutes
                cumulus.MySqlSettings.CustomMins.Enabled = settings.customminutes.enabled;
                if (cumulus.MySqlSettings.CustomMins.Enabled)
                {
                    cumulus.MySqlSettings.CustomMins.Command = settings.customminutes.command;
                    cumulus.CustomMySqlMinutesIntervalIndex  = settings.customminutes.intervalindex;
                    if (cumulus.CustomMySqlMinutesIntervalIndex >= 0 && cumulus.CustomMySqlMinutesIntervalIndex < cumulus.FactorsOf60.Length)
                    {
                        cumulus.MySqlSettings.CustomMins.Interval = cumulus.FactorsOf60[cumulus.CustomMySqlMinutesIntervalIndex];
                    }
                    else
                    {
                        cumulus.MySqlSettings.CustomMins.Interval = 10;
                    }
                }
                // custom roll-over
                cumulus.MySqlSettings.CustomRollover.Enabled = settings.customrollover.enabled;
                if (cumulus.MySqlSettings.CustomRollover.Enabled)
                {
                    cumulus.MySqlSettings.CustomRollover.Command = settings.customrollover.command;
                }

                // Save the settings
                cumulus.WriteIniFile();

                cumulus.SetMonthlySqlCreateString();
                cumulus.SetStartOfMonthlyInsertSQL();

                cumulus.SetDayfileSqlCreateString();
                cumulus.SetStartOfDayfileInsertSQL();

                cumulus.SetRealtimeSqlCreateString();
                cumulus.SetStartOfRealtimeInsertSQL();

                cumulus.CustomMysqlSecondsTimer.Interval = cumulus.MySqlSettings.CustomSecs.Interval * 1000;
                cumulus.CustomMysqlSecondsTimer.Enabled  = cumulus.MySqlSettings.CustomSecs.Enabled;

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                var msg = "Error processing settings: " + ex.Message;
                cumulus.LogMessage(msg);
                context.Response.StatusCode = 500;
                return(msg);
            }
            return("success");
        }
コード例 #14
0
ファイル: AlarmSettings.cs プロジェクト: cumulusmx/CumulusMX
        public string UpdateAlarmSettings(IHttpContext context)
        {
            var json = "";
            JsonAlarmSettings     result;
            JsonAlarmSettingsData settings;

            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                json = WebUtility.UrlDecode(data);

                // de-serialize it to the settings structure
                //var settings = JsonConvert.DeserializeObject<JsonAlarmSettingsData>(json);
                //var settings = JsonSerializer.DeserializeFromString<JsonAlarmSettingsData>(json);

                result   = json.FromJson <JsonAlarmSettings>();
                settings = result.data;
            }
            catch (Exception ex)
            {
                var msg = "Error de-serializing Alarm Settings JSON: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("Alarm Data: " + json);
                context.Response.StatusCode = 500;
                return(msg);
            }

            try
            {
                // process the settings
                cumulus.LogMessage("Updating Alarm settings");

                var emailRequired = false;

                cumulus.LowTempAlarm.Enabled    = settings.tempBelow.Enabled;
                cumulus.LowTempAlarm.Value      = settings.tempBelow.Val;
                cumulus.LowTempAlarm.Sound      = settings.tempBelow.SoundEnabled;
                cumulus.LowTempAlarm.SoundFile  = settings.tempBelow.Sound;
                cumulus.LowTempAlarm.Notify     = settings.tempBelow.Notify;
                cumulus.LowTempAlarm.Email      = settings.tempBelow.Email;
                cumulus.LowTempAlarm.Latch      = settings.tempBelow.Latches;
                cumulus.LowTempAlarm.LatchHours = settings.tempBelow.LatchHrs;
                emailRequired = cumulus.LowTempAlarm.Email && cumulus.LowTempAlarm.Enabled;
                cumulus.LowTempAlarm.Action       = settings.tempBelow.Action;
                cumulus.LowTempAlarm.ActionParams = settings.tempBelow.ActionParams;

                cumulus.HighTempAlarm.Enabled    = settings.tempAbove.Enabled;
                cumulus.HighTempAlarm.Value      = settings.tempAbove.Val;
                cumulus.HighTempAlarm.Sound      = settings.tempAbove.SoundEnabled;
                cumulus.HighTempAlarm.SoundFile  = settings.tempAbove.Sound;
                cumulus.HighTempAlarm.Notify     = settings.tempAbove.Notify;
                cumulus.HighTempAlarm.Email      = settings.tempAbove.Email;
                cumulus.HighTempAlarm.Latch      = settings.tempAbove.Latches;
                cumulus.HighTempAlarm.LatchHours = settings.tempAbove.LatchHrs;
                emailRequired = emailRequired || (cumulus.HighTempAlarm.Email && cumulus.HighTempAlarm.Enabled);
                cumulus.HighTempAlarm.Action       = settings.tempAbove.Action;
                cumulus.HighTempAlarm.ActionParams = settings.tempAbove.ActionParams;

                cumulus.TempChangeAlarm.Enabled    = settings.tempChange.Enabled;
                cumulus.TempChangeAlarm.Value      = settings.tempChange.Val;
                cumulus.TempChangeAlarm.Sound      = settings.tempChange.SoundEnabled;
                cumulus.TempChangeAlarm.SoundFile  = settings.tempChange.Sound;
                cumulus.TempChangeAlarm.Notify     = settings.tempChange.Notify;
                cumulus.TempChangeAlarm.Email      = settings.tempChange.Email;
                cumulus.TempChangeAlarm.Latch      = settings.tempChange.Latches;
                cumulus.TempChangeAlarm.LatchHours = settings.tempChange.LatchHrs;
                emailRequired = emailRequired || (cumulus.TempChangeAlarm.Email && cumulus.TempChangeAlarm.Enabled);
                cumulus.TempChangeAlarm.Action       = settings.tempChange.Action;
                cumulus.TempChangeAlarm.ActionParams = settings.tempChange.ActionParams;

                cumulus.LowPressAlarm.Enabled    = settings.pressBelow.Enabled;
                cumulus.LowPressAlarm.Value      = settings.pressBelow.Val;
                cumulus.LowPressAlarm.Sound      = settings.pressBelow.SoundEnabled;
                cumulus.LowPressAlarm.SoundFile  = settings.pressBelow.Sound;
                cumulus.LowPressAlarm.Notify     = settings.pressBelow.Notify;
                cumulus.LowPressAlarm.Email      = settings.pressBelow.Email;
                cumulus.LowPressAlarm.Latch      = settings.pressBelow.Latches;
                cumulus.LowPressAlarm.LatchHours = settings.pressBelow.LatchHrs;
                emailRequired = emailRequired || (cumulus.LowPressAlarm.Email && cumulus.LowPressAlarm.Enabled);
                cumulus.LowPressAlarm.Action       = settings.pressBelow.Action;
                cumulus.LowPressAlarm.ActionParams = settings.pressBelow.ActionParams;

                cumulus.HighPressAlarm.Enabled    = settings.pressAbove.Enabled;
                cumulus.HighPressAlarm.Value      = settings.pressAbove.Val;
                cumulus.HighPressAlarm.Sound      = settings.pressAbove.SoundEnabled;
                cumulus.HighPressAlarm.SoundFile  = settings.pressAbove.Sound;
                cumulus.HighPressAlarm.Notify     = settings.pressAbove.Notify;
                cumulus.HighPressAlarm.Email      = settings.pressAbove.Email;
                cumulus.HighPressAlarm.Latch      = settings.pressAbove.Latches;
                cumulus.HighPressAlarm.LatchHours = settings.pressAbove.LatchHrs;
                emailRequired = emailRequired || (cumulus.HighPressAlarm.Email && cumulus.HighPressAlarm.Enabled);
                cumulus.HighPressAlarm.Action       = settings.pressAbove.Action;
                cumulus.HighPressAlarm.ActionParams = settings.pressAbove.ActionParams;

                cumulus.PressChangeAlarm.Enabled    = settings.pressChange.Enabled;
                cumulus.PressChangeAlarm.Value      = settings.pressChange.Val;
                cumulus.PressChangeAlarm.Sound      = settings.pressChange.SoundEnabled;
                cumulus.PressChangeAlarm.SoundFile  = settings.pressChange.Sound;
                cumulus.PressChangeAlarm.Notify     = settings.pressChange.Notify;
                cumulus.PressChangeAlarm.Email      = settings.pressChange.Email;
                cumulus.PressChangeAlarm.Latch      = settings.pressChange.Latches;
                cumulus.PressChangeAlarm.LatchHours = settings.pressChange.LatchHrs;
                emailRequired = emailRequired || (cumulus.PressChangeAlarm.Email && cumulus.PressChangeAlarm.Enabled);
                cumulus.PressChangeAlarm.Action       = settings.pressChange.Action;
                cumulus.PressChangeAlarm.ActionParams = settings.pressChange.ActionParams;

                cumulus.HighRainTodayAlarm.Enabled    = settings.rainAbove.Enabled;
                cumulus.HighRainTodayAlarm.Value      = settings.rainAbove.Val;
                cumulus.HighRainTodayAlarm.Sound      = settings.rainAbove.SoundEnabled;
                cumulus.HighRainTodayAlarm.SoundFile  = settings.rainAbove.Sound;
                cumulus.HighRainTodayAlarm.Notify     = settings.rainAbove.Notify;
                cumulus.HighRainTodayAlarm.Email      = settings.rainAbove.Email;
                cumulus.HighRainTodayAlarm.Latch      = settings.rainAbove.Latches;
                cumulus.HighRainTodayAlarm.LatchHours = settings.rainAbove.LatchHrs;
                emailRequired = emailRequired || (cumulus.HighRainTodayAlarm.Email && cumulus.HighRainTodayAlarm.Enabled);
                cumulus.HighRainTodayAlarm.Action       = settings.rainAbove.Action;
                cumulus.HighRainTodayAlarm.ActionParams = settings.rainAbove.ActionParams;

                cumulus.HighRainRateAlarm.Enabled    = settings.rainRateAbove.Enabled;
                cumulus.HighRainRateAlarm.Value      = settings.rainRateAbove.Val;
                cumulus.HighRainRateAlarm.Sound      = settings.rainRateAbove.SoundEnabled;
                cumulus.HighRainRateAlarm.SoundFile  = settings.rainRateAbove.Sound;
                cumulus.HighRainRateAlarm.Notify     = settings.rainRateAbove.Notify;
                cumulus.HighRainRateAlarm.Email      = settings.rainRateAbove.Email;
                cumulus.HighRainRateAlarm.Latch      = settings.rainRateAbove.Latches;
                cumulus.HighRainRateAlarm.LatchHours = settings.rainRateAbove.LatchHrs;
                emailRequired = emailRequired || (cumulus.HighRainRateAlarm.Email && cumulus.HighRainRateAlarm.Enabled);
                cumulus.HighRainRateAlarm.Action       = settings.rainRateAbove.Action;
                cumulus.HighRainRateAlarm.ActionParams = settings.rainRateAbove.ActionParams;

                cumulus.IsRainingAlarm.Enabled    = settings.isRaining.Enabled;
                cumulus.IsRainingAlarm.Sound      = settings.isRaining.SoundEnabled;
                cumulus.IsRainingAlarm.SoundFile  = settings.isRaining.Sound;
                cumulus.IsRainingAlarm.Notify     = settings.isRaining.Notify;
                cumulus.IsRainingAlarm.Email      = settings.isRaining.Email;
                cumulus.IsRainingAlarm.Latch      = settings.isRaining.Latches;
                cumulus.IsRainingAlarm.LatchHours = settings.isRaining.LatchHrs;
                emailRequired = emailRequired || (cumulus.IsRainingAlarm.Email && cumulus.IsRainingAlarm.Enabled);
                cumulus.IsRainingAlarm.Action       = settings.isRaining.Action;
                cumulus.IsRainingAlarm.ActionParams = settings.isRaining.ActionParams;

                cumulus.HighGustAlarm.Enabled    = settings.gustAbove.Enabled;
                cumulus.HighGustAlarm.Value      = settings.gustAbove.Val;
                cumulus.HighGustAlarm.Sound      = settings.gustAbove.SoundEnabled;
                cumulus.HighGustAlarm.SoundFile  = settings.gustAbove.Sound;
                cumulus.HighGustAlarm.Notify     = settings.gustAbove.Notify;
                cumulus.HighGustAlarm.Email      = settings.gustAbove.Email;
                cumulus.HighGustAlarm.Latch      = settings.gustAbove.Latches;
                cumulus.HighGustAlarm.LatchHours = settings.gustAbove.LatchHrs;
                emailRequired = emailRequired || (cumulus.HighGustAlarm.Email && cumulus.HighGustAlarm.Enabled);
                cumulus.HighGustAlarm.Action       = settings.gustAbove.Action;
                cumulus.HighGustAlarm.ActionParams = settings.gustAbove.ActionParams;

                cumulus.HighWindAlarm.Enabled    = settings.windAbove.Enabled;
                cumulus.HighWindAlarm.Value      = settings.windAbove.Val;
                cumulus.HighWindAlarm.Sound      = settings.windAbove.SoundEnabled;
                cumulus.HighWindAlarm.SoundFile  = settings.windAbove.Sound;
                cumulus.HighWindAlarm.Notify     = settings.windAbove.Notify;
                cumulus.HighWindAlarm.Email      = settings.windAbove.Email;
                cumulus.HighWindAlarm.Latch      = settings.windAbove.Latches;
                cumulus.HighWindAlarm.LatchHours = settings.windAbove.LatchHrs;
                emailRequired = emailRequired || (cumulus.HighWindAlarm.Email && cumulus.HighWindAlarm.Enabled);
                cumulus.HighWindAlarm.Action       = settings.windAbove.Action;
                cumulus.HighWindAlarm.ActionParams = settings.windAbove.ActionParams;

                cumulus.SensorAlarm.Enabled          = settings.contactLost.Enabled;
                cumulus.SensorAlarm.Sound            = settings.contactLost.SoundEnabled;
                cumulus.SensorAlarm.SoundFile        = settings.contactLost.Sound;
                cumulus.SensorAlarm.Notify           = settings.contactLost.Notify;
                cumulus.SensorAlarm.Email            = settings.contactLost.Email;
                cumulus.SensorAlarm.Latch            = settings.contactLost.Latches;
                cumulus.SensorAlarm.LatchHours       = settings.contactLost.LatchHrs;
                cumulus.SensorAlarm.TriggerThreshold = settings.contactLost.Threshold;
                emailRequired = emailRequired || (cumulus.SensorAlarm.Email && cumulus.SensorAlarm.Enabled);
                cumulus.SensorAlarm.Action       = settings.contactLost.Action;
                cumulus.SensorAlarm.ActionParams = settings.contactLost.ActionParams;

                cumulus.DataStoppedAlarm.Enabled          = settings.dataStopped.Enabled;
                cumulus.DataStoppedAlarm.Sound            = settings.dataStopped.SoundEnabled;
                cumulus.DataStoppedAlarm.SoundFile        = settings.dataStopped.Sound;
                cumulus.DataStoppedAlarm.Notify           = settings.dataStopped.Notify;
                cumulus.DataStoppedAlarm.Email            = settings.dataStopped.Email;
                cumulus.DataStoppedAlarm.Latch            = settings.dataStopped.Latches;
                cumulus.DataStoppedAlarm.LatchHours       = settings.dataStopped.LatchHrs;
                cumulus.DataStoppedAlarm.TriggerThreshold = settings.dataStopped.Threshold;
                emailRequired = emailRequired || (cumulus.DataStoppedAlarm.Email && cumulus.DataStoppedAlarm.Enabled);
                cumulus.DataStoppedAlarm.Action       = settings.dataStopped.Action;
                cumulus.DataStoppedAlarm.ActionParams = settings.dataStopped.ActionParams;

                cumulus.BatteryLowAlarm.Enabled          = settings.batteryLow.Enabled;
                cumulus.BatteryLowAlarm.Sound            = settings.batteryLow.SoundEnabled;
                cumulus.BatteryLowAlarm.SoundFile        = settings.batteryLow.Sound;
                cumulus.BatteryLowAlarm.Notify           = settings.batteryLow.Notify;
                cumulus.BatteryLowAlarm.Email            = settings.batteryLow.Email;
                cumulus.BatteryLowAlarm.Latch            = settings.batteryLow.Latches;
                cumulus.BatteryLowAlarm.LatchHours       = settings.batteryLow.LatchHrs;
                cumulus.BatteryLowAlarm.TriggerThreshold = settings.batteryLow.Threshold;
                emailRequired = emailRequired || (cumulus.BatteryLowAlarm.Email && cumulus.BatteryLowAlarm.Enabled);
                cumulus.BatteryLowAlarm.Action       = settings.batteryLow.Action;
                cumulus.BatteryLowAlarm.ActionParams = settings.batteryLow.ActionParams;

                cumulus.SpikeAlarm.Enabled          = settings.spike.Enabled;
                cumulus.SpikeAlarm.Sound            = settings.spike.SoundEnabled;
                cumulus.SpikeAlarm.SoundFile        = settings.spike.Sound;
                cumulus.SpikeAlarm.Notify           = settings.spike.Notify;
                cumulus.SpikeAlarm.Email            = settings.spike.Email;
                cumulus.SpikeAlarm.Latch            = settings.spike.Latches;
                cumulus.SpikeAlarm.LatchHours       = settings.spike.LatchHrs;
                cumulus.SpikeAlarm.TriggerThreshold = settings.spike.Threshold;
                emailRequired                   = emailRequired || (cumulus.SpikeAlarm.Email && cumulus.SpikeAlarm.Enabled);
                cumulus.SpikeAlarm.Action       = settings.spike.Action;
                cumulus.SpikeAlarm.ActionParams = settings.spike.ActionParams;

                cumulus.UpgradeAlarm.Enabled    = settings.upgrade.Enabled;
                cumulus.UpgradeAlarm.Sound      = settings.upgrade.SoundEnabled;
                cumulus.UpgradeAlarm.SoundFile  = settings.upgrade.Sound;
                cumulus.UpgradeAlarm.Notify     = settings.upgrade.Notify;
                cumulus.UpgradeAlarm.Email      = settings.upgrade.Email;
                cumulus.UpgradeAlarm.Latch      = settings.upgrade.Latches;
                cumulus.UpgradeAlarm.LatchHours = settings.upgrade.LatchHrs;
                emailRequired = emailRequired || (cumulus.UpgradeAlarm.Email && cumulus.UpgradeAlarm.Enabled);
                cumulus.UpgradeAlarm.Action       = settings.upgrade.Action;
                cumulus.UpgradeAlarm.ActionParams = settings.upgrade.ActionParams;

                cumulus.HttpUploadAlarm.Enabled          = settings.httpUpload.Enabled;
                cumulus.HttpUploadAlarm.Sound            = settings.httpUpload.SoundEnabled;
                cumulus.HttpUploadAlarm.SoundFile        = settings.httpUpload.Sound;
                cumulus.HttpUploadAlarm.Notify           = settings.httpUpload.Notify;
                cumulus.HttpUploadAlarm.Email            = settings.httpUpload.Email;
                cumulus.HttpUploadAlarm.Latch            = settings.httpUpload.Latches;
                cumulus.HttpUploadAlarm.LatchHours       = settings.httpUpload.LatchHrs;
                cumulus.HttpUploadAlarm.TriggerThreshold = settings.httpUpload.Threshold;
                emailRequired = emailRequired || (cumulus.HttpUploadAlarm.Email && cumulus.HttpUploadAlarm.Enabled);
                cumulus.HttpUploadAlarm.Action       = settings.httpUpload.Action;
                cumulus.HttpUploadAlarm.ActionParams = settings.httpUpload.ActionParams;

                cumulus.MySqlUploadAlarm.Enabled          = settings.mySqlUpload.Enabled;
                cumulus.MySqlUploadAlarm.Sound            = settings.mySqlUpload.SoundEnabled;
                cumulus.MySqlUploadAlarm.SoundFile        = settings.mySqlUpload.Sound;
                cumulus.MySqlUploadAlarm.Notify           = settings.mySqlUpload.Notify;
                cumulus.MySqlUploadAlarm.Email            = settings.mySqlUpload.Email;
                cumulus.MySqlUploadAlarm.Latch            = settings.mySqlUpload.Latches;
                cumulus.MySqlUploadAlarm.LatchHours       = settings.mySqlUpload.LatchHrs;
                cumulus.MySqlUploadAlarm.TriggerThreshold = settings.mySqlUpload.Threshold;
                emailRequired = emailRequired || (cumulus.MySqlUploadAlarm.Email && cumulus.MySqlUploadAlarm.Enabled);
                cumulus.MySqlUploadAlarm.Action       = settings.mySqlUpload.Action;
                cumulus.MySqlUploadAlarm.ActionParams = settings.mySqlUpload.ActionParams;

                // validate the from email
                if (emailRequired && !EmailSender.CheckEmailAddress(result.email.fromEmail.Trim()))
                {
                    var msg = "ERROR: Alarm email option enabled and an invalid Alarm from email address entered";
                    cumulus.LogMessage(msg);
                    context.Response.StatusCode = 500;
                    return(msg);
                }
                else
                {
                    cumulus.AlarmFromEmail = result.email.fromEmail.Trim();
                }

                // validate the destination email(s)
                var emails = result.email.destEmail.Trim().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                for (var i = 0; i < emails.Length; i++)
                {
                    emails[i] = emails[i].Trim();
                    if (!EmailSender.CheckEmailAddress(emails[i]))
                    {
                        var msg = "ERROR: Invalid Alarm destination email address entered";
                        cumulus.LogMessage(msg);
                        context.Response.StatusCode = 500;
                        return(msg);
                    }
                }
                cumulus.AlarmDestEmail = emails;
                cumulus.AlarmEmailHtml = result.email.useHtml;

                // Save the settings
                cumulus.WriteIniFile();

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                cumulus.LogMessage("Error processing Alarm settings: " + ex.Message);
                cumulus.LogDebugMessage("Alarm Data: " + json);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }
            return("success");
        }
コード例 #15
0
        //public string UpdateInternetConfig(HttpListenerContext context)
        public string UpdateInternetConfig(IHttpContext context)
        {
            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                var json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                //JsonInternetSettingsData settings = new JavaScriptSerializer().Deserialize<JsonInternetSettingsData>(json);
                var settings = JSON.ToObject <JsonInternetSettingsData>(json);
                // process the settings
                cumulus.LogMessage("Updating internet settings");

                // website settings
                cumulus.ftp_directory = settings.website.directory ?? string.Empty;
                cumulus.ForumURL      = settings.website.forumurl ?? string.Empty;
                cumulus.ftp_port      = settings.website.ftpport;
                cumulus.ftp_host      = settings.website.hostname ?? string.Empty;
                cumulus.ftp_password  = settings.website.password ?? string.Empty;
                cumulus.ftp_user      = settings.website.username ?? string.Empty;
                cumulus.WebcamURL     = settings.website.webcamurl ?? string.Empty;

                // web settings
                cumulus.ActiveFTPMode         = settings.websettings.activeftp;
                cumulus.Sslftp                = settings.websettings.sslftp;
                cumulus.WebAutoUpdate         = settings.websettings.autoupdate;
                cumulus.RealtimeEnabled       = settings.websettings.enablerealtime;
                cumulus.RealtimeFTPEnabled    = settings.websettings.enablerealtimeftp;
                cumulus.RealtimeTxtFTP        = settings.websettings.realtimetxtftp;
                cumulus.RealtimeGaugesTxtFTP  = settings.websettings.realtimegaugestxtftp;
                cumulus.RealtimeInterval      = settings.websettings.realtimeinterval * 1000;
                cumulus.DeleteBeforeUpload    = settings.websettings.ftpdelete;
                cumulus.UpdateInterval        = settings.websettings.ftpinterval;
                cumulus.FTPRename             = settings.websettings.ftprename;
                cumulus.IncludeStandardFiles  = settings.websettings.includestdfiles;
                cumulus.IncludeGraphDataFiles = settings.websettings.includegraphdatafiles;
                cumulus.UTF8encode            = settings.websettings.utf8encode;
                if (settings.websettings.ftplogging != cumulus.FTPlogging)
                {
                    cumulus.FTPlogging = settings.websettings.ftplogging;
                    cumulus.SetFtpLogging(cumulus.FTPlogging);
                }

                // external programs
                cumulus.DailyProgram    = settings.externalprograms.dailyprogram ?? string.Empty;
                cumulus.DailyParams     = settings.externalprograms.dailyprogramparams ?? string.Empty;
                cumulus.ExternalProgram = settings.externalprograms.program ?? string.Empty;
                cumulus.ExternalParams  = settings.externalprograms.programparams ?? string.Empty;
                cumulus.RealtimeProgram = settings.externalprograms.realtimeprogram ?? string.Empty;
                cumulus.RealtimeParams  = settings.externalprograms.realtimeprogramparams ?? string.Empty;

                // twitter
                cumulus.TwitterEnabled      = settings.twitter.enabled;
                cumulus.TwitterInterval     = settings.twitter.interval;
                cumulus.TwitterPW           = settings.twitter.password ?? string.Empty;
                cumulus.TwitterSendLocation = settings.twitter.sendlocation;
                cumulus.Twitteruser         = settings.twitter.user ?? string.Empty;

                cumulus.SynchronisedTwitterUpdate = (60 % cumulus.TwitterInterval == 0);

                // wunderground
                cumulus.WundCatchUp          = settings.wunderground.catchup;
                cumulus.WundEnabled          = settings.wunderground.enabled;
                cumulus.SendIndoorToWund     = settings.wunderground.includeindoor;
                cumulus.SendSRToWund         = settings.wunderground.includesolar;
                cumulus.SendUVToWund         = settings.wunderground.includeuv;
                cumulus.WundInterval         = settings.wunderground.interval;
                cumulus.WundPW               = settings.wunderground.password ?? string.Empty;
                cumulus.WundRapidFireEnabled = settings.wunderground.rapidfire;
                cumulus.WundSendAverage      = settings.wunderground.sendavgwind;
                cumulus.WundID               = settings.wunderground.stationid ?? string.Empty;

                cumulus.SynchronisedWUUpdate = (!cumulus.WundRapidFireEnabled) && (60 % cumulus.WundInterval == 0);

                // Awekas
                cumulus.AwekasEnabled        = settings.awekas.enabled;
                cumulus.AwekasInterval       = settings.awekas.interval;
                cumulus.AwekasLang           = settings.awekas.lang;
                cumulus.AwekasPW             = settings.awekas.password ?? string.Empty;
                cumulus.AwekasUser           = settings.awekas.user ?? string.Empty;
                cumulus.SendSolarToAwekas    = settings.awekas.includesolar;
                cumulus.SendUVToAwekas       = settings.awekas.includeuv;
                cumulus.SendSoilTempToAwekas = settings.awekas.includesoiltemp;

                cumulus.SynchronisedAwekasUpdate = (60 % cumulus.AwekasInterval == 0);

                // WeatherCloud
                cumulus.WCloudWid         = settings.weathercloud.wid ?? string.Empty;
                cumulus.WCloudKey         = settings.weathercloud.key ?? string.Empty;
                cumulus.WCloudEnabled     = settings.weathercloud.enabled;
                cumulus.SendSolarToWCloud = settings.weathercloud.includesolar;
                cumulus.SendUVToWCloud    = settings.weathercloud.includeuv;

                cumulus.SynchronisedWCloudUpdate = (60 % cumulus.WCloudInterval == 0);

                // PWS weather
                cumulus.PWSCatchUp  = settings.pwsweather.catchup;
                cumulus.PWSEnabled  = settings.pwsweather.enabled;
                cumulus.PWSInterval = settings.pwsweather.interval;
                cumulus.SendSRToPWS = settings.pwsweather.includesolar;
                cumulus.SendUVToPWS = settings.pwsweather.includeuv;
                cumulus.PWSPW       = settings.pwsweather.password ?? string.Empty;
                cumulus.PWSID       = settings.pwsweather.stationid ?? string.Empty;

                cumulus.SynchronisedPWSUpdate = (60 % cumulus.PWSInterval == 0);

                // WOW
                cumulus.WOWCatchUp  = settings.wow.catchup;
                cumulus.WOWEnabled  = settings.wow.enabled;
                cumulus.SendSRToWOW = settings.wow.includesolar;
                cumulus.SendUVToWOW = settings.wow.includeuv;
                cumulus.WOWInterval = settings.wow.interval;
                cumulus.WOWPW       = settings.wow.password ?? string.Empty;;
                cumulus.WOWID       = settings.wow.stationid ?? string.Empty;;

                cumulus.SynchronisedWOWUpdate = (60 % cumulus.WOWInterval == 0);

                // Weatherbug
                cumulus.WeatherbugCatchUp  = settings.weatherbug.catchup;
                cumulus.WeatherbugEnabled  = settings.weatherbug.enabled;
                cumulus.SendSRToWeatherbug = settings.weatherbug.includesolar;
                cumulus.SendUVToWeatherbug = settings.weatherbug.includeuv;
                cumulus.WeatherbugInterval = settings.weatherbug.interval;
                cumulus.WeatherbugNumber   = settings.weatherbug.number ?? string.Empty;;
                cumulus.WeatherbugPW       = settings.weatherbug.password ?? string.Empty;;
                cumulus.WeatherbugID       = settings.weatherbug.publisherid ?? string.Empty;;

                cumulus.SynchronisedWBUpdate = (60 % cumulus.WeatherbugInterval == 0);

                // CWOP
                cumulus.APRSenabled  = settings.cwop.enabled;
                cumulus.APRSID       = settings.cwop.id ?? string.Empty;;
                cumulus.APRSinterval = settings.cwop.interval;
                cumulus.SendSRToAPRS = settings.cwop.includesolar;
                cumulus.APRSpass     = settings.cwop.password ?? string.Empty;;
                cumulus.APRSport     = settings.cwop.port;
                cumulus.APRSserver   = settings.cwop.server ?? string.Empty;;

                cumulus.SynchronisedAPRSUpdate = (60 % cumulus.APRSinterval == 0);

                // HTTP proxy
                cumulus.HTTPProxyPassword = settings.proxies.httpproxy.password ?? string.Empty;
                cumulus.HTTPProxyPort     = settings.proxies.httpproxy.port;
                cumulus.HTTPProxyName     = settings.proxies.httpproxy.proxy ?? string.Empty;
                cumulus.HTTPProxyUser     = settings.proxies.httpproxy.user ?? string.Empty;

                // Custom HTTP
                // custom seconds
                cumulus.CustomHttpSecondsString         = settings.customhttp.customseconds.url ?? string.Empty;
                cumulus.CustomHttpSecondsEnabled        = settings.customhttp.customseconds.enabled;
                cumulus.CustomHttpSecondsInterval       = settings.customhttp.customseconds.interval;
                cumulus.CustomHttpSecondsTimer.Interval = cumulus.CustomHttpSecondsInterval * 1000;
                cumulus.CustomHttpSecondsTimer.Enabled  = cumulus.CustomHttpSecondsEnabled;
                // custom minutes
                cumulus.CustomHttpMinutesString        = settings.customhttp.customminutes.url ?? string.Empty;
                cumulus.CustomHttpMinutesEnabled       = settings.customhttp.customminutes.enabled;
                cumulus.CustomHttpMinutesIntervalIndex = settings.customhttp.customminutes.intervalindex;
                if (cumulus.CustomHttpMinutesIntervalIndex >= 0 && cumulus.CustomHttpMinutesIntervalIndex < cumulus.FactorsOf60.Length)
                {
                    cumulus.CustomHttpMinutesInterval = cumulus.FactorsOf60[cumulus.CustomHttpMinutesIntervalIndex];
                }
                else
                {
                    cumulus.CustomHttpMinutesInterval = 10;
                }
                // custom rollover
                cumulus.CustomHttpRolloverString  = settings.customhttp.customrollover.url ?? string.Empty;
                cumulus.CustomHttpRolloverEnabled = settings.customhttp.customrollover.enabled;

                // Save the settings
                cumulus.WriteIniFile();

                cumulus.SetUpHttpProxy();
                //cumulus.SetFtpLogging(cumulus.FTPlogging);

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                cumulus.LogMessage(ex.Message);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }
            return("success");
        }
コード例 #16
0
        public string UpdateExtraSensorConfig(IHttpContext context)
        {
            var errorMsg = "";

            context.Response.StatusCode = 200;

            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                var json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                var settings = json.FromJson <JsonExtraSensorSettings>();
                // process the settings
                cumulus.LogMessage("Updating extra sensor settings");

                // General settings
                try
                {
                    cumulus.StationOptions.PrimaryAqSensor = settings.airquality.primaryaqsensor;
                    cumulus.airQualityIndex = settings.airquality.aqi;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing General settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // AirLink settings
                try
                {
                    cumulus.AirLinkIsNode              = settings.airLink.isNode;
                    cumulus.AirLinkApiKey              = settings.airLink.apiKey;
                    cumulus.AirLinkApiSecret           = settings.airLink.apiSecret;
                    cumulus.AirLinkAutoUpdateIpAddress = settings.airLink.autoUpdateIp;

                    cumulus.AirLinkInEnabled = settings.airLink.indoorenabled;
                    if (cumulus.AirLinkInEnabled && settings.airLink.indoor != null)
                    {
                        cumulus.AirLinkInIPAddr    = settings.airLink.indoor.ipAddress;
                        cumulus.AirLinkInHostName  = settings.airLink.indoor.hostname;
                        cumulus.AirLinkInStationId = settings.airLink.indoor.stationId;
                        if (cumulus.AirLinkInStationId < 10 && cumulus.AirLinkIsNode)
                        {
                            cumulus.AirLinkInStationId = cumulus.WllStationId;
                        }
                    }
                    cumulus.AirLinkOutEnabled = settings.airLink.outdoorenabled;
                    if (cumulus.AirLinkOutEnabled && settings.airLink.outdoor != null)
                    {
                        cumulus.AirLinkOutIPAddr    = settings.airLink.outdoor.ipAddress;
                        cumulus.AirLinkOutHostName  = settings.airLink.outdoor.hostname;
                        cumulus.AirLinkOutStationId = settings.airLink.outdoor.stationId;
                        if (cumulus.AirLinkOutStationId < 10 && cumulus.AirLinkIsNode)
                        {
                            cumulus.AirLinkOutStationId = cumulus.WllStationId;
                        }
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing AirLink settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Blake-Larsen settings
                try
                {
                    cumulus.UseBlakeLarsen = settings.blakeLarsen.enabled;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Blake-Larsen settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // RG-11 settings
                try
                {
                    cumulus.RG11Enabled = settings.rg11.dev1enabled;
                    if (cumulus.RG11Enabled && settings.rg11.port1 != null)
                    {
                        cumulus.RG11Port        = settings.rg11.port1.commPort;
                        cumulus.RG11TBRmode     = settings.rg11.port1.tipMode;
                        cumulus.RG11tipsize     = settings.rg11.port1.tipSize;
                        cumulus.RG11IgnoreFirst = settings.rg11.port1.ignoreFirst;
                        cumulus.RG11DTRmode     = settings.rg11.port1.dtrMode;
                    }

                    cumulus.RG11Enabled2 = settings.rg11.dev2enabled;
                    if (cumulus.RG11Enabled2 && settings.rg11.port2 != null)
                    {
                        cumulus.RG11Port2        = settings.rg11.port2.commPort;
                        cumulus.RG11TBRmode2     = settings.rg11.port2.tipMode;
                        cumulus.RG11tipsize2     = settings.rg11.port2.tipSize;
                        cumulus.RG11IgnoreFirst2 = settings.rg11.port2.ignoreFirst;
                        cumulus.RG11DTRmode2     = settings.rg11.port2.dtrMode;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing RG-11 settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }
            }
            catch (Exception ex)
            {
                cumulus.LogMessage(ex.Message);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }

            // Save the settings
            cumulus.WriteIniFile();

            return(context.Response.StatusCode == 200 ? "success" : errorMsg);
        }
コード例 #17
0
        //public string UpdateNoaaConfig(HttpListenerContext context)
        public string UpdateNoaaConfig(IHttpContext context)
        {
            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                var json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                var settings = json.FromJson <JsonNOAASettingsData>();
                // process the settings
                cumulus.LogMessage("Updating NOAA settings");

                cumulus.NOAAname             = settings.sitename;
                cumulus.NOAAcity             = settings.city;
                cumulus.NOAAstate            = settings.state;
                cumulus.NOAA12hourformat     = settings.timeformat == 0;
                cumulus.NOAAMonthFileFormat  = settings.monthfileformat;
                cumulus.NOAAYearFileFormat   = settings.yearfileformat;
                cumulus.NOAAUseUTF8          = settings.utf8;
                cumulus.NOAAUseDotDecimal    = settings.dotdecimal;
                cumulus.NOAAAutoSave         = settings.autosave;
                cumulus.NOAAAutoFTP          = settings.autoftp;
                cumulus.NOAAFTPDirectory     = settings.ftpdirectory;
                cumulus.NOAAheatingthreshold = settings.heatingthreshold;
                cumulus.NOAAcoolingthreshold = settings.coolingthreshold;
                cumulus.NOAAmaxtempcomp1     = settings.maxtempcomp1;
                cumulus.NOAAmaxtempcomp2     = settings.maxtempcomp2;
                cumulus.NOAAmintempcomp1     = settings.mintempcomp1;
                cumulus.NOAAmintempcomp2     = settings.mintempcomp2;
                cumulus.NOAAraincomp1        = settings.raincomp1;
                cumulus.NOAAraincomp2        = settings.raincomp2;
                cumulus.NOAAraincomp3        = settings.raincomp3;

                // normal mean temps
                cumulus.NOAATempNorms[1]  = settings.normalmeantemps.jan;
                cumulus.NOAATempNorms[2]  = settings.normalmeantemps.feb;
                cumulus.NOAATempNorms[3]  = settings.normalmeantemps.mar;
                cumulus.NOAATempNorms[4]  = settings.normalmeantemps.apr;
                cumulus.NOAATempNorms[5]  = settings.normalmeantemps.may;
                cumulus.NOAATempNorms[6]  = settings.normalmeantemps.jun;
                cumulus.NOAATempNorms[7]  = settings.normalmeantemps.jul;
                cumulus.NOAATempNorms[8]  = settings.normalmeantemps.aug;
                cumulus.NOAATempNorms[9]  = settings.normalmeantemps.sep;
                cumulus.NOAATempNorms[10] = settings.normalmeantemps.oct;
                cumulus.NOAATempNorms[11] = settings.normalmeantemps.nov;
                cumulus.NOAATempNorms[12] = settings.normalmeantemps.dec;

                // normal rain
                cumulus.NOAARainNorms[1]  = settings.normalrain.jan;
                cumulus.NOAARainNorms[2]  = settings.normalrain.feb;
                cumulus.NOAARainNorms[3]  = settings.normalrain.mar;
                cumulus.NOAARainNorms[4]  = settings.normalrain.apr;
                cumulus.NOAARainNorms[5]  = settings.normalrain.may;
                cumulus.NOAARainNorms[6]  = settings.normalrain.jun;
                cumulus.NOAARainNorms[6]  = settings.normalrain.jul;
                cumulus.NOAARainNorms[8]  = settings.normalrain.aug;
                cumulus.NOAARainNorms[9]  = settings.normalrain.sep;
                cumulus.NOAARainNorms[10] = settings.normalrain.oct;
                cumulus.NOAARainNorms[11] = settings.normalrain.nov;
                cumulus.NOAARainNorms[12] = settings.normalrain.dec;

                // Save the settings
                cumulus.WriteIniFile();

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                cumulus.LogMessage(ex.Message);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }
            return("success");
        }
コード例 #18
0
ファイル: StationSettings.cs プロジェクト: bvs79669/CumulusMX
        //public string UpdateStationConfig(HttpListenerContext context)
        public string UpdateStationConfig(IHttpContext context)
        {
            // get the response
            try
            {
                cumulus.LogMessage("Updating station settings");

                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                var json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                var settings = JSON.ToObject <JsonStationSettingsData>(json);
                // process the settings

                cumulus.GraphHours = settings.Graphs.graphhours;
                cumulus.GraphDays  = settings.Graphs.graphdays;

                // Annual Rainfall
                cumulus.RainSeasonStart = settings.AnnualRainfall.rainseasonstart;
                cumulus.YTDrain         = settings.AnnualRainfall.ytdamount;
                cumulus.YTDrainyear     = settings.AnnualRainfall.ytdyear;

                // Solar
                cumulus.SolarMinimum   = settings.Solar.solarmin;
                cumulus.RStransfactor  = settings.Solar.transfactor;
                cumulus.SunThreshold   = settings.Solar.sunthreshold;
                cumulus.UseBlakeLarsen = settings.Solar.useblakelarsen;
                cumulus.SolarCalc      = settings.Solar.solarcalc;
                cumulus.BrasTurbidity  = settings.Solar.turbidity;

                // Forecast
                cumulus.FChighpress        = settings.Forecast.highpressureextreme;
                cumulus.FClowpress         = settings.Forecast.lowpressureextreme;
                cumulus.HourlyForecast     = settings.Forecast.updatehourly;
                cumulus.UseCumulusForecast = settings.Forecast.usecumulusforecast;
                cumulus.FCpressinMB        = (settings.Forecast.pressureunit == "mb/hPa");

                // Location
                cumulus.Altitude       = settings.Location.altitude;
                cumulus.AltitudeInFeet = (settings.Location.altitudeunit == "feet");
                cumulus.LocationName   = settings.Location.sitename ?? string.Empty;
                cumulus.LocationDesc   = settings.Location.description ?? string.Empty;

                cumulus.Latitude = settings.Location.Latitude.degrees + (settings.Location.Latitude.minutes / 60.0) + (settings.Location.Latitude.seconds / 3600.0);
                if (settings.Location.Latitude.hemisphere == "South")
                {
                    cumulus.Latitude = -cumulus.Latitude;
                }

                cumulus.LatTxt = String.Format("{0}&nbsp;{1:D2}&deg;&nbsp;{2:D2}&#39;&nbsp;{3:D2}&quot;", settings.Location.Latitude.hemisphere[0], settings.Location.Latitude.degrees, settings.Location.Latitude.minutes,
                                               settings.Location.Latitude.seconds);

                cumulus.Longitude = settings.Location.Longitude.degrees + (settings.Location.Longitude.minutes / 60.0) + (settings.Location.Longitude.seconds / 3600.0);
                if (settings.Location.Longitude.hemisphere == "West")
                {
                    cumulus.Longitude = -cumulus.Longitude;
                }

                cumulus.LonTxt = String.Format("{0}&nbsp;{1:D2}&deg;&nbsp;{2:D2}&#39;&nbsp;{3:D2}&quot;", settings.Location.Longitude.hemisphere[0], settings.Location.Longitude.degrees, settings.Location.Longitude.minutes,
                                               settings.Location.Longitude.seconds);

                // Options
                cumulus.UseZeroBearing           = settings.Options.usezerobearing;
                cumulus.UseWind10MinAve          = settings.Options.calcwindaverage;
                cumulus.UseSpeedForAvgCalc       = settings.Options.usespeedforavg;
                cumulus.Humidity98Fix            = settings.Options.use100for98hum;
                cumulus.CalculatedDP             = settings.Options.calculatedewpoint;
                cumulus.CalculatedWC             = settings.Options.calculatewindchill;
                cumulus.SyncTime                 = settings.Options.syncstationclock;
                cumulus.UseCumulusPresstrendstr  = settings.Options.cumuluspresstrendnames;
                cumulus.ForceVPBarUpdate         = settings.Options.vp1minbarupdate;
                cumulus.LogExtraSensors          = settings.Options.extrasensors;
                cumulus.WS2300IgnoreStationClock = settings.Options.ignorelacrosseclock;
                cumulus.RoundWindSpeed           = settings.Options.roundwindspeeds;
                cumulus.SyncFOReads              = settings.Options.synchroniseforeads;
                cumulus.logging                 = settings.Options.debuglogging;
                cumulus.DataLogging             = settings.Options.datalogging;
                cumulus.WarnMultiple            = settings.Options.stopsecondinstance;
                cumulus.DavisReadReceptionStats = settings.Options.readreceptionstats;

                // Log rollover
                if (settings.logrollover.time == "9am")
                {
                    cumulus.RolloverHour = 9;
                }
                else
                {
                    cumulus.RolloverHour = 0;
                }

                cumulus.Use10amInSummer = settings.logrollover.summer10am;


                // log interval
                cumulus.DataLogInterval = settings.loginterval;

                // com port
                cumulus.ComportName = settings.comportname ?? string.Empty;;

                // Davis connection details
                cumulus.VP2ConnectionType             = settings.davisconn.conntype;
                cumulus.VP2IPAddr                     = settings.davisconn.tcpsettings.ipaddress ?? string.Empty;
                cumulus.VP2TCPPort                    = settings.davisconn.tcpsettings.tcpport;
                cumulus.VP2PeriodicDisconnectInterval = settings.davisconn.tcpsettings.disconperiod;

                // Units
                cumulus.WindUnit  = settings.units.wind;
                cumulus.PressUnit = settings.units.pressure;
                cumulus.TempUnit  = settings.units.temp;
                cumulus.RainUnit  = settings.units.rain;

                cumulus.SetupUnitText();

                // Station type
                if (cumulus.StationType != settings.stationtype)
                {
                    cumulus.LogMessage("Station type changed, restart required");
                    Console.WriteLine("*** Station type changed, restart required ***");
                }

                cumulus.StationType = settings.stationtype;

                // Save the settings
                cumulus.WriteIniFile();

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                cumulus.LogMessage(ex.Message);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }
            return("success");
        }
コード例 #19
0
        //public string UpdateCalibrationConfig(HttpListenerContext context)
        public string UpdateCalibrationConfig(IHttpContext context)
        {
            try
            {
                var InvC = new CultureInfo("");
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                var json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                var settings = JsonConvert.DeserializeObject <JsonCalibrationSettingsData>(json);
                // process the settings
                cumulus.LogMessage("Updating calibration settings");

                // offsets
                cumulus.PressOffset   = Convert.ToDouble(settings.offsets.pressure, InvC);
                cumulus.TempOffset    = Convert.ToDouble(settings.offsets.temperature, InvC);
                cumulus.InTempoffset  = Convert.ToDouble(settings.offsets.indoortemp, InvC);
                cumulus.HumOffset     = settings.offsets.humidity;
                cumulus.WindDirOffset = settings.offsets.winddir;
                cumulus.SolarOffset   = Convert.ToDouble(settings.offsets.solar);
                cumulus.UVOffset      = Convert.ToDouble(settings.offsets.uv, InvC);
                cumulus.WetBulbOffset = Convert.ToDouble(settings.offsets.wetbulb, InvC);

                // multipliers
                cumulus.PressMult     = Convert.ToDouble(settings.multipliers.pressure, InvC);
                cumulus.WindSpeedMult = Convert.ToDouble(settings.multipliers.windspeed, InvC);
                cumulus.WindGustMult  = Convert.ToDouble(settings.multipliers.windgust, InvC);
                cumulus.TempMult      = Convert.ToDouble(settings.multipliers.outdoortemp, InvC);
                cumulus.HumMult       = Convert.ToDouble(settings.multipliers.humidity, InvC);
                cumulus.RainMult      = Convert.ToDouble(settings.multipliers.rainfall, InvC);
                cumulus.SolarMult     = Convert.ToDouble(settings.multipliers.solar, InvC);
                cumulus.UVMult        = Convert.ToDouble(settings.multipliers.uv, InvC);
                cumulus.WetBulbMult   = Convert.ToDouble(settings.multipliers.wetbulb, InvC);

                // spike removal
                cumulus.SpikeTempDiff      = Convert.ToDouble(settings.spikeremoval.outdoortemp, InvC);
                cumulus.SpikeHumidityDiff  = Convert.ToDouble(settings.spikeremoval.humidity, InvC);
                cumulus.SpikeWindDiff      = Convert.ToDouble(settings.spikeremoval.windspeed, InvC);
                cumulus.SpikeGustDiff      = Convert.ToDouble(settings.spikeremoval.windgust, InvC);
                cumulus.SpikeMaxHourlyRain = Convert.ToDouble(settings.spikeremoval.maxhourlyrain, InvC);
                cumulus.SpikeMaxRainRate   = Convert.ToDouble(settings.spikeremoval.maxrainrate, InvC);
                cumulus.SpikePressDiff     = Convert.ToDouble(settings.spikeremoval.pressure, InvC);

                // limits
                cumulus.LimitTempHigh  = Convert.ToDouble(settings.limits.temphigh, InvC);
                cumulus.LimitTempLow   = Convert.ToDouble(settings.limits.templow, InvC);
                cumulus.LimitDewHigh   = Convert.ToDouble(settings.limits.dewhigh, InvC);
                cumulus.LimitPressHigh = Convert.ToDouble(settings.limits.presshigh, InvC);
                cumulus.LimitPressLow  = Convert.ToDouble(settings.limits.presslow, InvC);
                cumulus.LimitWindHigh  = Convert.ToDouble(settings.limits.windhigh, InvC);

                cumulus.ErrorLogSpikeRemoval = settings.log;

                // Save the settings
                cumulus.WriteIniFile();

                // Clear the spike alarm
                cumulus.SpikeAlarmState = false;

                // Log the new values
                cumulus.LogMessage("Setting new calibration values...");
                cumulus.LogOffsetsMultipliers();

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                cumulus.LogMessage(ex.Message);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }
            return("success");
        }
コード例 #20
0
        //public string UpdateCalibrationConfig(HttpListenerContext context)
        public string UpdateConfig(IHttpContext context)
        {
            var json = "";
            JsonCalibrationSettingsData settings;
            var invC = new CultureInfo("");

            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                settings = json.FromJson <JsonCalibrationSettingsData>();
            }
            catch (Exception ex)
            {
                var msg = "Error de-serializing Calibration Settings JSON: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("Calibration Data: " + json);
                context.Response.StatusCode = 500;
                return(msg);
            }

            try
            {
                // process the settings
                cumulus.LogMessage("Updating calibration settings");

                // offsets
                cumulus.Calib.Press.Offset   = Convert.ToDouble(settings.pressure.offset, invC);
                cumulus.Calib.Temp.Offset    = Convert.ToDouble(settings.temp.offset, invC);
                cumulus.Calib.InTemp.Offset  = Convert.ToDouble(settings.tempin.offset, invC);
                cumulus.Calib.Hum.Offset     = settings.hum.offset;
                cumulus.Calib.WindDir.Offset = settings.winddir.offset;
                cumulus.Calib.Solar.Offset   = Convert.ToDouble(settings.solar.offset);
                cumulus.Calib.UV.Offset      = Convert.ToDouble(settings.uv.offset, invC);
                cumulus.Calib.WetBulb.Offset = Convert.ToDouble(settings.wetbulb.offset, invC);

                // multipliers
                cumulus.Calib.Press.Mult     = Convert.ToDouble(settings.pressure.multiplier, invC);
                cumulus.Calib.WindSpeed.Mult = Convert.ToDouble(settings.windspd.multiplier, invC);
                cumulus.Calib.WindGust.Mult  = Convert.ToDouble(settings.gust.multiplier, invC);
                cumulus.Calib.Temp.Mult      = Convert.ToDouble(settings.temp.multiplier, invC);
                cumulus.Calib.Temp.Mult2     = Convert.ToDouble(settings.temp.multiplier2, invC);
                cumulus.Calib.Hum.Mult       = Convert.ToDouble(settings.hum.multiplier, invC);
                cumulus.Calib.Hum.Mult2      = Convert.ToDouble(settings.hum.multiplier2, invC);
                cumulus.Calib.Rain.Mult      = Convert.ToDouble(settings.rain.multiplier, invC);
                cumulus.Calib.Solar.Mult     = Convert.ToDouble(settings.solar.multiplier, invC);
                cumulus.Calib.UV.Mult        = Convert.ToDouble(settings.uv.multiplier, invC);
                cumulus.Calib.WetBulb.Mult   = Convert.ToDouble(settings.wetbulb.multiplier, invC);

                // spike removal
                cumulus.Spike.TempDiff      = Convert.ToDouble(settings.temp.spike, invC);
                cumulus.Spike.HumidityDiff  = Convert.ToDouble(settings.hum.spike, invC);
                cumulus.Spike.WindDiff      = Convert.ToDouble(settings.windspd.spike, invC);
                cumulus.Spike.GustDiff      = Convert.ToDouble(settings.gust.spike, invC);
                cumulus.Spike.MaxHourlyRain = Convert.ToDouble(settings.rain.spikehour, invC);
                cumulus.Spike.MaxRainRate   = Convert.ToDouble(settings.rain.spikerate, invC);
                cumulus.Spike.PressDiff     = Convert.ToDouble(settings.pressure.spike, invC);

                // limits
                cumulus.Limit.TempHigh  = Convert.ToDouble(settings.temp.limitmax, invC);
                cumulus.Limit.TempLow   = Convert.ToDouble(settings.temp.limitmin, invC);
                cumulus.Limit.DewHigh   = Convert.ToDouble(settings.dewpt.limitmax, invC);
                cumulus.Limit.PressHigh = Convert.ToDouble(settings.pressure.limitmax, invC);
                cumulus.Limit.PressLow  = Convert.ToDouble(settings.pressure.limitmin, invC);
                cumulus.Limit.WindHigh  = Convert.ToDouble(settings.gust.limitmax, invC);

                // Save the settings
                cumulus.WriteIniFile();

                // Clear the spike alarm
                cumulus.SpikeAlarm.Triggered = false;

                // Log the new values
                cumulus.LogMessage("Setting new calibration values...");
                cumulus.LogOffsetsMultipliers();

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                cumulus.LogMessage("Error setting Calibration settings: " + ex.Message);
                cumulus.LogDebugMessage("Calibration Data: " + json);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }
            return("success");
        }
コード例 #21
0
        public string UpdateConfig(IHttpContext context)
        {
            var errorMsg = "";
            var json     = "";
            JsonInternetSettingsData settings;

            context.Response.StatusCode = 200;

            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                settings = json.FromJson <JsonInternetSettingsData>();
            }
            catch (Exception ex)
            {
                var msg = "Error de-serializing Internet Settings JSON: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("Internet Data: " + json);
                context.Response.StatusCode = 500;
                return(msg);
            }


            // process the settings
            try
            {
                cumulus.LogMessage("Updating internet settings");

                // website settings
                try
                {
                    cumulus.FtpOptions.Enabled = settings.website.enabled;
                    if (cumulus.FtpOptions.Enabled)
                    {
                        cumulus.FtpOptions.Directory  = settings.website.directory ?? string.Empty;
                        cumulus.FtpOptions.Port       = settings.website.ftpport;
                        cumulus.FtpOptions.Hostname   = settings.website.hostname ?? string.Empty;
                        cumulus.FtpOptions.FtpMode    = (Cumulus.FtpProtocols)settings.website.sslftp;
                        cumulus.FtpOptions.Password   = settings.website.password ?? string.Empty;
                        cumulus.FtpOptions.Username   = settings.website.username ?? string.Empty;
                        cumulus.FtpOptions.SshAuthen  = settings.website.sshAuth ?? string.Empty;
                        cumulus.FtpOptions.SshPskFile = settings.website.pskFile ?? string.Empty;

                        cumulus.DeleteBeforeUpload = settings.website.general.ftpdelete;
                        cumulus.FTPRename          = settings.website.general.ftprename;
                        cumulus.UTF8encode         = settings.website.general.utf8encode;


                        if (cumulus.FtpOptions.FtpMode == Cumulus.FtpProtocols.FTP || cumulus.FtpOptions.FtpMode == Cumulus.FtpProtocols.FTPS)
                        {
                            cumulus.FtpOptions.AutoDetect  = settings.website.advanced.autodetect;
                            cumulus.FtpOptions.ActiveMode  = settings.website.advanced.activeftp;
                            cumulus.FtpOptions.DisableEPSV = settings.website.advanced.disableftpsepsv;
                        }

                        if (cumulus.FtpOptions.FtpMode == Cumulus.FtpProtocols.FTPS)
                        {
                            cumulus.FtpOptions.DisableExplicit  = settings.website.advanced.disableftpsexplicit;
                            cumulus.FtpOptions.IgnoreCertErrors = settings.website.advanced.ignorecerts;
                        }
                    }

                    cumulus.FtpOptions.LocalCopyEnabled = settings.website.localcopy;
                    if (cumulus.FtpOptions.LocalCopyEnabled)
                    {
                        cumulus.FtpOptions.LocalCopyFolder = settings.website.localcopyfolder;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing website settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // web settings
                try
                {
                    cumulus.RealtimeIntervalEnabled = settings.websettings.realtime.enabled;
                    if (cumulus.RealtimeIntervalEnabled)
                    {
                        cumulus.FtpOptions.RealtimeEnabled = settings.websettings.realtime.enablerealtimeftp;
                        cumulus.RealtimeInterval           = settings.websettings.realtime.realtimeinterval * 1000;
                        if (cumulus.RealtimeTimer.Interval != cumulus.RealtimeInterval)
                        {
                            cumulus.RealtimeTimer.Interval = cumulus.RealtimeInterval;
                        }

                        for (var i = 0; i < cumulus.RealtimeFiles.Length; i++)
                        {
                            cumulus.RealtimeFiles[i].Create = settings.websettings.realtime.files[i].create;
                            cumulus.RealtimeFiles[i].FTP    = cumulus.RealtimeFiles[i].Create && settings.websettings.realtime.files[i].ftp;
                            cumulus.RealtimeFiles[i].Copy   = cumulus.RealtimeFiles[i].Create && settings.websettings.realtime.files[i].copy;
                        }
                    }
                    cumulus.RealtimeTimer.Enabled = cumulus.RealtimeIntervalEnabled;
                    if (!cumulus.RealtimeTimer.Enabled || !cumulus.FtpOptions.RealtimeEnabled)
                    {
                        cumulus.RealtimeFTPDisconnect();
                    }

                    cumulus.WebIntervalEnabled = settings.websettings.interval.enabled;
                    if (cumulus.WebIntervalEnabled)
                    {
                        cumulus.FtpOptions.IntervalEnabled = settings.websettings.interval.enableintervalftp;
                        cumulus.UpdateInterval             = settings.websettings.interval.ftpinterval;
                        if (cumulus.WebTimer.Interval != cumulus.UpdateInterval * 60 * 1000)
                        {
                            cumulus.WebTimer.Interval = cumulus.UpdateInterval * 60 * 1000;
                        }

                        for (var i = 0; i < cumulus.StdWebFiles.Length; i++)
                        {
                            cumulus.StdWebFiles[i].Create = settings.websettings.interval.stdfiles.files[i].create;
                            cumulus.StdWebFiles[i].FTP    = cumulus.StdWebFiles[i].Create && settings.websettings.interval.stdfiles.files[i].ftp;
                            cumulus.StdWebFiles[i].Copy   = cumulus.StdWebFiles[i].Create && settings.websettings.interval.stdfiles.files[i].copy;
                        }

                        for (var i = 0; i < cumulus.GraphDataFiles.Length; i++)
                        {
                            cumulus.GraphDataFiles[i].Create = settings.websettings.interval.graphfiles.files[i].create;
                            cumulus.GraphDataFiles[i].FTP    = cumulus.GraphDataFiles[i].Create && settings.websettings.interval.graphfiles.files[i].ftp;
                            cumulus.GraphDataFiles[i].Copy   = cumulus.GraphDataFiles[i].Create && settings.websettings.interval.graphfiles.files[i].copy;
                        }

                        for (var i = 0; i < cumulus.GraphDataEodFiles.Length; i++)
                        {
                            cumulus.GraphDataEodFiles[i].Create = settings.websettings.interval.graphfileseod.files[i].create;
                            cumulus.GraphDataEodFiles[i].FTP    = cumulus.GraphDataEodFiles[i].Create && settings.websettings.interval.graphfileseod.files[i].ftp;
                            cumulus.GraphDataEodFiles[i].Copy   = cumulus.GraphDataEodFiles[i].Create && settings.websettings.interval.graphfileseod.files[i].copy;
                        }
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing web settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // external programs
                try
                {
                    if (settings.externalprograms != null)
                    {
                        cumulus.DailyProgram    = settings.externalprograms.dailyprogram ?? string.Empty;
                        cumulus.DailyParams     = settings.externalprograms.dailyprogramparams ?? string.Empty;
                        cumulus.ExternalProgram = settings.externalprograms.program ?? string.Empty;
                        cumulus.ExternalParams  = settings.externalprograms.programparams ?? string.Empty;
                        cumulus.RealtimeProgram = settings.externalprograms.realtimeprogram ?? string.Empty;
                        cumulus.RealtimeParams  = settings.externalprograms.realtimeprogramparams ?? string.Empty;
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing external programs: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // MQTT
                try
                {
                    cumulus.MQTT.Server           = settings.mqtt.server ?? string.Empty;
                    cumulus.MQTT.Port             = settings.mqtt.port;
                    cumulus.MQTT.UseTLS           = settings.mqtt.useTls;
                    cumulus.MQTT.Username         = settings.mqtt.username ?? string.Empty;
                    cumulus.MQTT.Password         = settings.mqtt.password ?? string.Empty;
                    cumulus.MQTT.EnableDataUpdate = settings.mqtt.dataUpdate.enabled;
                    if (cumulus.MQTT.EnableDataUpdate)
                    {
                        cumulus.MQTT.UpdateTemplate = settings.mqtt.dataUpdate.template ?? string.Empty;
                    }
                    cumulus.MQTT.EnableInterval = settings.mqtt.interval.enabled;
                    if (cumulus.MQTT.EnableInterval)
                    {
                        cumulus.MQTT.IntervalTime     = settings.mqtt.interval.time;
                        cumulus.MQTT.IntervalTemplate = settings.mqtt.interval.template ?? string.Empty;

                        cumulus.MQTTTimer.Interval = cumulus.MQTT.IntervalTime * 1000;
                        cumulus.MQTTTimer.Enabled  = cumulus.MQTT.EnableInterval && !string.IsNullOrWhiteSpace(cumulus.MQTT.IntervalTemplate);
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing MQTT settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Moon Image
                try
                {
                    cumulus.MoonImage.Enabled = settings.moonimage.enabled;
                    if (cumulus.MoonImage.Enabled)
                    {
                        cumulus.MoonImage.Size = settings.moonimage.size;
                        if (cumulus.MoonImage.Size < 10)
                        {
                            cumulus.MoonImage.Size = 10;
                        }

                        cumulus.MoonImage.Ftp = settings.moonimage.includemoonimage;
                        if (cumulus.MoonImage.Ftp)
                        {
                            cumulus.MoonImage.FtpDest = settings.moonimage.ftpdest;
                        }

                        cumulus.MoonImage.Copy = settings.moonimage.copyimage;
                        if (cumulus.MoonImage.Copy)
                        {
                            cumulus.MoonImage.CopyDest = settings.moonimage.copydest;
                        }
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Moon image settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // HTTP proxy
                try
                {
                    cumulus.HTTPProxyPassword = settings.proxies.httpproxy.password ?? string.Empty;
                    cumulus.HTTPProxyPort     = settings.proxies.httpproxy.port;
                    cumulus.HTTPProxyName     = settings.proxies.httpproxy.proxy ?? string.Empty;
                    cumulus.HTTPProxyUser     = settings.proxies.httpproxy.user ?? string.Empty;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing HTTP proxy settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // email settings
                try
                {
                    cumulus.SmtpOptions.Enabled = settings.emailsettings.enabled;
                    if (cumulus.SmtpOptions.Enabled)
                    {
                        cumulus.SmtpOptions.Server    = settings.emailsettings.server;
                        cumulus.SmtpOptions.Port      = settings.emailsettings.port;
                        cumulus.SmtpOptions.SslOption = settings.emailsettings.ssloption;
                        cumulus.SmtpOptions.RequiresAuthentication = settings.emailsettings.authenticate;
                        cumulus.SmtpOptions.User             = settings.emailsettings.user;
                        cumulus.SmtpOptions.Password         = settings.emailsettings.password;
                        cumulus.SmtpOptions.IgnoreCertErrors = settings.emailsettings.ignorecerterrors;

                        if (cumulus.emailer == null)
                        {
                            cumulus.emailer = new EmailSender(cumulus);
                        }
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Email settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // misc settings
                try
                {
                    cumulus.WebcamURL = settings.misc.webcamurl ?? string.Empty;
                    cumulus.ForumURL  = settings.misc.forumurl ?? string.Empty;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Misc settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    errorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }


                // Save the settings
                cumulus.WriteIniFile();

                cumulus.SetUpHttpProxy();
                //cumulus.SetFtpLogging(cumulus.FTPlogging);

                // Setup MQTT
                if (cumulus.MQTT.EnableDataUpdate || cumulus.MQTT.EnableInterval)
                {
                    if (!MqttPublisher.configured)
                    {
                        MqttPublisher.Setup(cumulus);
                    }
                    if (cumulus.MQTT.EnableInterval)
                    {
                        cumulus.MQTTTimer.Elapsed -= cumulus.MQTTTimerTick;
                        cumulus.MQTTTimer.Elapsed += cumulus.MQTTTimerTick;
                        cumulus.MQTTTimer.Start();
                    }
                    else
                    {
                        cumulus.MQTTTimer.Stop();
                    }
                }
                else
                {
                    cumulus.MQTTTimer.Stop();
                }
            }
            catch (Exception ex)
            {
                var msg = "Error processing Internet settings: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("Internet data: " + json);
                errorMsg += msg;
                context.Response.StatusCode = 500;
            }

            return(context.Response.StatusCode == 200 ? "success" : errorMsg);
        }
コード例 #22
0
        //public string UpdateInternetConfig(HttpListenerContext context)
        public string UpdateInternetConfig(IHttpContext context)
        {
            var ErrorMsg = "";

            context.Response.StatusCode = 200;

            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                // Start at char 5 to skip the "json:" prefix
                var json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                var settings = JsonConvert.DeserializeObject <JsonInternetSettingsData>(json);
                // process the settings
                cumulus.LogMessage("Updating internet settings");

                // website settings
                try
                {
                    cumulus.ftp_directory        = settings.website.directory ?? string.Empty;
                    cumulus.ForumURL             = settings.website.forumurl ?? string.Empty;
                    cumulus.ftp_port             = settings.website.ftpport;
                    cumulus.ftp_host             = settings.website.hostname ?? string.Empty;
                    cumulus.Sslftp               = (Cumulus.FtpProtocols)settings.website.sslftp;
                    cumulus.ftp_password         = settings.website.password ?? string.Empty;
                    cumulus.ftp_user             = settings.website.username ?? string.Empty;
                    cumulus.SshftpAuthentication = settings.website.sshAuth ?? string.Empty;
                    cumulus.SshftpPskFile        = settings.website.pskFile ?? string.Empty;
                    cumulus.WebcamURL            = settings.website.webcamurl ?? string.Empty;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing website settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // web settings
                try
                {
                    cumulus.ActiveFTPMode         = settings.websettings.activeftp;
                    cumulus.WebAutoUpdate         = settings.websettings.autoupdate;
                    cumulus.RealtimeEnabled       = settings.websettings.enablerealtime;
                    cumulus.RealtimeFTPEnabled    = settings.websettings.enablerealtimeftp;
                    cumulus.RealtimeTxtFTP        = settings.websettings.realtimetxtftp;
                    cumulus.RealtimeGaugesTxtFTP  = settings.websettings.realtimegaugestxtftp;
                    cumulus.RealtimeInterval      = settings.websettings.realtimeinterval * 1000;
                    cumulus.DeleteBeforeUpload    = settings.websettings.ftpdelete;
                    cumulus.UpdateInterval        = settings.websettings.ftpinterval;
                    cumulus.FTPRename             = settings.websettings.ftprename;
                    cumulus.IncludeStandardFiles  = settings.websettings.includestdfiles;
                    cumulus.IncludeGraphDataFiles = settings.websettings.includegraphdatafiles;
                    cumulus.IncludeMoonImage      = settings.websettings.includemoonimage;
                    cumulus.UTF8encode            = settings.websettings.utf8encode;
                    if (settings.websettings.ftplogging != cumulus.FTPlogging)
                    {
                        cumulus.FTPlogging = settings.websettings.ftplogging;
                        cumulus.SetFtpLogging(cumulus.FTPlogging);
                    }
                }
                catch (Exception ex)
                {
                    var msg = "Error processing web settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // external programs
                try
                {
                    cumulus.DailyProgram    = settings.externalprograms.dailyprogram ?? string.Empty;
                    cumulus.DailyParams     = settings.externalprograms.dailyprogramparams ?? string.Empty;
                    cumulus.ExternalProgram = settings.externalprograms.program ?? string.Empty;
                    cumulus.ExternalParams  = settings.externalprograms.programparams ?? string.Empty;
                    cumulus.RealtimeProgram = settings.externalprograms.realtimeprogram ?? string.Empty;
                    cumulus.RealtimeParams  = settings.externalprograms.realtimeprogramparams ?? string.Empty;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing external programs: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // twitter
                try
                {
                    cumulus.TwitterEnabled            = settings.twitter.enabled;
                    cumulus.TwitterInterval           = settings.twitter.interval;
                    cumulus.TwitterPW                 = settings.twitter.password ?? string.Empty;
                    cumulus.TwitterSendLocation       = settings.twitter.sendlocation;
                    cumulus.Twitteruser               = settings.twitter.user ?? string.Empty;
                    cumulus.SynchronisedTwitterUpdate = (60 % cumulus.TwitterInterval == 0);

                    cumulus.TwitterTimer.Interval = cumulus.TwitterInterval * 60 * 1000;
                    cumulus.TwitterTimer.Enabled  = cumulus.TwitterEnabled && !cumulus.SynchronisedTwitterUpdate && !String.IsNullOrWhiteSpace(cumulus.Twitteruser) && !String.IsNullOrWhiteSpace(cumulus.TwitterPW);
                }
                catch (Exception ex)
                {
                    var msg = "Error processing twitter settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // wunderground
                try
                {
                    cumulus.WundCatchUp          = settings.wunderground.catchup;
                    cumulus.WundEnabled          = settings.wunderground.enabled;
                    cumulus.SendIndoorToWund     = settings.wunderground.includeindoor;
                    cumulus.SendSRToWund         = settings.wunderground.includesolar;
                    cumulus.SendUVToWund         = settings.wunderground.includeuv;
                    cumulus.WundInterval         = settings.wunderground.interval;
                    cumulus.WundPW               = settings.wunderground.password ?? string.Empty;
                    cumulus.WundRapidFireEnabled = settings.wunderground.rapidfire;
                    cumulus.WundSendAverage      = settings.wunderground.sendavgwind;
                    cumulus.WundID               = settings.wunderground.stationid ?? string.Empty;
                    cumulus.SynchronisedWUUpdate = (!cumulus.WundRapidFireEnabled) && (60 % cumulus.WundInterval == 0);

                    cumulus.WundTimer.Interval = cumulus.WundRapidFireEnabled ? 5000 : cumulus.WundInterval * 60 * 1000;
                    cumulus.WundTimer.Enabled  = cumulus.WundEnabled && !cumulus.SynchronisedWUUpdate && !String.IsNullOrWhiteSpace(cumulus.WundID) && !String.IsNullOrWhiteSpace(cumulus.WundPW);
                }
                catch (Exception ex)
                {
                    var msg = "Error processing wunderground settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Windy
                try
                {
                    cumulus.WindyCatchUp = settings.windy.catchup;
                    cumulus.WindyEnabled = settings.windy.enabled;
                    //cumulus.WindySendSolar = settings.windy.includesolar;
                    cumulus.WindySendUV             = settings.windy.includeuv;
                    cumulus.WindyInterval           = settings.windy.interval;
                    cumulus.WindyApiKey             = settings.windy.apikey;
                    cumulus.WindyStationIdx         = settings.windy.stationidx;
                    cumulus.SynchronisedWindyUpdate = (60 % cumulus.WindyInterval == 0);

                    cumulus.WindyTimer.Interval = cumulus.WindyInterval * 60 * 1000;
                    cumulus.WindyTimer.Enabled  = cumulus.WindyEnabled && !cumulus.SynchronisedWindyUpdate && !String.IsNullOrWhiteSpace(cumulus.WindyApiKey);
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Windy settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Awekas
                try
                {
                    cumulus.AwekasEnabled            = settings.awekas.enabled;
                    cumulus.AwekasInterval           = settings.awekas.interval;
                    cumulus.AwekasLang               = settings.awekas.lang;
                    cumulus.AwekasPW                 = settings.awekas.password ?? string.Empty;
                    cumulus.AwekasUser               = settings.awekas.user ?? string.Empty;
                    cumulus.SendSolarToAwekas        = settings.awekas.includesolar;
                    cumulus.SendUVToAwekas           = settings.awekas.includeuv;
                    cumulus.SendSoilTempToAwekas     = settings.awekas.includesoiltemp;
                    cumulus.SendSoilMoistureToAwekas = settings.awekas.includesoilmoisture;
                    cumulus.SendLeafWetnessToAwekas  = settings.awekas.includeleafwetness;
                    cumulus.SendIndoorToAwekas       = settings.awekas.includeindoor;
                    cumulus.SynchronisedAwekasUpdate = (cumulus.AwekasInterval % 60 == 0);

                    cumulus.AwekasTimer.Interval = cumulus.AwekasInterval * 1000;
                    cumulus.AwekasTimer.Enabled  = cumulus.AwekasEnabled && !cumulus.SynchronisedAwekasUpdate && !String.IsNullOrWhiteSpace(cumulus.AwekasUser) && !String.IsNullOrWhiteSpace(cumulus.AwekasPW);
                }
                catch (Exception ex)
                {
                    var msg = "Error processing AWEKAS settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // WeatherCloud
                try
                {
                    cumulus.WCloudWid                = settings.weathercloud.wid ?? string.Empty;
                    cumulus.WCloudKey                = settings.weathercloud.key ?? string.Empty;
                    cumulus.WCloudEnabled            = settings.weathercloud.enabled;
                    cumulus.SendSolarToWCloud        = settings.weathercloud.includesolar;
                    cumulus.SendUVToWCloud           = settings.weathercloud.includeuv;
                    cumulus.SynchronisedWCloudUpdate = (60 % cumulus.WCloudInterval == 0);

                    //cumulus.WCloudTimer.Interval = cumulus.WCloudInterval * 60 * 1000;
                    ///cumulus.WCloudTimer.Enabled = cumulus.WCloudEnabled && !cumulus.SynchronisedWCloudUpdate && !String.IsNullOrWhiteSpace(cumulus.WCloudWid) && !String.IsNullOrWhiteSpace(cumulus.WCloudKey);
                }
                catch (Exception ex)
                {
                    var msg = "Error processing WeatherCloud settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // PWS weather
                try
                {
                    cumulus.PWSCatchUp            = settings.pwsweather.catchup;
                    cumulus.PWSEnabled            = settings.pwsweather.enabled;
                    cumulus.PWSInterval           = settings.pwsweather.interval;
                    cumulus.SendSRToPWS           = settings.pwsweather.includesolar;
                    cumulus.SendUVToPWS           = settings.pwsweather.includeuv;
                    cumulus.PWSPW                 = settings.pwsweather.password ?? string.Empty;
                    cumulus.PWSID                 = settings.pwsweather.stationid ?? string.Empty;
                    cumulus.SynchronisedPWSUpdate = (60 % cumulus.PWSInterval == 0);

                    cumulus.PWSTimer.Interval = cumulus.PWSInterval * 60 * 1000;
                    cumulus.PWSTimer.Enabled  = cumulus.PWSEnabled && !cumulus.SynchronisedPWSUpdate && !String.IsNullOrWhiteSpace(cumulus.PWSID) && !String.IsNullOrWhiteSpace(cumulus.PWSPW);
                }
                catch (Exception ex)
                {
                    var msg = "Error processing PWS weather settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // WOW
                try
                {
                    cumulus.WOWCatchUp            = settings.wow.catchup;
                    cumulus.WOWEnabled            = settings.wow.enabled;
                    cumulus.SendSRToWOW           = settings.wow.includesolar;
                    cumulus.SendUVToWOW           = settings.wow.includeuv;
                    cumulus.WOWInterval           = settings.wow.interval;
                    cumulus.WOWPW                 = settings.wow.password ?? string.Empty;;
                    cumulus.WOWID                 = settings.wow.stationid ?? string.Empty;;
                    cumulus.SynchronisedWOWUpdate = (60 % cumulus.WOWInterval == 0);

                    cumulus.WOWTimer.Interval = cumulus.WOWInterval * 60 * 1000;
                    cumulus.WOWTimer.Enabled  = cumulus.WOWEnabled && !cumulus.SynchronisedWOWUpdate && !String.IsNullOrWhiteSpace(cumulus.WOWID) && !String.IsNullOrWhiteSpace(cumulus.WOWPW);
                }
                catch (Exception ex)
                {
                    var msg = "Error processing WOW settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // CWOP
                try
                {
                    cumulus.APRSenabled            = settings.cwop.enabled;
                    cumulus.APRSID                 = settings.cwop.id ?? string.Empty;;
                    cumulus.APRSinterval           = settings.cwop.interval;
                    cumulus.SendSRToAPRS           = settings.cwop.includesolar;
                    cumulus.APRSpass               = settings.cwop.password ?? string.Empty;;
                    cumulus.APRSport               = settings.cwop.port;
                    cumulus.APRSserver             = settings.cwop.server ?? string.Empty;;
                    cumulus.SynchronisedAPRSUpdate = (60 % cumulus.APRSinterval == 0);

                    cumulus.APRStimer.Interval = cumulus.APRSinterval * 60 * 1000;
                    cumulus.APRStimer.Enabled  = cumulus.APRSenabled && !cumulus.SynchronisedAPRSUpdate && !String.IsNullOrWhiteSpace(cumulus.APRSID) && !String.IsNullOrWhiteSpace(cumulus.APRSpass);
                }
                catch (Exception ex)
                {
                    var msg = "Error processing CWOP settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // MQTT
                try
                {
                    cumulus.MQTTServer           = settings.mqtt.server ?? string.Empty;
                    cumulus.MQTTPort             = settings.mqtt.port;
                    cumulus.MQTTUseTLS           = settings.mqtt.useTls;
                    cumulus.MQTTUsername         = settings.mqtt.username ?? string.Empty;
                    cumulus.MQTTPassword         = settings.mqtt.password ?? string.Empty;
                    cumulus.MQTTEnableDataUpdate = settings.mqtt.dataUpdate.enabled;
                    cumulus.MQTTUpdateTopic      = settings.mqtt.dataUpdate.topic ?? string.Empty;
                    cumulus.MQTTUpdateTemplate   = settings.mqtt.dataUpdate.template ?? string.Empty;
                    cumulus.MQTTEnableInterval   = settings.mqtt.interval.enabled;
                    cumulus.MQTTIntervalTime     = settings.mqtt.interval.time;
                    cumulus.MQTTIntervalTopic    = settings.mqtt.interval.topic ?? string.Empty;
                    cumulus.MQTTIntervalTemplate = settings.mqtt.interval.template ?? string.Empty;

                    cumulus.MQTTTimer.Interval = cumulus.MQTTIntervalTime * 1000;
                    cumulus.MQTTTimer.Enabled  = cumulus.MQTTEnableInterval && !String.IsNullOrWhiteSpace(cumulus.MQTTIntervalTopic) && !String.IsNullOrWhiteSpace(cumulus.MQTTIntervalTemplate);
                }
                catch (Exception ex)
                {
                    var msg = "Error processing MQTT settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Moon Image
                try
                {
                    cumulus.MoonImageEnabled = settings.moonimage.enabled;
                    cumulus.MoonImageSize    = settings.moonimage.size;
                    cumulus.MoonImageFtpDest = settings.moonimage.ftpdest;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Moon image settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // HTTP proxy
                try
                {
                    cumulus.HTTPProxyPassword = settings.proxies.httpproxy.password ?? string.Empty;
                    cumulus.HTTPProxyPort     = settings.proxies.httpproxy.port;
                    cumulus.HTTPProxyName     = settings.proxies.httpproxy.proxy ?? string.Empty;
                    cumulus.HTTPProxyUser     = settings.proxies.httpproxy.user ?? string.Empty;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing HTTP proxy settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Custom HTTP
                try
                {
                    // custom seconds
                    cumulus.CustomHttpSecondsString         = settings.customhttp.customseconds.url ?? string.Empty;
                    cumulus.CustomHttpSecondsEnabled        = settings.customhttp.customseconds.enabled;
                    cumulus.CustomHttpSecondsInterval       = settings.customhttp.customseconds.interval;
                    cumulus.CustomHttpSecondsTimer.Interval = cumulus.CustomHttpSecondsInterval * 1000;
                    cumulus.CustomHttpSecondsTimer.Enabled  = cumulus.CustomHttpSecondsEnabled;
                    // custom minutes
                    cumulus.CustomHttpMinutesString        = settings.customhttp.customminutes.url ?? string.Empty;
                    cumulus.CustomHttpMinutesEnabled       = settings.customhttp.customminutes.enabled;
                    cumulus.CustomHttpMinutesIntervalIndex = settings.customhttp.customminutes.intervalindex;
                    if (cumulus.CustomHttpMinutesIntervalIndex >= 0 && cumulus.CustomHttpMinutesIntervalIndex < cumulus.FactorsOf60.Length)
                    {
                        cumulus.CustomHttpMinutesInterval = cumulus.FactorsOf60[cumulus.CustomHttpMinutesIntervalIndex];
                    }
                    else
                    {
                        cumulus.CustomHttpMinutesInterval = 10;
                    }
                    // custom rollover
                    cumulus.CustomHttpRolloverString  = settings.customhttp.customrollover.url ?? string.Empty;
                    cumulus.CustomHttpRolloverEnabled = settings.customhttp.customrollover.enabled;
                }
                catch (Exception ex)
                {
                    var msg = "Error processing Custom settings: " + ex.Message;
                    cumulus.LogMessage(msg);
                    ErrorMsg += msg + "\n\n";
                    context.Response.StatusCode = 500;
                }

                // Save the settings
                cumulus.WriteIniFile();

                cumulus.SetUpHttpProxy();
                //cumulus.SetFtpLogging(cumulus.FTPlogging);

                // Setup MQTT
                if (cumulus.MQTTEnableDataUpdate || cumulus.MQTTEnableInterval)
                {
                    if (!MqttPublisher.configured)
                    {
                        MqttPublisher.Setup(cumulus);
                    }
                    if (cumulus.MQTTEnableInterval)
                    {
                        cumulus.MQTTTimer.Elapsed -= cumulus.MQTTTimerTick;
                        cumulus.MQTTTimer.Elapsed += cumulus.MQTTTimerTick;
                        cumulus.MQTTTimer.Start();
                    }
                    else
                    {
                        cumulus.MQTTTimer.Stop();
                    }
                }
                else
                {
                    cumulus.MQTTTimer.Stop();
                }
            }
            catch (Exception ex)
            {
                cumulus.LogMessage(ex.Message);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }

            if (context.Response.StatusCode == 200)
            {
                return("success");
            }
            else
            {
                return(ErrorMsg);
            }
        }