HomeWaterLeaksDetection
EmailSender.h
Go to the documentation of this file.
1 #ifndef UNTITLED_EMAIL_SENDER_H
2 #define UNTITLED_EMAIL_SENDER_H
3 
4 #include "SPI.h"
5 #include "Ethernet.h"
6 #include "SD.h"
7 #include "map"
8 #include "Setup.h"
9 
10 //====================web server========================
11 
12 // if the webserver is enabled,
13 // include this file as well
14 #ifdef WEB_SERVER
15 # include <HTMLDataSource.h>
16 #endif
17 
18 //================constant definitions==================
19 
20 #define arduinoIP "192.168.1.123" // ip address of Arduino
21 
22 #define SMTPServerAddress "mail.smtp2go.com" // address of the smt2go server
23 #define SMTPServerPort 2525 // port of the service
24 
25 #define emailAddress "" // Arduino's e-mail address
26 #define auth64Login "" // Arduino's e-mail login
27 #define auth64Pass "" // Arduino's e-mail password
28 
29 //=================EmailSender class====================
30 
36  #ifdef WEB_SERVER
37  : public HTMLDataSource
38  #endif
39 {
40 //====================public data=======================
41 public:
44  enum Type {
54 
55  COUNT = 9
56  };
57 
58 //====================private data======================
59 private:
60  std::map<Type, bool> enabled;
62  EthernetClient client;
63 
64  byte mac[6] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
65  String receiverEmailAddress = "jakub.sil@seznam.cz";
66 
67 //==================private methods=====================
68 private:
70  EmailSender();
71 
74 
77 
79  EmailSender& operator=(EmailSender const&) { return *this; }
80 
81 //------------------------------------------------------
82 
89  int setEthernet();
90 
93  byte eRcv();
94 
96  void efail();
97 
102  byte sendEmail(String subject, String data);
103 
104 //==================public methods======================
105 public:
108  static EmailSender* getInstance();
109 
114  void sendEmail(Type type, String subject, String data);
115 
119  void enableNotification(Type type, bool state);
120 
123  void setReceiverEmailAddress(String email);
124 
132  String getFormatOfSettingsToSave();
133 
134 //====================web server========================
135 #ifdef WEB_SERVER
136 private:
139  std::map<int, String (*)(const EmailSender& leaksController)> htmlData;
140 
141 public:
149  const String getHTMLData(const int id) const;
150 
151 private:
155  friend String HTML_Notification_BOOTING(const EmailSender& emailSender);
156 
160  friend String HTML_Notification_DAILY_OVERVIEW(const EmailSender& emailSender);
161 
165  friend String HTML_Notification_LEAK_DETECTED(const EmailSender& emailSender);
166 
170  friend String HTML_Notification_VALVE_STATE(const EmailSender& emailSender);
171 
175  friend String HTML_Notification_RESET(const EmailSender& emailSender);
176 
180  friend String HTML_Notification_ALARM(const EmailSender& emailSender);
181 
185  friend String HTML_Notification_CHANGED_SETTINGS(const EmailSender& emailSender);
186 
190  friend String HTML_Notification_APPLIED_NEW_SETTING(const EmailSender& emailSender);
191 
195  friend String HTML_Notification_BYPASS(const EmailSender& emailSender);
196 
200  friend String HTML_ReceiverEmailAddress(const EmailSender& emailSender);
201 #endif
202 };
203 
204 #endif
EmailSender::CHANGED_SETTINGS
@ CHANGED_SETTINGS
when the user changes settings
Definition: EmailSender.h:51
EmailSender::getHTMLData
const String getHTMLData(const int id) const
Since this class is registered as a source of data for the HTML content, it needs return the appropri...
EmailSender::instance
static EmailSender * instance
the instance of EmailSender
Definition: EmailSender.h:61
EmailSender::HTML_Notification_APPLIED_NEW_SETTING
friend String HTML_Notification_APPLIED_NEW_SETTING(const EmailSender &emailSender)
Associated function for returing the state of the 'applied settings' notification.
EmailSender::BYPASS
@ BYPASS
when a bypass changes
Definition: EmailSender.h:53
EmailSender::~EmailSender
~EmailSender()
Descrutor of the class.
EmailSender::HTML_Notification_BYPASS
friend String HTML_Notification_BYPASS(const EmailSender &emailSender)
Associated function for returing the state of the 'bypass state' notification.
EmailSender::getFormatOfSettingsToSave
String getFormatOfSettingsToSave()
Returns settings.
Definition: EmailSender.cpp:248
EmailSender::receiverEmailAddress
String receiverEmailAddress
the default user's email address
Definition: EmailSender.h:65
EmailSender::enabled
std::map< Type, bool > enabled
map holding info about each time of e-mail - whether it's enabled or not
Definition: EmailSender.h:60
EmailSender
Definition: EmailSender.h:39
EmailSender::Type
Type
different types of e-mail that can be sent to the user
Definition: EmailSender.h:44
EmailSender::enableNotification
void enableNotification(Type type, bool state)
Enables/disables the particular type of e-mail notification.
Definition: EmailSender.cpp:43
EmailSender::COUNT
@ COUNT
total number of different kinds of e-mails
Definition: EmailSender.h:55
WEB_SERVER
#define WEB_SERVER
enable the webserver
Definition: Setup.h:13
EmailSender::BOOTING
@ BOOTING
when the system boots up
Definition: EmailSender.h:45
HTMLDataSource.h
Setup.h
EmailSender::HTML_Notification_VALVE_STATE
friend String HTML_Notification_VALVE_STATE(const EmailSender &emailSender)
Associated function for returing the state of the 'valve state' notification.
EmailSender::setReceiverEmailAddress
void setReceiverEmailAddress(String email)
Changes the user's e-mail address.
Definition: EmailSender.cpp:83
EmailSender::HTML_Notification_BOOTING
friend String HTML_Notification_BOOTING(const EmailSender &emailSender)
Associated function for returing the state of the 'bootup' notification.
EmailSender::LEAK_DETECTED
@ LEAK_DETECTED
when a leak has been detected
Definition: EmailSender.h:47
EmailSender::efail
void efail()
Closes the ethernet client after the connection has failed.
Definition: EmailSender.cpp:223
EmailSender::client
EthernetClient client
EthernetClient used to connect to the smt2go server.
Definition: EmailSender.h:62
EmailSender::mac
byte mac[6]
mac address of the ethernet shield
Definition: EmailSender.h:64
EmailSender::HTML_ReceiverEmailAddress
friend String HTML_ReceiverEmailAddress(const EmailSender &emailSender)
Associated function for returing the user's e-mail address.
EmailSender::EmailSender
EmailSender(EmailSender const &)
Copy constructor of the class.
Definition: EmailSender.h:76
EmailSender::sendEmail
byte sendEmail(String subject, String data)
Sends an e-mail off to the smtp2go server.
Definition: EmailSender.cpp:93
EmailSender::HTML_Notification_CHANGED_SETTINGS
friend String HTML_Notification_CHANGED_SETTINGS(const EmailSender &emailSender)
Associated function for returing the state of the 'changed settings' notification.
EmailSender::VALVE_STATE
@ VALVE_STATE
when the state of the valve has changed
Definition: EmailSender.h:48
EmailSender::RESET
@ RESET
when the device resets
Definition: EmailSender.h:49
EmailSender::APPLIED_NEW_SETTING
@ APPLIED_NEW_SETTING
when the new settings are applied
Definition: EmailSender.h:52
HTMLDataSource
Definition: HTMLDataSource.h:15
EmailSender::eRcv
byte eRcv()
Reads data using the ethernet client comming from the smtp2go server.
Definition: EmailSender.cpp:192
EmailSender::HTML_Notification_ALARM
friend String HTML_Notification_ALARM(const EmailSender &emailSender)
Associated function for returing the state of the 'home alarm state' notification.
EmailSender::HTML_Notification_DAILY_OVERVIEW
friend String HTML_Notification_DAILY_OVERVIEW(const EmailSender &emailSender)
Associated function for returing the state of the 'daily overview' notification.
EmailSender::EmailSender
EmailSender()
Constructor of the class.
Definition: EmailSender.cpp:47
EmailSender::DAILY_OVERVIEW
@ DAILY_OVERVIEW
daily overview about the system
Definition: EmailSender.h:46
EmailSender::HTML_Notification_LEAK_DETECTED
friend String HTML_Notification_LEAK_DETECTED(const EmailSender &emailSender)
Associated function for returing the state of the 'leak detected' notification.
EmailSender::setEthernet
int setEthernet()
Initializes the ethernet shield.
Definition: EmailSender.cpp:18
EmailSender::HTML_Notification_RESET
friend String HTML_Notification_RESET(const EmailSender &emailSender)
Associated function for returing the state of the 'system reset' notification.
EmailSender::ALARM
@ ALARM
when the state of the home alarm changes
Definition: EmailSender.h:50
EmailSender::operator=
EmailSender & operator=(EmailSender const &)
Assignmet operator of the class.
Definition: EmailSender.h:79
EmailSender::htmlData
std::map< int, String(*)(const EmailSender &leaksController)> htmlData
A map of different values (keys) and their associated functions which returns the appropriate values.
Definition: EmailSender.h:139
EmailSender::getInstance
static EmailSender * getInstance()
Returns the instance of the class.
Definition: EmailSender.cpp:87