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); }
// GET api/eventlast/100 public List<Event> Get(int count) { SQLServer dataAccess = new SQLServer(); return dataAccess.GetEventsLast(count); }
// GET api/last/60 public List<SensorData> Get(int count) { SQLServer dataAccess = new SQLServer(); return dataAccess.GetSensorDataLast(count); }
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); }
// GET api/recent public List<SensorData> Get() { SQLServer dataAccess = new SQLServer(); return dataAccess.GetSensorDataRecent(); }
// GET api/arduinos/60 public List<Arduino> Get(int count) { SQLServer dataAccess = new SQLServer(); return dataAccess.GetArduinos(); }
// GET api/eventrecent public List<Event> Get() { SQLServer dataAccess = new SQLServer(); return dataAccess.GetEventsRecent(); }