-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathremote.ino.h
76 lines (55 loc) · 2.12 KB
/
remote.ino.h
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
/* DS mailbox automation
* * Remote module
* (c) DNS 2020
*/
#include "MySystem.h" // System-level definitions
#ifdef DS_MAILBOX_REMOTE
using namespace ds;
#include "Transmitter.h" // Message transmitter
#include "PhysicalMailBox.h" // Mailbox
// Configuration
/// Application identification
const char *System::app_name PROGMEM = DS_APP_NAME "; Remote Module";
const char *System::app_version PROGMEM = DS_APP_VERSION;
const char *System::app_url PROGMEM = DS_APP_URL;
//// I/O
static const int PIN_REED = 3; // No need to receive data; use GPIO3 (RX) for reed sensor
static const int PIN_HC12_SET = 0; // Pin to control the configuration pin of HC-12
ADC_MODE(ADC_VCC); // Configure ADC to measure Vcc
Print* System::log = &Serial1; // Syslog on secondary UART (primary is occupied by transmitter)
//// Other
static const uint8_t MAILBOX_ID = 1; // Mailbox identification number (1-15)
// Normally, no need to change below this line
// Global variables
static Transmitter transmitter(Serial, MAILBOX_ID, PIN_HC12_SET); // Transmitter
static PhysicalMailBox mailbox(MAILBOX_ID, PIN_REED); // Mailbox
void setup() {
// First the system
System::begin();
// Initialize RF transmitter
transmitter.begin();
transmitter.wakeup();
// Initialize mailbox
mailbox.begin();
// Send wakeup message
transmitter << mailbox;
}
void loop() {
// Check if it time to sleep. If door gets closed, go to sleep immediately, because next change to open will result in restart
if (mailbox.doorClosed() || millis() >= mailbox.AWAKE_TIME) {
System::log->printf(TIMED("%s.\n"), mailbox.doorClosed() ? "Door closed" : "Awake timeout reached");
// Send status before sleeping
mailbox.updateBattery();
mailbox.setOnline(false);
transmitter << mailbox;
// Go to sleep
transmitter.sleep();
mailbox.sleep();
System::log->printf(TIMED("Putting system to sleep\n"));
ESP.deepSleep(0, WAKE_RF_DISABLED);
}
// Background processing
System::update();
mailbox.update();
}
#endif // DS_MAILBOX_REMOTE