Skip to content

Commit

Permalink
Add auto notification setting
Browse files Browse the repository at this point in the history
Alllow to automaticatilly send notification when device is online
  • Loading branch information
luc-github committed Sep 8, 2019
1 parent 46f2d27 commit 7b2d461
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
18 changes: 18 additions & 0 deletions esp3d/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,19 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
ESPCOM::print ( F ("\",\"H\":\"Notifications Settings\",\"M\":\""), output, espresponse);
ESPCOM::print ( (const char *) CONFIG::intTostr (MIN_NOTIFICATION_SETTINGS_LENGTH), output, espresponse);
ESPCOM::print ( F("\"}"), output, espresponse);
ESPCOM::println (F (","), output, espresponse);
//Auto Notification
ESPCOM::print (F ("{\"F\":\"network\",\"P\":\""), output, espresponse);
ESPCOM::print ( (const char *) CONFIG::intTostr (ESP_AUTO_NOTIFICATION), output, espresponse);
ESPCOM::print (F ("\",\"T\":\"B\",\"V\":\""), output, espresponse);
if (!CONFIG::read_byte (ESP_AUTO_NOTIFICATION, &bbuf ) ) {
ESPCOM::print ("???", output, espresponse);
} else {
ESPCOM::print ( (const char *) CONFIG::intTostr (bbuf), output, espresponse);
}
ESPCOM::print (F ("\",\"H\":\"Auto notification\",\"O\":[{\"No\":\"0\"},{\"Yes\":\"1\"}]}"), output, espresponse);


#endif //NOTIFICATION_FEATURE
}

Expand Down Expand Up @@ -1419,6 +1432,11 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
CONFIG::InitDHT(true);
}
#endif
#ifdef NOTIFICATION_FEATURE
if (pos == ESP_AUTO_NOTIFICATION) {
notificationsservice.setAutonotification ((bbuf == 0)? false: true);
}
#endif
#if defined(TIMESTAMP_FEATURE)
if ( (pos == EP_TIMEZONE) || (pos == EP_TIME_ISDST) || (pos == EP_TIME_SERVER1) || (pos == EP_TIME_SERVER2) || (pos == EP_TIME_SERVER3) ) {
CONFIG::init_time_client();
Expand Down
3 changes: 3 additions & 0 deletions esp3d/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,9 @@ bool CONFIG::reset_config()
if (!CONFIG::write_string (ESP_NOTIFICATION_SETTINGS, DEFAULT_NOTIFICATION_SETTINGS ) ) {
return false;
}
if (!CONFIG::write_byte (ESP_AUTO_NOTIFICATION, DEFAULT_AUTO_NOTIFICATION_STATE) ) {
return false;
}
#endif

return set_EEPROM_version(EEPROM_CURRENT_VERSION);
Expand Down
7 changes: 5 additions & 2 deletions esp3d/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

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

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

//Notifications
#define ESP_PUSHOVER_NOTIFICATION 1
Expand Down
17 changes: 16 additions & 1 deletion esp3d/notifications_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,22 @@ bool Wait4Answer(TSecureClient & client, const char * linetrigger, const char *
return false;
}

bool NotificationsService::sendAutoNotification(const char * msg)
{
if ((WiFi.getMode() == WIFI_AP) || (!_started) || (!_autonotification))return false;
String msgtpl = msg;
//check if has variable to change
if (msgtpl.indexOf("%") != -1) {
msgtpl.replace("%ESP_IP%", WiFi.localIP().toString().c_str());
msgtpl.replace("%ESP_NAME%", wifi_config.get_hostname());
}
return sendMSG("ESP3D Notification", msgtpl.c_str());
}

NotificationsService::NotificationsService()
{
_started = false;
_autonotification = false;
_notificationType = 0;
_token1 = "";
_token1 = "";
Expand Down Expand Up @@ -411,7 +424,9 @@ bool NotificationsService::begin()
return false;
break;
}

if (CONFIG::read_byte (ESP_NOTIFICATION_TYPE, &bbuf ) ) {
_autonotification = (bbuf == 0) ? false: true;
}
if (!res) {
end();
}
Expand Down
4 changes: 4 additions & 0 deletions esp3d/notifications_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ class NotificationsService
bool sendMSG(const char * title, const char * message);
const char * getTypeString();
bool started();
bool isAutonotification() { return _autonotification;};
void setAutonotification(bool value) { _autonotification = value;};
bool sendAutoNotification(const char * msg);
private:
bool _started;
uint8_t _notificationType;
bool _autonotification;
String _token1;
String _token2;
String _settings;
Expand Down
1 change: 1 addition & 0 deletions esp3d/wificonf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ bool WIFI_CONFIG::Enable_servers()
#endif
#if defined(NOTIFICATION_FEATURE)
notificationsservice.begin();
notificationsservice.sendAutoNotification(NOTIFICATION_ESP_ONLINE);
#endif

return true;
Expand Down

0 comments on commit 7b2d461

Please sign in to comment.