-
Notifications
You must be signed in to change notification settings - Fork 1
Mailbox Sketch
You would probably notice that the mailbox sketch has unusual design, where mailbox.ino contains just:
#include "local.ino.h" // Local module
#include "remote.ino.h" // Remote module
local.ino.h and remote.ino.h are the actual sketches for the receiver and transmitter correspondingly. The selection of which one is active is made in MySystem.h with the help of DS_MAILBOX_REMOTE
define. The reason for this is that both sketches have significant piece of code to share:
- ESP-DS-System library (System.h and System.cpp);
- communication protocol (MailBoxMessage.h and MailBoxMessage.cpp);
- common mailbox definition (MailBox.h and MailBox.cpp);
- some common definitions for transmitter and receiver (Transceiver.h and Transceiver.cpp).
Having these files as copies in two sketches would be impractical for updates and version control. A standard Arduino IDE answer to this is to make your own library and place it out of the sketch. Here, however, it would have little sense to make a library, because the code is application-specific. While developing on Linux, I put the shared code in a separate folder and used symbolic links to let the two sketches know where the code is. However, on Windows symlinks are not supported, so the design would have had to be adapted for publishing. Combining two sketches into one looked like the only viable option.
Most of the files are present in pairs .h
/ .cpp
, where .h
contains class declaration, and .cpp
contains implementation. Sometimes there is only .h
or only .cpp
.
-
System
— ESP-DS-System library (not sketch-specific); -
MySystem
— sketch-specific settings; selection of local / remote module to build. See details in Getting Started; -
MailBoxMessage
— communication protocol definition; -
Transceiver
— base class forTransmitter
andReceiver
; -
MailBox
— base class forPhysicalMailBox
andVirtualMailBox
; -
mailbox.ino
— sketch entry point.
-
Transmitter
— HC-12 transmission interface, in particular procedures for data sending and sleep mode handling; -
PhysicalMailBox
— physical interface to mailbox door sensor. Also includes battery management; -
remote.ino
— main loop. Also takes care of deep sleep for ESP8266 controller.
-
Receiver
— HC-12 receiver interface. Also includes transmission emulation mode; -
VirtualMailBox
— virtual representation of the physical mailbox on receiver side; -
MailBoxManager
— support for multiple mailboxes on receiver side; -
web
— web site interface. This is not a class per se, but a collection of functions to support web server; -
Telegram
— Telegram interface; -
GoogleAssistant
— Google Home interface; -
local.ino
— main loop.