예제 #1
0
        public ActionResult Arduinos(int? id)
        {
            ViewBag.Title = "Arduinos";
            ViewBag.TimeZoneOffset = ConfigurationManager.AppSettings["TimeZoneOffset"].ToInt(0);

            SQLServer dataAccess = new SQLServer();
            var model = new ArduinosViewModel(dataAccess.GetArduinos());

            return View("Arduinos", model);
        }
예제 #2
0
 // GET api/eventlast/100
 public List<Event> Get(int count)
 {
     SQLServer dataAccess = new SQLServer();
     return dataAccess.GetEventsLast(count);
 }
예제 #3
0
 // GET api/last/60
 public List<SensorData> Get(int count)
 {
     SQLServer dataAccess = new SQLServer();
     return dataAccess.GetSensorDataLast(count);
 }
예제 #4
0
        public void Initialize()
        {
            ConsoleStatus("Initialization Starting...");

            database = new SQLServer();
            string logPath = "ArduinoMonitor.log";

            //Set Application Defaults
            ArduinoID = 1;
            LogToFile = true;
            LogToDatabase = true;
            RetryEmailOnFailure = true;
            database.ConnectionString = "Data Source=MSP-SQLSERVER;Initial Catalog=ArduinoMonitor;User ID=ArduinoMonitor;Password=password;";

            LowThreshold = 62;
            HighThreshold = 80;
            EmailHysteresis = new TimeSpan(0, 5, 0);

            string portName = "COM4";
            int portBaud = 9600;

            if (UseConfigurationFile && LoadConfigurationFile())
            {
                try
                {
                    ArduinoID = int.Parse(appSettings["Arduino_ID"].Value);
                    database.ConnectionString = connectionStrings["ArduinoMonitor"].ConnectionString;

                    //COM Port
                    portName = appSettings["COM_Port"].Value;
                    portBaud = int.Parse(appSettings["COM_BaudRate"].Value);
                    SendDTR = bool.Parse(appSettings["COM_SendDTR"].Value);

                    //Logging
                    LogToDatabase = bool.Parse(appSettings["Log_ToDatabase"].Value);
                    LogToFile = bool.Parse(appSettings["Log_ToFile"].Value);
                    logPath = appSettings["Log_FileName"].Value;
                    LogInterval = new TimeSpan(0, 0, int.Parse(appSettings["Log_Interval_s"].Value));
                    InitializeWait = new TimeSpan(0, 0, int.Parse(appSettings["Log_Initialize_Wait_s"].Value));

                    //Threshold
                    CheckInterval = new TimeSpan(0, 0, int.Parse(appSettings["Check_Interval_s"].Value));
                    LowThreshold = decimal.Parse(appSettings["Low_Threshold"].Value);
                    HighThreshold = decimal.Parse(appSettings["High_Threshold"].Value);

                    //Email
                    EnableEmail = bool.Parse(appSettings["Email_Enable"].Value);
                    Email.FromAddress = appSettings["Email_From"].Value;
                    Email.SMTPServer = appSettings["Email_SMTP_Server"].Value;
                    Email.SMTPPort = int.Parse(appSettings["Email_SMTP_Port"].Value);
                    Recipients = appSettings["Email_Recipients"].Value;
                    EmailHysteresis = new TimeSpan(0, int.Parse(appSettings["Email_Hysteresis_m"].Value), 0);
                    RetryEmailOnFailure = bool.Parse(appSettings["Email_RetryOnFailure"].Value);

                    ConfigurationWatch = bool.Parse(appSettings["Configuration_Watch"].Value);
                }
                catch (Exception ex)
                {
                    ConsoleError("Could not load configuration settings: {0}", ex.Message);
                }
            }

            if (LogToFile)
            {
                //Open and Configure Log File
                logFile = File.AppendText(logPath);
                logFile.AutoFlush = true;
            }

            if (ConfigurationWatch)
            {
                // Create a new FileSystemWatcher and set its properties.
                watcher = new FileSystemWatcher();
                watcher.Path = Path.GetDirectoryName(configFile);
                watcher.Filter = Path.GetFileName(configFile);

                /* Watch for changes in LastAccess and LastWrite times, and
                   the renaming of files or directories. */
                watcher.NotifyFilter = NotifyFilters.LastWrite;
                // Only watch text files.
                watcher.Filter = "*.config";

                // Add event handlers.
                watcher.Changed += ConfigurationChanged;

                // Begin watching.
                watcher.EnableRaisingEvents = true;
            }

            //Configure and Open Serial Port
            System.ComponentModel.IContainer components = new System.ComponentModel.Container();
            serialPort = new SerialPort(components) {PortName = portName, BaudRate = portBaud};

            serialPort.Open();
            if (!serialPort.IsOpen)
            {
                LogError(String.Format("Cannot open Serial Port {0}", portName));

                return;
            }

            //When true, resets the Arduino when application begins.
            serialPort.DtrEnable = SendDTR;
            //Callback for data from the Arduino
            serialPort.DataReceived += DataReceived;

            //Successful Initialization
            LogStatus("Initialization Successful", EventType.Initialized);
        }
예제 #5
0
 // GET api/recent
 public List<SensorData> Get()
 {
     SQLServer dataAccess = new SQLServer();
     return dataAccess.GetSensorDataRecent();
 }
예제 #6
0
 // GET api/arduinos/60
 public List<Arduino> Get(int count)
 {
     SQLServer dataAccess = new SQLServer();
     return dataAccess.GetArduinos();
 }
예제 #7
0
 // GET api/eventrecent
 public List<Event> Get()
 {
     SQLServer dataAccess = new SQLServer();
     return dataAccess.GetEventsRecent();
 }