Skip to content

Commit

Permalink
Merge pull request #21 from floodsense/maxbotix-serial-v3
Browse files Browse the repository at this point in the history
Maxbotix serial v3
  • Loading branch information
jatinpalchuri authored Jun 9, 2021
2 parents f832ff9 + 57195f5 commit 907d0cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
17 changes: 11 additions & 6 deletions src/lorawan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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);
}
Expand Down
14 changes: 2 additions & 12 deletions src/maxbotix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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..."));
Expand Down

0 comments on commit 907d0cd

Please sign in to comment.