mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-11 23:58:58 +08:00
Add auto notification setting
Alllow to automaticatilly send notification when device is online
This commit is contained in:
parent
46f2d27a7b
commit
7b2d4612df
@ -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
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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 ////////////////////////////////////////////////////////////////////////
|
||||
@ -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
|
||||
@ -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
|
||||
|
@ -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 = "";
|
||||
@ -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();
|
||||
}
|
||||
|
@ -35,9 +35,13 @@ public:
|
||||
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;
|
||||
|
@ -673,6 +673,7 @@ bool WIFI_CONFIG::Enable_servers()
|
||||
#endif
|
||||
#if defined(NOTIFICATION_FEATURE)
|
||||
notificationsservice.begin();
|
||||
notificationsservice.sendAutoNotification(NOTIFICATION_ESP_ONLINE);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user