mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-06-06 02:36:49 +08:00
Add auto notification
Fix wrong network mode with failing WIFI-STA Add flexible Title for message
This commit is contained in:
parent
11e2722768
commit
e869bab859
@ -139,11 +139,12 @@ ESP_SECONDARY_SD 852//1 bytes = flag
|
||||
ESP_DIRECT_SD_CHECK 853//1 bytes = flag
|
||||
ESP_SD_CHECK_UPDATE_AT_BOOT 854//1 bytes = flag
|
||||
ESP_NOTIFICATION_SETTINGS 855//128 bytes 127+1 = string ; warning does not support multibyte char like chinese
|
||||
ESP_CALIBRATION_1 983
|
||||
ESP_CALIBRATION_2 987
|
||||
ESP_CALIBRATION_3 991
|
||||
ESP_CALIBRATION_4 995
|
||||
ESP_CALIBRATION_5 999
|
||||
ESP_CALIBRATION_1 983 //4 bytes = int
|
||||
ESP_CALIBRATION_2 987 //4 bytes = int
|
||||
ESP_CALIBRATION_3 991 //4 bytes = int
|
||||
ESP_CALIBRATION_4 995 //4 bytes = int
|
||||
ESP_CALIBRATION_5 999 //4 bytes = int
|
||||
ESP_AUTO_NOTIFICATION 1004 //1 byte = flag
|
||||
|
||||
*Get available AP list (limited to 30)
|
||||
output is JSON or plain text according parameter
|
||||
|
@ -154,6 +154,7 @@
|
||||
//DEBUG_OUTPUT_TELNET 4
|
||||
//DEBUG_OUTPUT_WEBSOCKET 5
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
|
||||
#ifdef ESP_DEBUG_FEATURE
|
||||
#define DEBUG_ESP3D_OUTPUT_PORT 8000
|
||||
#endif //ESP_DEBUG_FEATURE
|
||||
@ -214,4 +215,7 @@
|
||||
#define ESP_MANUFACTURER_NAME "Espressif Systems"
|
||||
#define ESP_MANUFACTURER_URL "http://espressif.com"
|
||||
|
||||
#define NOTIFICATION_ESP_ONLINE "Hi, %ESP_NAME% is now online at %ESP_IP%"
|
||||
#define ESP_NOTIFICATION_TITLE "ESP3D Notification"
|
||||
|
||||
#endif //_CONFIGURATION_H
|
||||
|
@ -320,6 +320,12 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printLN ("\"}");
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
//Auto notification
|
||||
output->print (",{\"F\":\"network\",\"P\":\"");
|
||||
output->print (ESP_AUTO_NOTIFICATION);
|
||||
output->print("\",\"T\":\"B\",\"V\":\"");
|
||||
output->print (Settings_ESP3D::read_byte(ESP_AUTO_NOTIFICATION));
|
||||
output->printLN("\",\"H\":\"Auto notification\",\"O\":[{\"No\":\"0\"},{\"Yes\":\"1\"}]}");
|
||||
//Notification type
|
||||
output->print (",{\"F\":\"network\",\"P\":\"");
|
||||
output->print (ESP_NOTIFICATION_TYPE);
|
||||
|
@ -31,6 +31,9 @@
|
||||
#ifdef TIMESTAMP_FEATURE
|
||||
#include "../../modules/time/time_server.h"
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
#include "../../modules/notifications/notifications_service.h"
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
//Set EEPROM setting
|
||||
//[ESP401]P=<position> T=<type> V=<value> pwd=<user/admin password>
|
||||
bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||
@ -72,6 +75,11 @@ bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type,
|
||||
timeserver.begin();
|
||||
break;
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
case ESP_AUTO_NOTIFICATION:
|
||||
notificationsservice.setAutonotification((sval.toInt() == 0)?false:true);
|
||||
break;
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
#ifdef DHT_DEVICE
|
||||
case ESP_DHT_TYPE:
|
||||
esp3d_DHT.begin();
|
||||
|
@ -45,7 +45,7 @@ bool Commands::ESP600(const char* cmd_params, level_authenticate_type auth_type,
|
||||
return false;
|
||||
} else {
|
||||
parameter = get_param (cmd_params, "");
|
||||
if (notificationsservice.sendMSG("ESP3D Notification", parameter.c_str())) {
|
||||
if (notificationsservice.sendMSG(ESP_NOTIFICATION_TITLE, parameter.c_str())) {
|
||||
output->printMSG ("ok");
|
||||
} else {
|
||||
output->printERROR ("Cannot send message!");
|
||||
|
@ -110,6 +110,7 @@
|
||||
#define DEFAULT_NOTIFICATION_TOKEN1 ""
|
||||
#define DEFAULT_NOTIFICATION_TOKEN2 ""
|
||||
#define DEFAULT_NOTIFICATION_SETTINGS ""
|
||||
#define DEFAULT_AUTO_NOTIFICATION_STATE 1
|
||||
|
||||
|
||||
//default int values
|
||||
@ -238,6 +239,9 @@ uint8_t Settings_ESP3D::get_default_byte_value(int pos)
|
||||
case ESP_NOTIFICATION_TYPE:
|
||||
res = DEFAULT_NOTIFICATION_TYPE;
|
||||
break;
|
||||
case ESP_AUTO_NOTIFICATION:
|
||||
res = DEFAULT_AUTO_NOTIFICATION_STATE;
|
||||
break;
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
#if defined (WIFI_FEATURE) || defined (ETH_FEATURE)
|
||||
case ESP_STA_IP_MODE:
|
||||
@ -999,6 +1003,8 @@ bool Settings_ESP3D::reset()
|
||||
Settings_ESP3D::write_string(ESP_HOSTNAME,Settings_ESP3D::get_default_string_value(ESP_HOSTNAME).c_str());
|
||||
#endif //WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
//Auto Notification
|
||||
Settings_ESP3D::write_byte(ESP_AUTO_NOTIFICATION,Settings_ESP3D::get_default_byte_value(ESP_AUTO_NOTIFICATION));
|
||||
//Notification Type
|
||||
Settings_ESP3D::write_byte(ESP_NOTIFICATION_TYPE,Settings_ESP3D::get_default_byte_value(ESP_NOTIFICATION_TYPE));
|
||||
//Notification Token1
|
||||
|
@ -81,11 +81,12 @@
|
||||
#define ESP_DIRECT_SD_CHECK 853//1 bytes = flag
|
||||
#define ESP_SD_CHECK_UPDATE_AT_BOOT 854//1 bytes = flag
|
||||
#define ESP_NOTIFICATION_SETTINGS 855//128 bytes 127+1 = string ; warning does not support multibyte char like chinese
|
||||
#define ESP_CALIBRATION_1 983
|
||||
#define ESP_CALIBRATION_2 987
|
||||
#define ESP_CALIBRATION_3 991
|
||||
#define ESP_CALIBRATION_4 995
|
||||
#define ESP_CALIBRATION_5 999
|
||||
#define ESP_CALIBRATION_1 983 //4 bytes = int
|
||||
#define ESP_CALIBRATION_2 987 //4 bytes = int
|
||||
#define ESP_CALIBRATION_3 991 //4 bytes = int
|
||||
#define ESP_CALIBRATION_4 995 //4 bytes = int
|
||||
#define ESP_CALIBRATION_5 999 //4 bytes = int
|
||||
#define ESP_AUTO_NOTIFICATION 1004 //1 byte = flag
|
||||
|
||||
//Hidden password
|
||||
#define HIDDEN_PASSWORD "********"
|
||||
|
@ -22,7 +22,7 @@
|
||||
#define _VERSION_ESP3D_H
|
||||
|
||||
//version and sources location
|
||||
#define FW_VERSION "3.0.0.a15"
|
||||
#define FW_VERSION "3.0.0.a16"
|
||||
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
||||
|
||||
#endif //_VERSION_ESP3D_H
|
||||
|
@ -244,6 +244,10 @@ bool NetConfig::begin()
|
||||
#if defined (WIFI_FEATURE)
|
||||
if ((espMode == ESP_WIFI_AP) || (espMode == ESP_WIFI_STA)) {
|
||||
res = WiFiConfig::begin();
|
||||
//in case STA failed and fallback to AP mode
|
||||
if (WiFi.getMode() == WIFI_AP) {
|
||||
_mode = ESP_WIFI_AP;
|
||||
}
|
||||
}
|
||||
#endif //WIFI_FEATURE
|
||||
#if defined (ETH_FEATURE)
|
||||
@ -259,6 +263,7 @@ bool NetConfig::begin()
|
||||
#endif //BLUETOOTH_FEATURE
|
||||
//if network is up, let's start services
|
||||
if (res) {
|
||||
_started = true;
|
||||
bool start_services = false;
|
||||
#if defined (ETH_FEATURE)
|
||||
if (EthConfig::started()) {
|
||||
@ -271,6 +276,7 @@ bool NetConfig::begin()
|
||||
}
|
||||
#endif //WIFI_FEATURE
|
||||
if (start_services) {
|
||||
log_esp3d("Starting service");
|
||||
res = NetServices::begin();
|
||||
}
|
||||
}
|
||||
@ -284,9 +290,10 @@ bool NetConfig::begin()
|
||||
#endif //ARDUINO_ARCH_ESP32
|
||||
DEBUG_ESP3D_NETWORK_INIT
|
||||
if (res) {
|
||||
_started = true;
|
||||
log_esp3d("Network config started");
|
||||
} else {
|
||||
end();
|
||||
log_esp3d("Network config failed");
|
||||
}
|
||||
ESP3DGlobalOutput::display_IP();
|
||||
return res;
|
||||
|
@ -250,6 +250,7 @@ bool NetServices::begin()
|
||||
#endif //SSDP_FEATURE
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
notificationsservice.begin();
|
||||
notificationsservice.sendAutoNotification(NOTIFICATION_ESP_ONLINE);
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
if (!res) {
|
||||
end();
|
||||
|
@ -95,6 +95,27 @@ bool Wait4Answer(TSecureClient & client, const char * linetrigger, const char *
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NotificationsService::sendAutoNotification(const char * msg)
|
||||
{
|
||||
if (!(NetConfig::started()) || (NetConfig::getMode() != ESP_WIFI_STA)|| (!_started) || (!_autonotification)) {
|
||||
log_esp3d("Auto notification rejected");
|
||||
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%", NetConfig::hostname());
|
||||
}
|
||||
if (!sendMSG(ESP_NOTIFICATION_TITLE, msgtpl.c_str())) {
|
||||
log_esp3d("Auto notification failed");
|
||||
return false;
|
||||
} else {
|
||||
log_esp3d("Auto notification sent");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
NotificationsService::NotificationsService()
|
||||
{
|
||||
_started = false;
|
||||
@ -397,7 +418,7 @@ bool NotificationsService::begin()
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
_autonotification = (Settings_ESP3D::read_byte(ESP_AUTO_NOTIFICATION) == 0) ? false: true;
|
||||
if (!res) {
|
||||
end();
|
||||
}
|
||||
|
@ -35,8 +35,18 @@ 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;
|
||||
bool _autonotification;
|
||||
uint8_t _notificationType;
|
||||
String _token1;
|
||||
String _token2;
|
||||
|
Loading…
x
Reference in New Issue
Block a user