-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathABoatMon.ino
140 lines (117 loc) · 3.6 KB
/
ABoatMon.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Greg Cope <[email protected]>
* see; https://github.com/gregcope/ABoatMon
*
* Allot of code pinched from;
* https://github.com/LowPowerLab/RFM69/blob/master/Examples/MotionMote/MotionMote.ino
*
* TODO
* Look at https://github.com/cdl1051/DS18B20_NROO/blob/master/DS18B20.h
* https://lowpowerlab.com/forum/projects/temperature-sensing-with-ds18b20/msg18040/#msg18040
* https://lowpowerlab.com/forum/moteino/improvedoptimized-ds18b201wire-read/msg14975/#msg14975
*
*
*/
// External includes
// https://github.com/mikalhart/TinyGPSPlus/releases
#include <TinyGPS++.h>
// http://www.pjrc.com/teensy/td_libs_OneWire.html
#include <OneWire.h>
// internal classes/includes
#include "Device.h"
#include "Config.h"
#include "Sleep.h"
#include "Gps.h"
#include "Lipo.h"
// PIN defines
#define D12_GPS_ENABLE 12
//#define GPS_TX 10 // serial1
//#define GPS_RX 11 // serial1
//#define BUTTON_LED 26
#define BUTTON_LED 15
#define BUTTON 25
#define BILGE_SWITCH 3 // Other line from BilgeSwitch to GND
//#define LIPO_VOLTAGE_DIVIDER 24 // D24 is same as A0
const int LIPO_VOLTAGE_DIVIDER = 0;
#define TEMP_POWER 27 // PA3
#define TEMP_DATA 28 // PA4
// Red connects to 27, Blue/Black connects to ground and Yellow/White (data) to 28
#define VCC_12V-24V_VOLTAGE_DIVIDER A5
#define VCC_12V-24V_ENABLE 19
#define FONA_TX 8 // serial
#define FONA_RX 9 // serial
#define FONA_POWER 30
#define FONA_KEY 14
#define FONA_PS 18
#define FONA_NETSTAT 13
// Static defines
#define FOURMIN_CYCLES 5 // 8 sec sleep * 30 cycles = 240 secs or 4 mins
#define HOUR_CYCLES 450 // 8 sec sleep * 450 cyles == 3600 secs or 1 hour
#define GPS_FIX_TIMEOUT_MSECS 300000 // time to try and get a fix in msecs is 300 secs, or 5 mins
#define UPDATE_GPS_FIX_TIMEOUT_MSECS 12000 // 12 secs
// debug functions
#define DEBUG(input) {Serial.print(input); Serial.flush();}
#define DEBUGln(input) {Serial.println(input); Serial.flush();}
// Objects
// tinyGPS is a nmea feed parser
TinyGPSPlus nmea;
Sleep sleep;
Gps gps(D12_GPS_ENABLE);
Lipo lipo(LIPO_VOLTAGE_DIVIDER);
// these are devices, and have physical on/off/interface things
//Device gpsDevice(D12_GPS_ENABLE);
//Device buttonLed(BUTTON_LED);
//Device tempSensor(TEMP_POWER);
// Make one wire faster
// http://www.cupidcontrols.com/2014/10/moteino-arduino-and-1wire-optimize-your-read-for-speed/
//Config config;
//Device charger(CHARGER_POWER);
//Device fona(FONA_POWER);
// Variables
byte bilgeSwitchPosition = 0;
// Cycle Vars
unsigned long cycleCount = 0;
byte fourMinCycleCount = 0;
unsigned int hourCycleCount = 0;
unsigned long NOW = 0;
// GPS / Nmea vars
//unsigned long nmeaSentenceTimeOutMs = 0;
//boolean nmeaSentenceTimeoutReached = false;
double fixLat = 100; // invalid Lat
double fixLng = 100; // invalid Lat
double alarmLat = 100; // invalid Lat
double alarmLng = 100; // invalid Lat
// LipoBattery
float lipoBatteryAlarm = 3.1;
float lipoBatteryVolts = 0;
char lipoBatteryVoltsString[10]; //longest battery voltage reading message = 9chars
// Message vars
String messageStr = "";
byte needToSendMessage = 0;
byte batMessageSent = 0;
byte bilgeMessageSent = 0;
byte gpsNoFixMessageSent = 0;
byte gpsGeoFenceMessageSent = 0;
//
// Code from here on ...
//
void setup() {
Serial.begin(9600);
Serial.flush();
DEBUGln("setup Start");
//yep burn CPU for 1 sec... to let stuff settle
delay(1000);
gps.getInitialFix(GPS_FIX_TIMEOUT_MSECS);
DEBUG("Lipo volts: ");
DEBUG(lipo.read());
DEBUGln(".");
DEBUGln("setup Done");
}
void loop() {
DEBUGln("loop ...");
gps.updateFix(UPDATE_GPS_FIX_TIMEOUT_MSECS);
DEBUG("Lipo volts: ");
DEBUG(lipo.read());
DEBUGln(".");
sleep.kip8Secs();
}