diff --git a/README.md b/README.md index 5b2d95d7..23b0e7dc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +# This repository is updated for TTN v3 download this library and also remove the old lmic library from arduino libraries and download the latest library from[here](https://github.com/mcci-catena/arduino-lmic) # FloodSense Sensor Technical Documentation [This repository](https://github.com/floodsense/floodsense_sensor) contains the source code for the Floodsense sensor which uses ultrasonic sensor technology to detect floods and send the data over LoRa using LoRaWAN protocol. [Here](https://github.com/floodsense/sensor_experiments) is the experiments repo containing technical documentation, analysis and additional support related to this library. diff --git a/src/lorawan.cpp b/src/lorawan.cpp index a7d906ce..c7d2db6e 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -13,7 +13,8 @@ unsigned int TX_INTERVAL; unsigned char cfg_packet[7]; unsigned char lora_packet[5]; -bool TX_COMPLETED = false; // Set to false on start and after sleep; is set to true when an uplink is successful +bool TX_COMPLETED = false; + // Set to false on start and after sleep; is set to true when an uplink is successful bool UPDATE_CONFIG = true; // Set to true at start and when there is a change in sensor cfg; used to send sensor cfg via uplink void os_getArtEui (u1_t* buf) { @@ -442,15 +443,12 @@ void prepare_packet(void) { /* LoraWAN uplink packet format | Error flags | Battery Level | Ultrasonic reading | | 1 byte | 2 bytes | 2 bytes | - | Ultrasonic reading | | 2 bytes | | high byte | low byte | - | Battery Level | | 2 bytes | | high byte | low byte | - |------------------------------------------------------------ Error Flags ----------------------------------------------------------------| | bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 | | Used only for CFG update (all other bits are high) | | | | | | | SD error flag | @@ -495,13 +493,20 @@ void prepare_packet(void) { void lorawan_runloop_once() { os_runloop_once(); - if ( !os_queryTimeCriticalJobs(ms2osticksRound((TX_INTERVAL * 1000) - 1000 )) && TX_COMPLETED == true) { + //&& TX_COMPLETED == true + //!(LMIC.opmode & OP_TXRXPEND) + if ( !os_queryTimeCriticalJobs(ms2osticksRound(8000) ) && TX_COMPLETED == true ) { TX_COMPLETED = false; // This means the previous TX is complete and also no Critical Jobs pending in LMIC Serial.println("About to go to deep sleep and no critical jobs"); + //delay(30000); gotodeepsleepnow(TX_INTERVAL); Serial.println("Im awake and TX_COMPLETED is set to false"); - // Prepare a packet in relaxed setiing + while(LMIC.opmode & OP_TXRXPEND){ + os_runloop_once(); + } + + //Prepare a packet in relaxed setiing prepare_packet(); os_setCallback(&sendjob, do_send); } diff --git a/src/maxbotix.cpp b/src/maxbotix.cpp index d05b85fc..632acb57 100644 --- a/src/maxbotix.cpp +++ b/src/maxbotix.cpp @@ -19,19 +19,15 @@ void setup_maxbotix(unsigned int mode=2, unsigned int sampling_rate=250 , unsign digitalWrite(triggerPin, LOW); Serial1.begin(9600); Serial.println("Sensor Settings:"); - writeToSDCard(String("Sensor Settings:")); sensorMode = mode; Serial.print(" Sensor mode: "); Serial.println(sensorMode); - writeToSDCard(String(" Sensor mode: "+ sensorMode)); sensor_sampling_rate = sampling_rate; Serial.print(" Sensor sampling rate: "); Serial.println(sensor_sampling_rate); - writeToSDCard(String(" Sensor sampling rate: "+ sensor_sampling_rate)); sensor_numberOfReadings = numberOfReadings; Serial.print(" Number of readings per measurement: "); Serial.println(sensor_numberOfReadings); - writeToSDCard(String(" Number of readings per measurement: "+ sensor_numberOfReadings)); } uint16_t sensor_singleread(void) { @@ -91,25 +87,19 @@ uint16_t read_sensor_using_modes(unsigned int sensorMode, unsigned int sensor_sa case 1: // Mean distance = mean(readings_arr, n, sensor_numberOfReadings); - Serial.print("Mean is: "); Serial.println(distance); - writeToSDCard(String("Mean is: " + distance)); break; case 2: // Median distance = median(readings_arr, n, sensor_numberOfReadings); - Serial.print("Median is: "); Serial.println(distance); - writeToSDCard(String("Median is: " + distance)); break; case 3: // Mode distance = mode(readings_arr, n, sensor_numberOfReadings); - Serial.print("Mode is: "); Serial.println(distance); - writeToSDCard(String("Mode is: " + distance)); + break; default: // Single Pulse-In single reading distance = sensor_singleread(); - Serial.print("Default single reading is: "); Serial.println(distance); - writeToSDCard(String("Default single reading is: " + distance)); + break; } Serial.println("Cleaning measurements array..."); writeToSDCard(String("Cleaning measurements array..."));