Commit 4ffe911b authored by Patrick's avatar Patrick

with arduino formatted gsm-ultrasound sketch

parent 4e41cafd
# gsm-ultrasound
Arduino UNO sketch for collecting ultrasound stage readings from a red-peg shield, at ordinal times; then batch and send those readings to a teal-mallet server via an Arduino GSM shield.
The sketch assumes O2 sim card, the following lines will need to be added for another provider:
```
// PIN Number
#define PIN_NUMBER ((char*)"") // with no sim card pin
// APN data
#define GPRS_APN ((char*)"mobile.o2.co.uk") // for O2
#define GPRS_LOGIN ((char*)"o2web") // for O2
#define GPRS_PASSWORD ((char*)"password") // for O2
```
## Settings
From the available settings:
Set the sensor to river bed distance, plus any static offset for the readings, in mm
```
#define MAX_DEPTH 15000 // sensor to bed depth in mm
#define OFFSET 0 // gauge offset in mm
```
The ordinal should be left at 15 minute multiples, and the maximum successful measurement buffer on the UNO is 11. The number to send must be less than the number of stored measurement, but can be reduced to send more frequently, at a cost to the battery life.
```
#define ORDINAL_INTERVAL 15 // ordinal minutes (0,15,30,45)
#define NUM_MMNT 11 // measurement buffer length
#define NUM_TO_SEND 10 // how many measurements should be gathered before sending
```
The server name is the receipient server address, and the entity id sets the station id to receive the readings. This `ENTITY_ID` *must* be unique for each device.
```
#define SERVER_NAME ((char*)"nw.teal-mallet.net")
#define ENTITY_ID ((char*)"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")
```
/home/patrick/Projects/ea/purple-mallard/platformio/gsm-ultrasound/src/gsm-ultrasound.ino
\ No newline at end of file
......@@ -6,7 +6,7 @@ red_peg RP;
#include <teal_mallet_gsm.h>
teal_mallet_gsm TM;
#include <SPI.h>
#include "SdFat.h"
#include <SdFat.h>
SdFat SD;
File myFile;
#define SD_CS_PIN SD_SS
......@@ -24,7 +24,10 @@ File myFile;
/* end settings */
// set > 0 to get debug serial output
#define DEBUG_MODE 1
#define DEBUG_MODE 0
// set to 0 to remove gsm sending
#define USE_GSM 1
// choose processor sleep mode (1 = on)
#define SLEEP_MODE_ON 1
......@@ -71,7 +74,9 @@ t_SensorData last_sending_time;
void setup() {
RP.begin(true);
#if USE_GSM > 0
TM.begin(SERVER_NAME, ENTITY_ID);
#endif
delay(100);
Serial.begin(BAUD);
......@@ -158,7 +163,13 @@ void sleep_idle() {
#endif
#endif
#else
#if DEBUG_MODE > 0
Serial.print("s.");
#endif
delay(4000); // simulate sleep
#if DEBUG_MODE > 0
Serial.println("!");
#endif
#endif
// get the time from the RTC
......@@ -260,7 +271,7 @@ void take_measurement() {
myFile.write(':');
myFile.print("00"); // zero seconds
myFile.write(',');
myFile.print(temp); // stage in m
myFile.print(temp, 3); // stage in m
myFile.println();
myFile.close();
......@@ -290,9 +301,28 @@ t_SensorData get_reading(sensor_e target) {
delay(148); // alow analog reading to settle
}
delay(100);
t_SensorData sensorData = RP.get(target);
t_SensorData incoming;
if (target == ANA) {
incoming = RP.ask(target);
//delay(30000); // wait for 30 seconds for 40 reads to be averaged
delay(4000);
for (uint8_t i=0; i<5+1; i++) {
// send an empty get
incoming = RP.ask();
if (incoming.the_sensor == target) {
RP.sensorsOff();
return incoming;
}
delay(10);
}
// if we did'nt get the right answer, set empty
incoming.the_sensor = EMPTY;
} else {
// normal target, normal get()
incoming = RP.get(target);
}
RP.sensorsOff();
return sensorData;
return incoming;
}
void send_reading() {
......@@ -306,6 +336,7 @@ void send_reading() {
Serial.println(F(")"));
delay(100);
#endif
#if USE_GSM > 0
#if DEBUG_MODE > 1
Serial.println(F("connecting GPRS..."));
#endif
......@@ -329,6 +360,7 @@ void send_reading() {
#if DEBUG_MODE > 1
Serial.println(F("GPRS powered down."));
#endif
#endif
// reset the buffer length
readings_tail = readings_head;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment