Skip to content

Commit

Permalink
Merge pull request #99 from OpenGarage/emailSupport
Browse files Browse the repository at this point in the history
Email support
  • Loading branch information
rayshobby authored Oct 15, 2024
2 parents b1e1f8c + ee6709e commit 324fac6
Show file tree
Hide file tree
Showing 17 changed files with 2,014 additions and 109 deletions.
File renamed without changes.
File renamed without changes.
Binary file added Compiled/og_1.2.3.bin
Binary file not shown.
1,115 changes: 1,115 additions & 0 deletions OpenGarage/EMailSender.cpp

Large diffs are not rendered by default.

525 changes: 525 additions & 0 deletions OpenGarage/EMailSender.h

Large diffs are not rendered by default.

157 changes: 157 additions & 0 deletions OpenGarage/EMailSenderKey.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
* EMail Sender Arduino, esp8266, stm32 and esp32 library to send email
*
* AUTHOR: Renzo Mischianti
* VERSION: 3.0.14
*
* https://www.mischianti.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Renzo Mischianti www.mischianti.org All right reserved.
*
* You may copy, alter and reuse this code in any way you like, but please leave
* reference to www.mischianti.org in your comments if you redistribute this code.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef EMailSenderKey_h
#define EMailSenderKey_h

// Uncomment if you use esp8266 core <= 2.4.2
//#define ARDUINO_ESP8266_RELEASE_2_4_2

// If you want disable attachments and save memory comment this define
//#define ENABLE_ATTACHMENTS

// Uncomment to enable printing out nice debug messages.
#define EMAIL_SENDER_DEBUG

// Define where debug output will be printed.
#define DEBUG_PRINTER Serial

#define STORAGE_NONE (0)
// INTERNAL STORAGE
#define STORAGE_SPIFFS (1)
#define STORAGE_LITTLEFS (2)
#define STORAGE_FFAT (3)
#define STORAGE_SPIFM (5) // Libraries Adafruit_SPIFlash and SdFat-Adafruit-Fork
// EXTERNAL STORAGE
#define STORAGE_SD (4)
#define STORAGE_SDFAT2 (6) // Library SdFat version >= 2.0.2
#define STORAGE_SDFAT_RP2040_ESP8266 (7) // Library ESP8266SdFat on Raspberry Pi Pico

#define NETWORK_ESP8266_ASYNC (0)
#define NETWORK_ESP8266 (1)
#define NETWORK_ESP8266_242 (6)
#define NETWORK_W5100 (2)
#define NETWORK_ETHERNET (2) // Standard Arduino Ethernet library
#define NETWORK_ENC28J60 (3)
#define NETWORK_ESP32 (4)
#define NETWORK_RP2040_WIFI (4)
#define NETWORK_ESP32_ETH (5)
#define NETWORK_WiFiNINA (7)
#define NETWORK_ETHERNET_LARGE (8)
#define NETWORK_ETHERNET_ENC (9)
#define NETWORK_ETHERNET_STM (10)
#define NETWORK_UIPETHERNET (11)
#define NETWORK_ETHERNET_2 (12)
#define NETWORK_ETHERNET_GENERIC (13) // Ethernet generic
#define NETWORK_MBED_WIFI (14) // Arduino GIGA R1 WiFi

// if you want force disable SSL if present uncomment this define
// #define FORCE_DISABLE_SSL

// If you want add a wrapper to emulate SSL over Client like EthernetClient
// #define SSLCLIENT_WRAPPER

// esp8266 microcontrollers configuration
#ifndef DEFAULT_EMAIL_NETWORK_TYPE_ESP8266
#define DEFAULT_EMAIL_NETWORK_TYPE_ESP8266 NETWORK_ESP8266
#define DEFAULT_INTERNAL_ESP8266_STORAGE STORAGE_LITTLEFS
#define DEFAULT_EXTERNAL_ESP8266_STORAGE STORAGE_NONE
#endif
// esp32 microcontrollers configuration
#ifndef DEFAULT_EMAIL_NETWORK_TYPE_ESP32
#define DEFAULT_EMAIL_NETWORK_TYPE_ESP32 NETWORK_ESP32
#define DEFAULT_INTERNAL_ESP32_STORAGE STORAGE_SPIFFS
#define DEFAULT_EXTERNAL_ESP32_STORAGE STORAGE_SD
#endif
// stm32 microcontrollers configuration
#ifndef DEFAULT_EMAIL_NETWORK_TYPE_STM32
#define DEFAULT_EMAIL_NETWORK_TYPE_STM32 NETWORK_W5100
#define DEFAULT_INTERNAL_STM32_STORAGE STORAGE_NONE
#define DEFAULT_EXTERNAL_STM32_STORAGE STORAGE_SDFAT2
#endif
// Arduino microcontrollers configuration
#ifndef DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO
#define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO NETWORK_W5100
#define DEFAULT_INTERNAL_ARDUINO_STORAGE STORAGE_NONE
#define DEFAULT_EXTERNAL_ARDUINO_STORAGE STORAGE_SD
#endif
// Arduino SAMD microcontrollers configuration
#ifndef DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO_SAMD
#define DEFAULT_EMAIL_NETWORK_TYPE_SAMD NETWORK_WiFiNINA
#define DEFAULT_INTERNAL_ARDUINO_SAMD_STORAGE STORAGE_NONE
#define DEFAULT_EXTERNAL_ARDUINO_SAMD_STORAGE STORAGE_SD
#endif
// Raspberry Pi Pico (rp2040) configuration
#ifndef DEFAULT_EMAIL_NETWORK_TYPE_RP2040
#define DEFAULT_EMAIL_NETWORK_TYPE_RP2040 NETWORK_RP2040_WIFI
#define DEFAULT_INTERNAL_ARDUINO_RP2040_STORAGE STORAGE_LITTLEFS
#define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_NONE
#endif
// Arduino MBED microcontrollers configuration LIKE Arduino GIGA
#ifndef DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO_MBED
#define DEFAULT_EMAIL_NETWORK_TYPE_MBED NETWORK_MBED_WIFI
#define DEFAULT_INTERNAL_ARDUINO_MBED_STORAGE STORAGE_NONE
#define DEFAULT_EXTERNAL_ARDUINO_MBED_STORAGE STORAGE_SD
#endif

#ifdef SSLCLIENT_WRAPPER
// Generate the trust_anchors.h with this online generator
// https://openslab-osu.github.io/bearssl-certificate-utility/
/**
* For Ethernet w5x00 card you must follow the step given
* from this link https://github.com/OPEnSLab-OSU/SSLClient#sslclient-with-ethernet
* you can modify Ethernet library or use directly this modified one
* https://github.com/OPEnSLab-OSU/EthernetLarge
*
* For enc28j60 use EthernetENC available from library manager or
* https://github.com/jandrassy/EthernetENC
*/
#define ANALOG_PIN A7
#include <SSLClient.h>
#include "trust_anchors.h"

#define PUT_OUTSIDE_SCOPE_CLIENT_DECLARATION
#endif

// This two value can take a number 1..20 or you can specify 'a'
// but with auto you can lost specified response error
#define DEFAULT_EHLO_RESPONSE_COUNT 6
#define DEFAULT_CONNECTION_RESPONSE_COUNT 0

#define SD_CS_PIN SS
#define SPIFM_CS_PIN SS

//#define STORAGE_INTERNAL_FORCE_DISABLE
//#define STORAGE_EXTERNAL_FORCE_DISABLE

#endif
8 changes: 7 additions & 1 deletion OpenGarage/OpenGarage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ OptionStruct OpenGarage::options[] = {
{"mqur", 0, 0, ""},
{"mqpw", 0, 0, ""},
{"mqtp", 0, 0, ""},
{"emen", 0, 1, ""},
{"smtp", 0, 0, DEFAULT_SMTP_SERVER},
{"sprt", DEFAULT_SMTP_PORT, 65535, ""},
{"send", 0, 0, ""},
{"apwd", 0, 0, ""},
{"recp", 0, 0, ""},
{"dvip", 0, 0, ""},
{"gwip", 0, 0, ""},
{"subn", 0, 0, "255.255.255.0"},
Expand All @@ -105,7 +111,7 @@ void ud_start_trigger() {
digitalWrite(PIN_TRIG, LOW);
}

ICACHE_RAM_ATTR void ud_isr() {
IRAM_ATTR void ud_isr() {
if(!triggered) return;

// ECHO pin went from low to high
Expand Down
1 change: 1 addition & 0 deletions OpenGarage/OpenGarage.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <DHTesp.h>
#include <AM2320.h>
#include <DallasTemperature.h>
#include <EMailSender.h>

#include "defines.h"

Expand Down
4 changes: 2 additions & 2 deletions OpenGarage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Install Visual Studio Code (VS Code) (https://code.visualstudio.com/). Then laun
### Method 2: Use makeEspArduino and Makefile

#### Step A: Install ESP8266 core and required libraries
Follow https://github.com/plerup/makeEspArduino to install **ESP8266 core 2.7.4**. Then download or `git clone` the following libraries to a folder such as `$(HOME)/Arduino/libraries` (note the version of each library):
Follow https://github.com/plerup/makeEspArduino to install **ESP8266 core 3.1.2**. Then download or `git clone` the following libraries to a folder such as `$(HOME)/Arduino/libraries` (note the version of each library):

* Blynk library for Arduino (https://github.com/blynkkk/blynk-library) (v1.0.1)
* MQTT PubSUbClient https://github.com/knolleary/pubsubclient (v2.8)
Expand All @@ -30,7 +30,7 @@ To compile the firmware code using makeESPArduino, simply run `make` in command
#### Step A: Install Arduino IDE, ESP8266 core, and required libraries

* Install Arduino IDE (https://arduino.cc).
* Launch Arduino IDE and install ESP8266 core 2.7.4 for Arduino (https://github.com/esp8266/Arduino/releases/tag/2.7.4)
* Launch Arduino IDE and install ESP8266 core 1.3.2 for Arduino (https://github.com/esp8266/Arduino/releases/tag/3.1.2)
* Install the libraries listed above.
* Download this repository and extract the `OpenGarage` folder to your Arduino's `libraries` folder.

Expand Down
13 changes: 11 additions & 2 deletions OpenGarage/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define _DEFINES_H

/** Firmware version, hardware version, and maximal values */
#define OG_FWV 122 // Firmware version: 122 means 1.2.2
#define OG_FWV 123 // Firmware version: 123 means 1.2.3

/** GPIO pins */
#define PIN_RELAY 15 // D8 on nodemcu
Expand Down Expand Up @@ -57,6 +57,9 @@
#define DEFAULT_OTC_DMN "ws.cloud.openthings.io"
#define DEFAULT_OTC_PRT 80

#define DEFAULT_SMTP_SERVER "smtp.gmail.com"
#define DEFAULT_SMTP_PORT 465

#define OG_SN1_CEILING 0x00 // SN1 is built-in ultrasonic sensor
#define OG_SN1_SIDE 0x01

Expand Down Expand Up @@ -177,6 +180,12 @@ typedef enum {
OPTION_MQUR, // MQTT user name (optional)
OPTION_MQPW, // MQTT password (optional)
OPTION_MQTP, // MQTT topic (optional)
OPTION_EMEN, // Email enable
OPTION_SMTP, // SMTP Server
OPTION_SPRT, // SMTP Port
OPTION_SEND, // Sender Email
OPTION_APWD, // SMTP App Password
OPTION_RECP, // Recipient Email
OPTION_DVIP, // device IP
OPTION_GWIP, // gateway IP
OPTION_SUBN, // subnet
Expand All @@ -196,7 +205,7 @@ typedef enum {
#define LED_FAST_BLINK 100
#define LED_SLOW_BLINK 500

#define TIME_SYNC_TIMEOUT 1800 //Issues connecting to MQTT can throw off the time function, sync more often
#define TIME_SYNC_TIMEOUT 3600 //Issues connecting to MQTT can throw off the time function, sync more often

#define TMP_BUFFER_SIZE 100

Expand Down
2 changes: 1 addition & 1 deletion OpenGarage/html/sta_home.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</div>
</div>
<div data-role='footer' data-theme='c'>
<p>&nbsp; OpenGarage Firmware v<label id='fwv'>-</label><div data-role='controlgroup' data-type='horizontal'><a href='update' target='_top' data-role='button' data-inline=true data-mini=true>Firmware Update</a><a href='https://github.com/OpenGarage/OpenGarage-Firmware/tree/master/docs/fw1.2.0' target='_blank' data-role='button' data-inline=true data-mini=true>User Manual</a></p></div>
<p>&nbsp; OpenGarage Firmware v<label id='fwv'>-</label><div data-role='controlgroup' data-type='horizontal'><a href='update' target='_top' data-role='button' data-inline=true data-mini=true>Firmware Update</a><a href='https://github.com/OpenGarage/OpenGarage-Firmware/tree/master/docs' target='_blank' data-role='button' data-inline=true data-mini=true>User Manual</a></p></div>
</div>
</div>
<script>
Expand Down
51 changes: 35 additions & 16 deletions OpenGarage/html/sta_options.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
<input type='radio' name='rd_ct' id='blynk' onclick='update_ct()' checked><label for='blynk'>Blynk</label>
<input type='radio' name='rd_ct' id='otc' onclick='update_ct()'><label for='otc'>OTC</label>
</fieldset>
</td>
<tr class='cld'><td><b>Cloud Token:</b></td><td><input type='text' size=20 maxlength=64 id='auth' data-mini='true'></td></tr>
<tr class='cld'><td><b>Cloud Server:</b></td><td><input type='text' size=20 maxlength=64 id='bdmn' data-mini='true'></td></tr>
</td></tr>
<tr class='cld'><td><b>Cloud Token:</b></td><td><input type='text' size=22 maxlength=64 id='auth' data-mini='true'></td></tr>
<tr class='cld'><td><b>Cloud Server:</b></td><td><input type='text' size=22 maxlength=64 id='bdmn' data-mini='true'></td></tr>
<tr class='cld'><td><b>Cloud Port:</b></td><td><input type='text' size=5 maxlength=5 id='bprt' data-mini='true'></td></tr>
<tr class='cld'><td colspan=2><hr></td></tr>
<tr><td colspan=2><input type='checkbox' id='mqen' data-mini='true' onclick='update_mqtt()'><label for='mqen'>Enable MQTT</label></td></tr>
Expand All @@ -79,20 +79,26 @@
<tr class='mqt'><td><b>MQTT Password:</b></td><td><input type='password' size=16 maxlength=64 id='mqpw' data-mini='true' placeholder='(unchanged if left blank)'></td></tr>
<tr class='mqt'><td><b>MQTT Topic:</b></td><td><input type='text' size=16 maxlength=64 id='mqtp' data-mini='true' placeholder='(optional)'></td></tr>
<tr class='mqt'><td colspan=2><hr></td></tr>
<tr><td><b>IFTTT Key:</b></td><td><input type='text' size=20 maxlength=64 id='iftt' data-mini='true' placeholder='(optional)'></td></tr>
<tr><td colspan=2><input type='checkbox' id='emen' data-mini='true' onclick='update_email()'><label for='emen'>Enable Email Notifications</label></td></tr>
<tr class='email'><td><b>SMTP Server:</b></td><td><input type='text' size=16 maxlength=64 id='smtp' data-mini='true'></td></tr>
<tr class='email'><td><b>SMTP Port:</b></td><td><input type='text' size=5 maxlength=5 id='sprt' data-mini='true'></td></tr>
<tr class='email'><td><b>Sender Email:</b></td><td><input type='text' size=16 maxlength=64 id='send' data-mini='true'></td></tr>
<tr class='email'><td><b>App Password:</b></td><td><input type='text' size=16 maxlength=64 id='apwd' data-mini='true'></td></tr>
<tr class='email'><td><b>Recipient Email:</b></td><td><input type='text' size=16 maxlength=64 id='recp' data-mini='true'></td></tr>
<tr height=30px><td colspan=2><b>Choose Notification Events:</b></td></tr>
<tr><td><input type='checkbox' id='noto0' data-mini='true'><label for='noto0'>Door Open</label></td><td><input type='checkbox' id='noto1' data-mini='true' ><label for='noto1'>Door Close</label></td></tr>
<tr><td><b>IFTTT Key:</b></td><td><input type='text' size=20 maxlength=64 id='iftt' data-mini='true' placeholder='(if using IFTTT notification)'></td></tr>
</table>
<table>
<tr><td colspan=4><b>Choose Notifications:</b></td></tr>
<tr><td><input type='checkbox' id='noto0' data-mini='true'><label for='noto0'>Door<br> Open</label></td><td><input type='checkbox' id='noto1' data-mini='true' ><label for='noto1'>Door<br> Close</label></td><td><input type='checkbox' id='noto2' data-mini='true' disabled><label for='noto2'>Vehicle<br> Leave</label></td><td><input type='checkbox' id='noto3' data-mini='true' disabled ><label for='noto3'>Vehicle<br> Arrive</label></td></tr>
<tr><td colspan=4><hr></td></tr>
<tr><td colspan=4><b>Automation:</b></td></tr>
<tr><td colspan=4></td></tr><tr><td colspan=4></td></tr>
<tr><td colspan=4>If open for longer than:</td></tr>
<tr><td><input type='text' size=3 maxlength=3 id='ati' value=30 data-mini='true'></td><td>minutes:</td><td><input type='checkbox' id='ato0' data-mini='true'><label for='ato0'>Notify me</label></td><td><input type='checkbox' id='ato1' data-mini='true'><label for='ato1'>Auto-close</label></td></tr>
<tr><td colspan=4>If open after time:<small> (Use UTC 24hr format)</small>:</td></tr>
<tr><td><input type='text' size=3 maxlength=3 id='atib' value=3 data-mini='true'></td><td> UTC:</td><td><input type='checkbox' id='atob0' data-mini='true'><label for='atob0'>Notify me</label></td><td><input type='checkbox' id='atob1' data-mini='true'><label for='atob1'>Auto-close</label></td></tr>
<tr><td colspan=4><hr></td></tr>
<tr><td colspan=4><b>Automation:</b></td></tr>
<tr><td colspan=4></td></tr><tr><td colspan=4></td></tr>
<tr><td colspan=4>If open for longer than:</td></tr>
<tr><td><input type='text' size=3 maxlength=3 id='ati' value=30 data-mini='true'></td><td>minutes:</td><td><input type='checkbox' id='ato0' data-mini='true'><label for='ato0'>Notify me</label></td><td><input type='checkbox' id='ato1' data-mini='true'><label for='ato1'>Auto-close</label></td></tr>
<tr><td colspan=4>If open after time:<small> (Use UTC 24hr format)</small>:</td></tr>
<tr><td><input type='text' size=3 maxlength=3 id='atib' value=3 data-mini='true'></td><td> UTC:</td><td><input type='checkbox' id='atob0' data-mini='true'><label for='atob0'>Notify me</label></td><td><input type='checkbox' id='atob1' data-mini='true'><label for='atob1'>Auto-close</label></td></tr>
</table><table>
</table>
</table>
</div>
<div id='div_other' style='display:none;'>
<table cellpadding=2>
Expand Down Expand Up @@ -157,6 +163,10 @@
if(eval_cb('#mqen')) $('.mqt').show();
else $('.mqt').hide();
}
function update_email(){
if(eval_cb('#emen')) $('.email').show();
else $('.email').hide();
}
function update_sfi(){
if(eval_cb('#sf_con')) $('#tbl_cmr').show();
else $('#tbl_cmr').hide();
Expand All @@ -177,8 +187,8 @@
$('#div_cloud').hide();
$('#div_other').hide();
if(eval_cb('#basic')) $('#div_basic').show();
if(eval_cb('#cloud')) $('#div_cloud').show();
if(eval_cb('#other')) $('#div_other').show();
if(eval_cb('#cloud')) {$('#div_cloud').show(); update_cld(); update_mqtt(); update_email();}
if(eval_cb('#other')) {$('#div_other').show(); update_usi();}
}
$('#btn_back').click(function(e){
e.preventDefault(); goback();
Expand Down Expand Up @@ -215,6 +225,8 @@
bc('mqtt',1);bc('mqur',1);bc('mqtp',1);bc('mqpt');
if($('#mqpw').val().length>0) bc('mqpw',1);
comm+='&mqen='+(eval_cb('#mqen')?1:0);
bc('smtp',1);bc('send',1);bc('apwd',1);bc('recp',1);bc('sprt');
comm+='&emen='+(eval_cb('#emen')?1:0);
bc('bprt');bc('ntp1',1);bc('host',1);
if($('#cb_key').is(':checked')) {
if(!$('#nkey').val()) {
Expand Down Expand Up @@ -282,6 +294,13 @@
if(jd.mqtp) $('#mqtp').val(jd.mqtp);
if(jd.mqpt) $('#mqpt').val(jd.mqpt);
update_mqtt();
if(jd.emen>0) cbt('emen');
$('#smtp').val(jd.smtp);
$('#sprt').val(jd.sprt);
$('#send').val(jd.send);
$('#apwd').val(jd.apwd);
$('#recp').val(jd.recp);
update_email();
$('#dvip').val(jd.dvip);
$('#gwip').val(jd.gwip);
$('#subn').val(jd.subn);
Expand Down
Loading

0 comments on commit 324fac6

Please sign in to comment.