Skip to content

Commit 7b2d461

Browse files
committed
Add auto notification setting
Alllow to automaticatilly send notification when device is online
1 parent 46f2d27 commit 7b2d461

File tree

6 files changed

+47
-3
lines changed

6 files changed

+47
-3
lines changed

esp3d/command.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,19 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
12591259
ESPCOM::print ( F ("\",\"H\":\"Notifications Settings\",\"M\":\""), output, espresponse);
12601260
ESPCOM::print ( (const char *) CONFIG::intTostr (MIN_NOTIFICATION_SETTINGS_LENGTH), output, espresponse);
12611261
ESPCOM::print ( F("\"}"), output, espresponse);
1262+
ESPCOM::println (F (","), output, espresponse);
1263+
//Auto Notification
1264+
ESPCOM::print (F ("{\"F\":\"network\",\"P\":\""), output, espresponse);
1265+
ESPCOM::print ( (const char *) CONFIG::intTostr (ESP_AUTO_NOTIFICATION), output, espresponse);
1266+
ESPCOM::print (F ("\",\"T\":\"B\",\"V\":\""), output, espresponse);
1267+
if (!CONFIG::read_byte (ESP_AUTO_NOTIFICATION, &bbuf ) ) {
1268+
ESPCOM::print ("???", output, espresponse);
1269+
} else {
1270+
ESPCOM::print ( (const char *) CONFIG::intTostr (bbuf), output, espresponse);
1271+
}
1272+
ESPCOM::print (F ("\",\"H\":\"Auto notification\",\"O\":[{\"No\":\"0\"},{\"Yes\":\"1\"}]}"), output, espresponse);
1273+
1274+
12621275
#endif //NOTIFICATION_FEATURE
12631276
}
12641277

@@ -1419,6 +1432,11 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
14191432
CONFIG::InitDHT(true);
14201433
}
14211434
#endif
1435+
#ifdef NOTIFICATION_FEATURE
1436+
if (pos == ESP_AUTO_NOTIFICATION) {
1437+
notificationsservice.setAutonotification ((bbuf == 0)? false: true);
1438+
}
1439+
#endif
14221440
#if defined(TIMESTAMP_FEATURE)
14231441
if ( (pos == EP_TIMEZONE) || (pos == EP_TIME_ISDST) || (pos == EP_TIME_SERVER1) || (pos == EP_TIME_SERVER2) || (pos == EP_TIME_SERVER3) ) {
14241442
CONFIG::init_time_client();

esp3d/config.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,9 @@ bool CONFIG::reset_config()
911911
if (!CONFIG::write_string (ESP_NOTIFICATION_SETTINGS, DEFAULT_NOTIFICATION_SETTINGS ) ) {
912912
return false;
913913
}
914+
if (!CONFIG::write_byte (ESP_AUTO_NOTIFICATION, DEFAULT_AUTO_NOTIFICATION_STATE) ) {
915+
return false;
916+
}
914917
#endif
915918

916919
return set_EEPROM_version(EEPROM_CURRENT_VERSION);

esp3d/config.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020

2121
//version and sources location
22-
#define FW_VERSION "2.1.0.b37"
22+
#define FW_VERSION "2.1.0.b38"
2323
#define REPOSITORY "https://github.com/luc-github/ESP3D"
2424

2525
//Customize ESP3D ////////////////////////////////////////////////////////////////////////
@@ -316,7 +316,8 @@ typedef enum {
316316
#define EP_HOSTNAME 130//33 bytes 32+1 = string ; warning does not support multibyte char like chinese
317317
#define EP_DHT_INTERVAL 164//4 bytes = int
318318
#define ESP_NOTIFICATION_TYPE 168 //1 byte = flag
319-
#define EP_FREE_INT2 169//3 bytes = int
319+
#define ESP_AUTO_NOTIFICATION 170//1 bytes = flag
320+
#define EP_FREE_BYTE1 171//1 bytes = flag
320321
#define EP_FREE_INT3 172//4 bytes = int
321322
#define EP_ADMIN_PWD 176//21 bytes 20+1 = string ; warning does not support multibyte char like chinese
322323
#define EP_USER_PWD 197//21 bytes 20+1 = string ; warning does not support multibyte char like chinese
@@ -396,6 +397,8 @@ const int DEFAULT_DHT_INTERVAL = 30;
396397
#define DEFAULT_NOTIFICATION_TOKEN1 ""
397398
#define DEFAULT_NOTIFICATION_TOKEN2 ""
398399
#define DEFAULT_NOTIFICATION_SETTINGS ""
400+
#define DEFAULT_AUTO_NOTIFICATION_STATE 1
401+
#define NOTIFICATION_ESP_ONLINE "Hi, %ESP_NAME% is now online at %ESP_IP%"
399402

400403
//Notifications
401404
#define ESP_PUSHOVER_NOTIFICATION 1

esp3d/notifications_service.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,22 @@ bool Wait4Answer(TSecureClient & client, const char * linetrigger, const char *
9292
return false;
9393
}
9494

95+
bool NotificationsService::sendAutoNotification(const char * msg)
96+
{
97+
if ((WiFi.getMode() == WIFI_AP) || (!_started) || (!_autonotification))return false;
98+
String msgtpl = msg;
99+
//check if has variable to change
100+
if (msgtpl.indexOf("%") != -1) {
101+
msgtpl.replace("%ESP_IP%", WiFi.localIP().toString().c_str());
102+
msgtpl.replace("%ESP_NAME%", wifi_config.get_hostname());
103+
}
104+
return sendMSG("ESP3D Notification", msgtpl.c_str());
105+
}
106+
95107
NotificationsService::NotificationsService()
96108
{
97109
_started = false;
110+
_autonotification = false;
98111
_notificationType = 0;
99112
_token1 = "";
100113
_token1 = "";
@@ -411,7 +424,9 @@ bool NotificationsService::begin()
411424
return false;
412425
break;
413426
}
414-
427+
if (CONFIG::read_byte (ESP_NOTIFICATION_TYPE, &bbuf ) ) {
428+
_autonotification = (bbuf == 0) ? false: true;
429+
}
415430
if (!res) {
416431
end();
417432
}

esp3d/notifications_service.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ class NotificationsService
3535
bool sendMSG(const char * title, const char * message);
3636
const char * getTypeString();
3737
bool started();
38+
bool isAutonotification() { return _autonotification;};
39+
void setAutonotification(bool value) { _autonotification = value;};
40+
bool sendAutoNotification(const char * msg);
3841
private:
3942
bool _started;
4043
uint8_t _notificationType;
44+
bool _autonotification;
4145
String _token1;
4246
String _token2;
4347
String _settings;

esp3d/wificonf.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ bool WIFI_CONFIG::Enable_servers()
673673
#endif
674674
#if defined(NOTIFICATION_FEATURE)
675675
notificationsservice.begin();
676+
notificationsservice.sendAutoNotification(NOTIFICATION_ESP_ONLINE);
676677
#endif
677678

678679
return true;

0 commit comments

Comments
 (0)