static void InitializeObjects() { AppConfigData config = new AppConfigData(); lcdScreen = new LcdScreen(config.LcdRsPinNumber, config.LcdEPinNumber, config.LcdData0PinNumber, config.LcdData1PinNumber, config.LcdData2PinNumber, config.LcdData3PinNumber, config.LcdData4PinNumber, config.LcdData5PinNumber, config.LcdData6PinNumber, config.LcdData7PinNumber ); alarm = new Alarm(new Diode(config.DiodePinNumber), new Buzzer(config.BuzzerPinNumber), new Button(config.ButtonPinNumber)); thermometer = new Thermometer(config.DevicesDirectoryPath, config.ThermometerAddress, config.ContentFileName); dhtSensor = new DHT(config.DHTSensorPinNumber); dhtData = new DHTData(); temperatureThreshold = config.TemperatureThreshold; }
public JoinChildDtoResponse(DHT dht, List <ValueDtoResponse> data) { RangeMin = dht.HashRange.Min.ToString(); RangeMax = dht.HashRange.Max.ToString(); Child = dht.Child; Data = data; }
private static async void ThreadBody(ModuleClient moduleClient) { var dht = new DHT(Pi.Gpio.Pin07, DHTSensorTypes.DHT11); //int messageCount = 0; while (true) { try { var htData = dht.ReadData(); var tempData = new MessageBody { Temperature = htData.TempCelcius, Humidity = htData.Humidity, TimeCreated = DateTime.UtcNow, Identifier = "HmtSensor" }; string dataBuffer = JsonConvert.SerializeObject(tempData); var eventMessage = new Message(Encoding.UTF8.GetBytes(dataBuffer)); eventMessage.Properties.Add("batchId", Guid.NewGuid().ToString()); Console.WriteLine($"Sending message - Body: [{dataBuffer}]"); await moduleClient.SendEventAsync("temperatureOutput", eventMessage); } catch (DHTException) { } await Task.Delay(10000); //messageCount++; } }
public async Task <IActionResult> Post([FromBody] DHT dt) { try { if (dt == null) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var data = await _repository.Add(dt); return(Ok(data)); } catch (Exception e) { return(BadRequest()); throw e; } }
public ActionResult <string> Get(int id) { //Sensor TH DHT11 var dht = new DHT(22); var readFromDHT11 = dht.ReadData(); var currentDateTime = DateTime.Now; return(Ok($"Temp= {readFromDHT11.TempCelcius} and Hum= {readFromDHT11.Humidity} , DateTime= {currentDateTime}")); }
public Condition Get() { //DHT11 sensor initialize at GPIO 17 var dhtLocalLivingRoom = new DHT(Pi.Gpio[P1.Gpio18], DHTSensorTypes.DHT11); var sensorData = dhtLocalLivingRoom.ReadData(); return(new Condition { SensorName = "LivingRoom1", Temperature = sensorData.TempCelcius, Humidity = sensorData.Humidity, TimeStamp = DateTime.Now }); }
public IActionResult Get() { var dhtLocalLivingRoom = new DHT(Pi.Gpio[P1.Gpio18], DHTSensorTypes.DHT11); var sensorData = dhtLocalLivingRoom.ReadData(); var lvRoomSensor1 = new Condition { SensorName = "LivingRoom1", Temperature = sensorData.TempCelcius, Humidity = sensorData.Humidity, TimeStamp = DateTime.Now }; _conditionRepository.insertCondition(lvRoomSensor1); return(Ok(StatusCode(200))); }
public async Task <IActionResult> CheckDHT() { string responseMessage = ""; string clientAdress = Constants.Constants.NODEMCU_IP_ADDRESS; int timeout = 10; var client = new HttpClient() { BaseAddress = new Uri(clientAdress), Timeout = TimeSpan.FromSeconds(timeout) }; DHT dht = new DHT(); try { HttpResponseMessage response = await client.GetAsync(clientAdress + "/values"); response.EnsureSuccessStatusCode(); responseMessage = await response.Content.ReadAsStringAsync(); if (response != null) { dht = JsonConvert.DeserializeObject <DHT>(responseMessage); } } catch (HttpRequestException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", e.Message); responseMessage = e.Message; } //box id will be changed in the future dht.BoxId = 1; dht.MeasureTime = DateTime.Now; dht.CalledBy = "user"; _context.DHTs.Add(dht); _context.SaveChanges(); return(Json(responseMessage)); }
static void Main(string[] args) { _programName = AppDomain.CurrentDomain.FriendlyName; Console.WriteLine($"Starting {_programName}.\n"); WriteToLogFile($"Starting {_programName}."); try { var dht = new DHT(Pi.Gpio.Pin07, DHTSensorTypes.DHT11); while (true) { try { var d = dht.ReadData(); Console.WriteLine(DateTime.UtcNow); Console.WriteLine(" temp: " + d.TempCelcius); Console.WriteLine(" hum: " + d.Humidity); } catch (DHTException) { } Thread.Sleep(10000); } } catch (Exception e) { Console.Write(e.Message + " - " + e.StackTrace); } //GetConfigurationSettings(); //CreateDatabaseAndTables(); //SetupPin00AsTippingListener(); //Console.WriteLine("\nPress any key to exit ..."); //Console.ReadKey(); Console.WriteLine($"\nEnding {_programName}."); WriteToLogFile($"Ending {_programName}."); }
private void DoWork(object state) { using (var scope = _scopeFactory.CreateScope()) { var dhtRepository = scope.ServiceProvider.GetRequiredService <IDHTRepository>(); try { DHT lastRecord = dhtRepository.GetLastRecord(); _hubContext.Clients.All.BroadcastData(lastRecord); } catch (Exception e) { _logger.LogInformation("Error occured in DHT data logging: {e}", e.GetType().Name); } } }
public async Task <DHT> GetBoxData() { string responseMessage = ""; string clientAdress = Constants.Constants.NODEMCU_IP_ADDRESS; int timeout = 10; var client = new HttpClient() { BaseAddress = new Uri(clientAdress), Timeout = TimeSpan.FromSeconds(timeout) }; DHT dht = new DHT(); try { HttpResponseMessage response = await client.GetAsync(clientAdress + "/values"); response.EnsureSuccessStatusCode(); responseMessage = await response.Content.ReadAsStringAsync(); if (response != null) { dht = JsonConvert.DeserializeObject <DHT>(responseMessage); } } catch (HttpRequestException e) { responseMessage = e.Message; } //box id will be changed in the future dht.BoxId = 1; dht.MeasureTime = DateTime.Now; dht.CalledBy = "service"; return(dht); }
public async Task <List <DHT> > UpdateSettings(int oldId, DHTConfig newDHT) { var dHTs = GetRowsBySensorId(oldId); foreach (var oldDht in dHTs) { DHT dht = new DHT(); dht = oldDht; dht.BoxId = newDHT.BoxId; dht.DeviceId = newDHT.NewId; dht.Device = newDHT.Device; dht.DateModified = newDHT.DateModified; _context.DHTs.Update(dht); _context.SaveChanges(); } var results = await _context.DHTs.ToListAsync(); return(results); }
public async Task <ActionResult> GetCurrentValue() { string responseMessage = ""; string clientAdress = Constants.Constants.NODEMCU_IP_ADDRESS; int timeout = 10; var client = new HttpClient() { BaseAddress = new Uri(clientAdress), Timeout = TimeSpan.FromSeconds(timeout) }; DHT dht = new DHT(); try { HttpResponseMessage response = await client.GetAsync(clientAdress + "/values"); response.EnsureSuccessStatusCode(); responseMessage = await response.Content.ReadAsStringAsync(); if (response != null) { dht = JsonConvert.DeserializeObject <DHT>(responseMessage); } } catch (HttpRequestException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", e.Message); responseMessage = e.Message; } dht.MeasureTime = DateTime.Now; return(Json(dht)); }
private async void DoWork(object state) { using (var scope = _scopeFactory.CreateScope()) { var dbContext = scope.ServiceProvider.GetRequiredService <HomeContext>(); try { DHT dhtRecord = await GetBoxData(); dbContext.Add(dhtRecord); //LightSensor lightSensorRecord = await GetLightSensorData(); //dbContext.Add(lightSensorRecord); dbContext.SaveChanges(); } catch (Exception e) { _logger.LogInformation("Error occured in DHT data logging: {e}", e.GetType().Name); } } }