Code for the Reed Switch on an mDot
Dependencies: DHT22 libmDot-mbed5
Revision 14:c05bcdee1483, committed 2018-06-12
- Comitter:
- lootspk
- Date:
- Tue Jun 12 02:38:01 2018 +0000
- Parent:
- 13:dced485e5e95
- Commit message:
- Gate Monitor Code
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r dced485e5e95 -r c05bcdee1483 main.cpp --- a/main.cpp Thu May 17 02:09:26 2018 +0000 +++ b/main.cpp Tue Jun 12 02:38:01 2018 +0000 @@ -19,13 +19,10 @@ #include <vector> #include <algorithm> #include <sstream> - - //dht 22 pin (D6 on UDK 2) - DHT22 dht22(PA_1); + //analogue ldr pin (A0 on UDK 2) AnalogIn a0(PB_1); - //Analogue soil moisture pin - AnalogIn a2(PC_1); + // these options must match the settings on your Conduit /* @@ -35,11 +32,11 @@ app sess key: f42ea6890802d8f2c3e9d0d9f37c80a6 */ //device address -static uint8_t network_address[] = { 0x06, 0x4a, 0xc4, 0x5b }; +static uint8_t network_address[] = { 0x06, 0x10, 0x9f, 0xb0 }; //network session key -static uint8_t network_session_key[] = { 0x55, 0x26, 0xfe, 0x0a, 0x28, 0xa9, 0x74, 0xeb, 0x07, 0x0f, 0x7b, 0x45, 0x04, 0x33, 0xc3, 0x5c }; +static uint8_t network_session_key[] = { 0x04, 0xb9, 0xb4, 0x7f, 0x20, 0xdb, 0x3a, 0xa3, 0x8f, 0xf5, 0xef, 0xd1, 0x39, 0x02, 0xde, 0x5e }; //application sesssion or data session key -static uint8_t data_session_key[] = { 0xf4, 0x2e, 0xa6, 0x89, 0x08, 0x02, 0xd8, 0xf2, 0xc3, 0xe9, 0xd0, 0xd9, 0xf3, 0x7c, 0x80, 0xa6 }; +static uint8_t data_session_key[] = { 0x92, 0x57, 0xa7, 0xe4, 0x2e, 0x47, 0x04, 0x54, 0x5c, 0xed, 0x0a, 0xbe, 0x5a, 0x99, 0xcd, 0xf9 }; static uint8_t frequency_sub_band = 2; //VFI static bool public_network = true; //enable receipt of ackknowledge packets 0 = No, 1 = Yes @@ -138,55 +135,33 @@ wait(5); //init data variable std::vector<uint8_t> data; - logInfo("Staring Light Readings:"); - //read LDR - //read LDR as float (0.0-1.0, multiply by 1000) - //read multiple times - this just smoothes the value out a little bit - float ldr1 = a0.read() * 1000; - //printf("%d\n", ldr1); + logInfo("Starting reed sensor readings"); + float reed1 = a0.read() * 10; wait_ms(100); - float ldr2 = a0.read() * 1000; - //printf("%d\n", ldr2); + float reed2 = a0.read() * 10; wait_ms(100); - float ldr3 = a0.read() * 1000; - //printf("%d\n", ldr3); + float reed3 = a0.read() * 10; wait_ms(100); - //average the multiple readings - float ldr = (ldr1 + ldr2 + ldr3) / 3; - - logInfo("All light readings taken"); - logInfo("Starting Moisture readings:"); + float reedFinal = (reed1 + reed2 + reed3)/3; + logInfo("Reed sensor readings taken"); - //read sensor - //read multiple times - this just smoothes the value out a little bit - float moist1 = a2.read() * 1023; - wait_ms(100); - float moist2 = a2.read() * 1023; - wait_ms(100); - float moist3 = a2.read() * 1023; - wait_ms(100); - //average the multiple readings - float moistF = (moist1 + moist2 + moist3) / 3; - - logInfo("All Moisture readings taken"); - logInfo("Starting Temp and Humidity readings"); - - //read DHT22 - //get dht22 sample - int error = dht22.sample(); - //sampling is a little slow - give it time - wait_ms(100); - //it's required to divide these values by ten for some reason - float h = (float)dht22.getHumidity() / 10; - float t = (float)dht22.getTemperature() / 10; + if (reedFinal <= 0.1) + { + logInfo("/n"); + logInfo("Gate is Closed!"); + logInfo("/n"); + } + else + { + logInfo("/n"); + logInfo("Gate is Open!"); + logInfo("/n"); + } //build our output string now - string l_str = ToString(ldr); - string h_str = ToString(h); - string t_str = ToString(t); - string m_str = ToString(moistF); - string output = "L:" + l_str + " H:" + h_str + " T:" + t_str + "M:" + m_str; + string reed_str = ToString(reedFinal); + string output = "Reed Switch Reading:" + reed_str; //serial output for debugging @@ -201,7 +176,7 @@ logInfo("Data sent!"); // go to sleep and wake up automatically sleep_time seconds later - uint32_t sleep_time = 20; + uint32_t sleep_time = 7; //false is "don't deep sleep" - mDot doesn't do that dot->sleep(sleep_time, mDot::RTC_ALARM, false); }