Home Alert System
Dependencies: PWM_Tone_Library DHT
Revision 4:2d12380f4578, committed 2019-03-07
- Comitter:
- ethaderu
- Date:
- Thu Mar 07 17:10:28 2019 +0000
- Parent:
- 3:78f223d34f36
- Child:
- 5:569a4894abc1
- Commit message:
- 3/7
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Mar 05 02:34:44 2019 +0000 +++ b/main.cpp Thu Mar 07 17:10:28 2019 +0000 @@ -8,7 +8,7 @@ // Data in pins AnalogIn loudness_sensor(A0); -DHT DHT_sensor(D1, DHT11); //(DATA_PIN, BOARD_TYPE) +DHT DHT_sensor(D0, DHT11); //(DATA_PIN, BOARD_TYPE) // Set Sensor Stream details char deviceId[] = "9728a93b2632b9676d520568e64b5693"; //// Device you want to push to @@ -21,9 +21,9 @@ { pc.baud(115200); - // Intialize Ethernet connection + // Intialize and connect to Ethernet connection EthernetInterface eth; - printf("Now waiting for eth.init()\r\n"); + printf("Waiting for eth.init()\r\n"); eth.init(); eth.connect(); printf("Success. Connected! Device IP Address is %s\r\n", eth.getIPAddress()); @@ -36,63 +36,71 @@ // Data vars float hum_rms = 0.0f; float temp_rms = 0.0f; - float loud_rms = 0.0; + float loud_rms = 0.0f; - // Test connection/return value - /*if(m2xClient.updateStreamValue(deviceId, streamLou, loud_rms) == -1) - { - printf("Error: (m2xClient.updateStreamValue(deviceId, streamLou, loud_rms) == -1) is true\r\n\r\n" - "\tSomething is wrong.\r\n"); - exit(EXIT_FAILURE); - } - printf("test: send() returned %d\r\n", ret);*/ - - // Degree character ASCII + // Degree character 'º' ASCII value char degree_char = 167; - printf("Begin Data Acquisition from Loudness Sensor...\r\n\r\n"); - wait(.5); + int DHT_error = 0; - if(DHT_sensor.ReadTemperature(FARENHEIT) == 32 && DHT_sensor.ReadHumidity() == 0) - { - printf("Updating DHT.\r\n"); - wait(2); - temp_rms = DHT_sensor.ReadTemperature(FARENHEIT); - hum_rms = DHT_sensor.ReadHumidity(); - } + printf("Begin data acquisition from sensors and sending data to M2X...\r\n\r\n"); + wait(.5); while(1) { + wait_ms(250); + DHT_error = DHT_sensor.readData(); + + // Get data - if(DHT_sensor.ReadTemperature(FARENHEIT) != 32 && DHT_sensor.ReadHumidity() != 0) + if(DHT_error != 0) { temp_rms = DHT_sensor.ReadTemperature(FARENHEIT); hum_rms = DHT_sensor.ReadHumidity(); - } - else - { - // Do nothing (Keep temp and humidity values the same - // No data is being read. The sensor only reads data about every 1 second - } + } // end if + loud_rms = 100*loudness_sensor.read(); - printf("------------------------------------------------------------------------\r\n"); + // High temperature + if(temp_rms >= 77 && temp_rms < 80) + { + printf("------------------------------------------------------------------------\r\n"); + printf("The temperature is over 77%cF, turn on the AC!\r\n", degree_char); + } + else if(temp_rms >= 80) + { + printf("------------------------------------------------------------------------\r\n"); + printf("The temperature is over 80%cF! Call 911 and get home immediately!\r\n", degree_char); + } - // Print data - printf("Temperature: %4.2f%cF\n", temp_rms, degree_char); // "0000.00*F" - printf("Humidity: %4.2f%%\n", hum_rms); // "0000.00%" - printf("Loudness: %.2f%%\r\n", loud_rms); // "000.00%" + // High humidity + if(hum_rms >= 50) + { + printf("------------------------------------------------------------------------\r\n"); + printf("The humidity is over 50%%, turn on the AC!\r\n"); + } - ret = m2xClient.updateStreamValue(deviceId, streamHum, hum_rms); - printf("send() returned %d\r\n", ret); - ret = m2xClient.updateStreamValue(deviceId, streamTem, temp_rms); - printf("send() returned %d\r\n", ret); - ret = m2xClient.updateStreamValue(deviceId, streamLou, loud_rms); - printf("send() returned %d\r\n", ret); + // Noise detected + if(loud_rms > 99) + { + printf("------------------------------------------------------------------------\r\n"); + printf("There's noise in the home! Could be an intruder!\r\n"); + } + - wait_ms(100); - } - + /*// Print data + printf("Tmeperature: %4.2f%cF\n", temp_rms, degree_char); // "0000.00ºF" + printf("Humidity: %4.2f\n", hum_rms); // "0000.00%" + printf("Loudness: %.2f%%\r\n", loud_rms); // "000.00%" + */ + // Send data to M2X Client, and print return value + m2xClient.updateStreamValue(deviceId, streamHum, hum_rms); + //printf("send() returned %d\r\n", ret); + m2xClient.updateStreamValue(deviceId, streamTem, temp_rms); + //printf("send() returned %d\r\n", ret); + m2xClient.updateStreamValue(deviceId, streamLou, loud_rms); + //printf("send() returned %d\r\n", ret); + } // end while() -} +} // end main()