Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DHT22 libmDot-mbed5
Fork of mDot_LoRa_Connect_ABPA_DHT22_sleep by
Diff: main.cpp
- Revision:
- 12:8e9badbc7314
- Parent:
- 11:45465d7cff1f
- Child:
- 13:dced485e5e95
diff -r 45465d7cff1f -r 8e9badbc7314 main.cpp --- a/main.cpp Mon Aug 28 00:42:34 2017 +0000 +++ b/main.cpp Thu May 17 00:09:06 2018 +0000 @@ -24,6 +24,8 @@ 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 /* @@ -33,11 +35,11 @@ app sess key: d6f28430da4035273b9e3c07eb30c0dd */ //device address -static uint8_t network_address[] = { 0x07, 0x23, 0x89, 0xf7 }; +static uint8_t network_address[] = { 0x06, 0xf0, 0xa4, 0x08 }; //network session key -static uint8_t network_session_key[] = { 0xb3, 0x5a, 0xca, 0x73, 0xd2, 0x83, 0x99, 0x6d, 0xc3, 0xcb, 0xc0, 0x80, 0x3a, 0xf0, 0x45, 0x47 }; +static uint8_t network_session_key[] = { 0x93, 0xb7, 0xbd, 0xfc, 0xc6, 0x70, 0x4f, 0x60, 0x5b, 0xf8, 0x5a, 0xca, 0xb6, 0x78, 0xea, 0x69 }; //application sesssion or data session key -static uint8_t data_session_key[] = { 0xd6, 0xf2, 0x84, 0x30, 0xda, 0x40, 0x35, 0x27, 0x3b, 0x9e, 0x3c, 0x07, 0xeb, 0x30, 0xc0, 0xdd }; +static uint8_t data_session_key[] = { 0x12, 0xf5, 0xb8, 0x32, 0x26, 0xcb, 0xa0, 0x9e, 0xfb, 0x59, 0x47, 0x7f, 0x6e, 0x66, 0xfd, 0x2f }; static uint8_t frequency_sub_band = 2; //VFI static bool public_network = true; //enable receipt of ackknowledge packets 0 = No, 1 = Yes @@ -136,18 +138,39 @@ 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); wait_ms(100); float ldr2 = a0.read() * 1000; + //printf("%d\n", ldr2); wait_ms(100); float ldr3 = a0.read() * 1000; + //printf("%d\n", ldr3); wait_ms(100); //average the multiple readings + float ldr = (ldr1 + ldr2 + ldr3) / 3; + + logInfo("All light readings taken"); + logInfo("Starting Moisture readings:"); + + //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 @@ -162,7 +185,9 @@ string l_str = ToString(ldr); string h_str = ToString(h); string t_str = ToString(t); - string output = "L:" + l_str + " H:" + h_str + " T:" + t_str; + string m_str = ToString(moistF); + string output = "L:" + l_str + " H:" + h_str + " T:" + t_str + "M:" + m_str; + //serial output for debugging logInfo("Sending %s", output.c_str()); @@ -173,9 +198,10 @@ //now send send_data(data); + logInfo("Data sent!"); // go to sleep and wake up automatically sleep_time seconds later - uint32_t sleep_time = 60; + uint32_t sleep_time = 20; //false is "don't deep sleep" - mDot doesn't do that dot->sleep(sleep_time, mDot::RTC_ALARM, false); }