mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 07:39:01 +08:00
Code sync with upstream
Code clening Add Boot delay as parameter in EEPROM for easier tuning Add Notifications
This commit is contained in:
parent
1ab596d610
commit
3b9d5302a1
@ -53,6 +53,9 @@ Note:
|
||||
* Init / Get current time
|
||||
[ESP140]<INIT> <srv1=XXXXX> <srv2=XXXXX> <srv3=XXXXX> <zone=xxx> <dst=YES/NO> <time=YYYY-MM-DD#H24:MM:SS> pwd=<admin password>
|
||||
|
||||
* Get/Set boot delay
|
||||
[ESP150]<time in milliseconds>[pwd=<admin password>]
|
||||
|
||||
*Get/Set pin value
|
||||
[ESP201]P<pin> V<value> [PULLUP=YES RAW=YES]pwd=<admin password>
|
||||
if no V<value> get P<pin> value
|
||||
@ -130,6 +133,13 @@ cmd are RESTART / RESET
|
||||
* Change user password
|
||||
[ESP555]<password>pwd=<admin/user password>
|
||||
|
||||
* Send Notification
|
||||
[ESP600]msg [pwd=<admin password>]
|
||||
|
||||
* Set/Get Notification settings
|
||||
[ESP610]type=<NONE/PUSHOVER/EMAIL/LINE> T1=<token1> T2=<token2> TS=<Settings> [pwd=<admin password>]
|
||||
Get will give type and settings only, not the protected T1/T2
|
||||
|
||||
* Format ESP Filesystem
|
||||
[ESP710]FORMAT pwd=<admin password>
|
||||
|
||||
|
@ -107,9 +107,7 @@
|
||||
#define WEB_UPDATE_FEATURE
|
||||
|
||||
//NOTIFICATION_FEATURE : allow to push notifications
|
||||
//ESP_PUSHOVER_NOTIFICATION 1
|
||||
//ESP_EMAIL_NOTIFICATION 2
|
||||
//#define NOTIFICATION_FEATURE ESP_PUSHOVER_NOTIFICATION
|
||||
#define NOTIFICATION_FEATURE
|
||||
|
||||
//Extra features /////////////////////////////////////////////////////////////////////////
|
||||
/************************************
|
||||
|
@ -306,6 +306,11 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
|
||||
response = ESP140(cmd_params, auth_type, output);
|
||||
break;
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
//Get/Set boot delay
|
||||
//[ESP150]<time>[pwd=<admin password>]
|
||||
case 150:
|
||||
response = ESP150(cmd_params, auth_type, output);
|
||||
break;
|
||||
#ifdef DIRECT_PIN_FEATURE
|
||||
//Get/Set pin value
|
||||
//[ESP201]P<pin> V<value> [PULLUP=YES RAW=YES]pwd=<admin password>
|
||||
@ -362,13 +367,19 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
|
||||
response = ESP555(cmd_params, auth_type, output);
|
||||
break;
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
#if defined( WIFI_FEATURE) || defined (ETH_FEATURE)
|
||||
#if defined(NOTIFICATION_FEATURE)
|
||||
//Send Notification
|
||||
//[ESP600]<msg>[pwd=<admin password>]
|
||||
case 600:
|
||||
response = ESP600(cmd_params, auth_type, output);
|
||||
break;
|
||||
#endif //WIFI_FEATURE || ETH_FEATURE+
|
||||
//Set/Get Notification settings
|
||||
//[ESP610]type=<NONE/PUSHOVER/EMAIL/LINE> T1=<token1> T2=<token2> TS=<Settings> [pwd=<admin password>]
|
||||
//Get will give type and settings only not the protected T1/T2
|
||||
case 610:
|
||||
response = ESP610(cmd_params, auth_type, output);
|
||||
break;
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
#ifdef FILESYSTEM_FEATURE
|
||||
//Format ESP Filesystem
|
||||
//[ESP710]FORMAT pwd=<admin password>
|
||||
|
@ -70,6 +70,7 @@ public:
|
||||
#if defined(TIMESTAMP_FEATURE)
|
||||
bool ESP140(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
bool ESP150(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#ifdef DIRECT_PIN_FEATURE
|
||||
bool ESP201(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#endif //DIRECT_PIN_FEATURE
|
||||
@ -87,9 +88,10 @@ public:
|
||||
bool ESP550(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
bool ESP555(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
#if defined( WIFI_FEATURE) || defined (ETH_FEATURE)
|
||||
#if defined(NOTIFICATION_FEATURE)
|
||||
bool ESP600(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#endif //WIFI_FEATURE || ETH_FEATURE
|
||||
bool ESP610(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
#if defined(FILESYSTEM_FEATURE)
|
||||
bool ESP710(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
bool ESP720(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
|
@ -42,6 +42,7 @@
|
||||
#endif //DISPLAY_DEVICE
|
||||
|
||||
#include "esp3doutput.h"
|
||||
#include "../modules/boot_delay/boot_delay.h"
|
||||
|
||||
bool Esp3D::restart = false;
|
||||
|
||||
@ -58,11 +59,11 @@ Esp3D::~Esp3D()
|
||||
}
|
||||
|
||||
//Begin which setup everything
|
||||
bool Esp3D::begin(uint16_t startdelayms)
|
||||
bool Esp3D::begin()
|
||||
{
|
||||
BootDelay bd;
|
||||
Hal::begin();
|
||||
DEBUG_ESP3D_INIT
|
||||
|
||||
bool res = true;
|
||||
#if defined(CONNECTED_DEVICES_FEATURE)
|
||||
if (!DevicesServices::begin()) {
|
||||
@ -70,8 +71,8 @@ bool Esp3D::begin(uint16_t startdelayms)
|
||||
res = false;
|
||||
}
|
||||
#endif //CONNECTED_DEVICES_FEATURE
|
||||
//delay() to avoid to disturb printer
|
||||
delay(startdelayms);
|
||||
//delayto avoid to disturb printer
|
||||
bd.begin(/*&outserialfn*/);
|
||||
log_esp3d("Mode %d", WiFi.getMode());
|
||||
|
||||
if (!Settings_ESP3D::begin()) {
|
||||
|
@ -30,7 +30,7 @@ class Esp3D
|
||||
public:
|
||||
Esp3D();
|
||||
~Esp3D();
|
||||
bool begin(uint16_t startdelayms = 500);
|
||||
bool begin();
|
||||
void handle();
|
||||
bool end();
|
||||
static bool reset();
|
||||
|
63
esp3d/src/core/espcmd/ESP150.cpp
Normal file
63
esp3d/src/core/espcmd/ESP150.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
ESP150.cpp - ESP3D command class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "../../include/esp3d_config.h"
|
||||
#include "../commands.h"
|
||||
#include "../esp3doutput.h"
|
||||
#include "../settings_esp3d.h"
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
//Get/Set boot delay
|
||||
//[ESP150]<time>[pwd=<admin password>]
|
||||
bool Commands::ESP150(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||
{
|
||||
bool response = true;
|
||||
String parameter;
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
if (auth_type == LEVEL_GUEST) {
|
||||
output->printERROR("Wrong authentication!", 401);
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
(void)auth_type;
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
parameter = get_param (cmd_params, "");
|
||||
//get
|
||||
if (parameter.length() == 0) {
|
||||
output->printMSG(String(Settings_ESP3D::read_uint32(ESP_BOOT_DELAY)).c_str());
|
||||
} else {
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
if (auth_type != LEVEL_ADMIN) {
|
||||
output->printERROR("Wrong authentication!", 401);
|
||||
return false;
|
||||
}
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
uint ibuf = parameter.toInt();
|
||||
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_BOOT_DELAY)) || (ibuf < Settings_ESP3D::get_min_int32_value(ESP_BOOT_DELAY))) {
|
||||
output->printERROR ("Incorrect delay!");
|
||||
return false;
|
||||
}
|
||||
if (!Settings_ESP3D::write_uint32 (ESP_BOOT_DELAY, ibuf)) {
|
||||
output->printERROR ("Set failed!");
|
||||
response = false;
|
||||
} else {
|
||||
output->printMSG ("ok");
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
@ -341,6 +341,50 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->print (Settings_ESP3D::get_min_string_size(ESP_TIME_SERVER3));
|
||||
output->printLN ("\"}");
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
//Notification type
|
||||
output->print (",{\"F\":\"network\",\"P\":\"");
|
||||
output->print (ESP_NOTIFICATION_TYPE);
|
||||
output->print ("\",\"T\":\"B\",\"V\":\"");
|
||||
output->print (Settings_ESP3D::read_byte(ESP_NOTIFICATION_TYPE));
|
||||
output->print ("\",\"H\":\"Notification\",\"O\":[{\"None\":\"0\"},{\"Pushover\":\"");
|
||||
output->print (ESP_PUSHOVER_NOTIFICATION);
|
||||
output->print ("\"},{\"Email\":\"");
|
||||
output->print (ESP_EMAIL_NOTIFICATION);
|
||||
output->print ("\"},{\"Line\":\"");
|
||||
output->print (ESP_LINE_NOTIFICATION);
|
||||
output->printLN ("\"}]}");
|
||||
//Token 1
|
||||
output->print (",{\"F\":\"network\",\"P\":\"");
|
||||
output->print (ESP_NOTIFICATION_TOKEN1);
|
||||
output->print ("\",\"T\":\"S\",\"V\":\"");
|
||||
output->print (HIDDEN_PASSWORD);
|
||||
output->print ("\",\"S\":\"");
|
||||
output->print (Settings_ESP3D::get_max_string_size(ESP_NOTIFICATION_TOKEN1));
|
||||
output->print ("\",\"H\":\"Token 1\",\"M\":\"");
|
||||
output->print (Settings_ESP3D::get_min_string_size(ESP_NOTIFICATION_TOKEN1));
|
||||
output->printLN ("\"}");
|
||||
//Token 2
|
||||
output->print (",{\"F\":\"network\",\"P\":\"");
|
||||
output->print (ESP_NOTIFICATION_TOKEN2);
|
||||
output->print ("\",\"T\":\"S\",\"V\":\"");
|
||||
output->print (HIDDEN_PASSWORD);
|
||||
output->print ("\",\"S\":\"");
|
||||
output->print (Settings_ESP3D::get_max_string_size(ESP_NOTIFICATION_TOKEN2));
|
||||
output->print ("\",\"H\":\"Token 2\",\"M\":\"");
|
||||
output->print (Settings_ESP3D::get_min_string_size(ESP_NOTIFICATION_TOKEN2));
|
||||
output->printLN ("\"}");
|
||||
//Notifications Settings
|
||||
output->print (",{\"F\":\"network\",\"P\":\"");
|
||||
output->print (ESP_NOTIFICATION_SETTINGS);
|
||||
output->print ("\",\"T\":\"S\",\"V\":\"");
|
||||
output->print (Settings_ESP3D::read_string(ESP_NOTIFICATION_SETTINGS));
|
||||
output->print ("\",\"S\":\"");
|
||||
output->print (Settings_ESP3D::get_max_string_size(ESP_NOTIFICATION_SETTINGS));
|
||||
output->print ("\",\"H\":\"Notifications Settings\",\"M\":\"");
|
||||
output->print (Settings_ESP3D::get_min_string_size(ESP_NOTIFICATION_SETTINGS));
|
||||
output->printLN ("\"}");
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
//Target FW
|
||||
output->print (",{\"F\":\"printer\",\"P\":\"");
|
||||
output->print (ESP_TARGET_FW);
|
||||
@ -384,7 +428,16 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->print (Settings_ESP3D::get_min_int32_value(ESP_DHT_INTERVAL));
|
||||
output->printLN ("\"}");
|
||||
#endif //DHT_DEVICE
|
||||
|
||||
//Start delay
|
||||
output->print (",{\"F\":\"printer\",\"P\":\"");
|
||||
output->print (ESP_BOOT_DELAY);
|
||||
output->print ("\",\"T\":\"I\",\"V\":\"");
|
||||
output->print (Settings_ESP3D::read_uint32(ESP_BOOT_DELAY));
|
||||
output->print ("\",\"H\":\"Start delay\",\"S\":\"");
|
||||
output->print (Settings_ESP3D::get_max_int32_value(ESP_BOOT_DELAY));
|
||||
output->print ("\",\"M\":\"");
|
||||
output->print (Settings_ESP3D::get_min_int32_value(ESP_BOOT_DELAY));
|
||||
output->printLN ("\"}");
|
||||
//Output flag
|
||||
output->print (",{\"F\":\"printer\",\"P\":\"");
|
||||
output->print (ESP_OUTPUT_FLAG);
|
||||
|
@ -50,6 +50,9 @@
|
||||
#if defined (DHT_DEVICE)
|
||||
#include "../../modules/dht/dht.h"
|
||||
#endif //DHT_DEVICE
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
#include "../../modules/notifications/notifications_service.h"
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
//Get ESP current status
|
||||
//output is JSON or plain text according parameter
|
||||
//[ESP420]<plain>
|
||||
@ -948,6 +951,28 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printLN("");
|
||||
}
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
#if defined (NOTIFICATION_FEATURE)
|
||||
if (!plain) {
|
||||
output->print (",{\"id\":\"");
|
||||
}
|
||||
output->print ("Notification");
|
||||
if (!plain) {
|
||||
output->print ("\",\"value\":\"");
|
||||
} else {
|
||||
output->print (": ");
|
||||
}
|
||||
output->print (notificationsservice.started()?"Enabled":"Disabled");
|
||||
if (notificationsservice.started()) {
|
||||
output->print ("(");
|
||||
output->print (notificationsservice.getTypeString());
|
||||
output->print (")");
|
||||
}
|
||||
if (!plain) {
|
||||
output->print ("\"}");
|
||||
} else {
|
||||
output->printLN("");
|
||||
}
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
#if defined (DHT_DEVICE)
|
||||
if (!plain) {
|
||||
output->print (",{\"id\":\"");
|
||||
|
@ -18,13 +18,14 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "../../include/esp3d_config.h"
|
||||
#if defined (WIFI_FEATURE) || defined (ETH_FEATURE)
|
||||
#if defined (NOTIFICATION_FEATURE)
|
||||
#include "../commands.h"
|
||||
#include "../esp3doutput.h"
|
||||
#include "../settings_esp3d.h"
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
#include "../../modules/notifications/notifications_service.h"
|
||||
//Send Notification
|
||||
//[ESP600]<msg>[pwd=<admin password>]
|
||||
//[ESP600]msg [pwd=<admin password>]
|
||||
bool Commands::ESP600(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||
{
|
||||
bool response = true;
|
||||
@ -43,10 +44,15 @@ bool Commands::ESP600(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printERROR ("Invalid message!");
|
||||
return false;
|
||||
} else {
|
||||
//TODO
|
||||
parameter = get_param (cmd_params, "");
|
||||
if (notificationsservice.sendMSG("ESP3D Notification", parameter.c_str())) {
|
||||
output->printMSG ("ok");
|
||||
} else {
|
||||
output->printERROR ("Cannot send message!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
#endif //WIFI_FEATURE || ETH_FEATURE
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
|
118
esp3d/src/core/espcmd/ESP610.cpp
Normal file
118
esp3d/src/core/espcmd/ESP610.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
ESP610.cpp - ESP3D command class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "../../include/esp3d_config.h"
|
||||
#if defined (NOTIFICATION_FEATURE)
|
||||
#include "../commands.h"
|
||||
#include "../esp3doutput.h"
|
||||
#include "../settings_esp3d.h"
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
#include "../../modules/notifications/notifications_service.h"
|
||||
//Set/Get Notification settings
|
||||
//[ESP610]type=<NONE/PUSHOVER/EMAIL/LINE> T1=<token1> T2=<token2> TS=<Settings> [pwd=<admin password>]
|
||||
//Get will give type and settings only not the protected T1/T2
|
||||
bool Commands::ESP610(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||
{
|
||||
bool response = true;
|
||||
String parameter;
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
if (auth_type == LEVEL_GUEST) {
|
||||
output->printERROR("Wrong authentication!", 401);
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
(void)auth_type;
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
parameter = get_param (cmd_params, "");
|
||||
//get
|
||||
if (parameter.length() == 0) {
|
||||
uint8_t Ntype = Settings_ESP3D::read_byte(ESP_NOTIFICATION_TYPE);
|
||||
static String tmp;
|
||||
tmp = (Ntype == ESP_PUSHOVER_NOTIFICATION)?"PUSHOVER":(Ntype == ESP_EMAIL_NOTIFICATION)?"EMAIL":(Ntype == ESP_LINE_NOTIFICATION)?"LINE":"NONE";
|
||||
tmp+= " ";
|
||||
tmp+= Settings_ESP3D::read_string(ESP_NOTIFICATION_SETTINGS);
|
||||
output->printMSG (tmp.c_str());
|
||||
} else {
|
||||
response = false;
|
||||
//type
|
||||
parameter = get_param (cmd_params, "type=");
|
||||
if (parameter.length() > 0) {
|
||||
uint8_t Ntype;
|
||||
parameter.toUpperCase();
|
||||
if (parameter == "NONE") {
|
||||
Ntype = 0;
|
||||
} else if (parameter == "PUSHOVER") {
|
||||
Ntype = ESP_PUSHOVER_NOTIFICATION;
|
||||
} else if (parameter == "EMAIL") {
|
||||
Ntype = ESP_EMAIL_NOTIFICATION;
|
||||
} else if (parameter == "LINE") {
|
||||
Ntype = ESP_LINE_NOTIFICATION;
|
||||
} else {
|
||||
output->printERROR("Only NONE, PUSHOVER, EMAIL, LINE are supported!");
|
||||
return false;
|
||||
}
|
||||
if(!Settings_ESP3D::write_byte(ESP_NOTIFICATION_TYPE, Ntype)) {
|
||||
output->printERROR ("Set failed!");
|
||||
return false;
|
||||
} else {
|
||||
response = true;
|
||||
}
|
||||
}
|
||||
//Settings
|
||||
parameter = get_param (cmd_params, "TS=");
|
||||
if (parameter.length() > 0) {
|
||||
if(!Settings_ESP3D::write_string(ESP_NOTIFICATION_SETTINGS, parameter.c_str())) {
|
||||
output->printERROR ("Set failed!");
|
||||
return false;
|
||||
} else {
|
||||
response = true;
|
||||
}
|
||||
}
|
||||
//Token1
|
||||
parameter = get_param (cmd_params, "T1=");
|
||||
if (parameter.length() > 0) {
|
||||
if(!Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN1, parameter.c_str())) {
|
||||
output->printERROR ("Set failed!");
|
||||
return false;
|
||||
} else {
|
||||
response = true;
|
||||
}
|
||||
}
|
||||
//Token2
|
||||
parameter = get_param (cmd_params, "T2=");
|
||||
if (parameter.length() > 0) {
|
||||
if(!Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN2, parameter.c_str())) {
|
||||
output->printERROR ("Set failed!");
|
||||
return false;
|
||||
} else {
|
||||
response = true;
|
||||
}
|
||||
}
|
||||
if (response) {
|
||||
//Restart service
|
||||
notificationsservice.begin();
|
||||
output->printMSG ("ok");
|
||||
} else {
|
||||
output->printERROR ("Invalid parameter! Only type, T1, T2 and TS are supported");
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
#endif //NOTIFICATION_FEATURE
|
@ -43,14 +43,22 @@
|
||||
#endif // SETTINGS_IN_PREFERENCES
|
||||
|
||||
//Current Settings Version
|
||||
#define CURRENT_SETTINGS_VERSION "ESP3D03"
|
||||
#define CURRENT_SETTINGS_VERSION "ESP3D04"
|
||||
|
||||
//boundaries
|
||||
#define MAX_DHT_INTERVAL 1000
|
||||
#define MAX_DHT_INTERVAL 60000
|
||||
#define MIN_DHT_INTERVAL 0
|
||||
#define MAX_LOCAL_PASSWORD_LENGTH 20
|
||||
#define MIN_LOCAL_PASSWORD_LENGTH 1
|
||||
#define MAX_VERSION_LENGTH 7 //ESP3DXX
|
||||
#define MAX_BOOT_DELAY 40000
|
||||
#define MIN_BOOT_DELAY 0
|
||||
#define MIN_NOTIFICATION_TOKEN_LENGTH 0
|
||||
#define MIN_NOTIFICATION_SETTINGS_LENGTH 0
|
||||
#define MAX_NOTIFICATION_TOKEN_LENGTH 63
|
||||
#define MAX_NOTIFICATION_SETTINGS_LENGTH 127
|
||||
#define MAX_SERVER_ADDRESS_LENGTH 128
|
||||
#define MIN_SERVER_ADDRESS_LENGTH 0
|
||||
|
||||
|
||||
//default byte values
|
||||
@ -92,6 +100,10 @@
|
||||
#define DEFAULT_IS_DIRECT_SD 0
|
||||
#define DEFAULT_HTTP_ON 1
|
||||
#define DEFAULT_TELNET_ON 1
|
||||
#define DEFAULT_NOTIFICATION_TYPE 0
|
||||
#define DEFAULT_NOTIFICATION_TOKEN1 ""
|
||||
#define DEFAULT_NOTIFICATION_TOKEN2 ""
|
||||
#define DEFAULT_NOTIFICATION_SETTINGS ""
|
||||
|
||||
|
||||
//default int values
|
||||
@ -100,6 +112,7 @@
|
||||
#define DEFAULT_HTTP_PORT 80L
|
||||
#define DEFAULT_TELNET_PORT 23L
|
||||
#define DEFAULT_DHT_INTERVAL 30000L
|
||||
#define DEFAULT_BOOT_DELAY 10000L
|
||||
|
||||
#ifdef WIFI_FEATURE
|
||||
//default string values
|
||||
@ -202,6 +215,11 @@ uint8_t Settings_ESP3D::get_default_byte_value(int pos)
|
||||
case ESP_RADIO_MODE:
|
||||
res = DEFAULT_ESP_RADIO_MODE;
|
||||
break;
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
case ESP_NOTIFICATION_TYPE:
|
||||
res = DEFAULT_NOTIFICATION_TYPE;
|
||||
break;
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
#if defined (WIFI_FEATURE) || defined (ETH_FEATURE)
|
||||
case ESP_STA_IP_MODE:
|
||||
res = DEFAULT_STA_IP_MODE;
|
||||
@ -289,6 +307,9 @@ uint32_t Settings_ESP3D::get_default_int32_value(int pos)
|
||||
case ESP_BAUD_RATE:
|
||||
res = DEFAULT_BAUD_RATE;
|
||||
break;
|
||||
case ESP_BOOT_DELAY:
|
||||
res = DEFAULT_BOOT_DELAY;
|
||||
break;
|
||||
#if defined (WIFI_FEATURE) || defined (ETH_FEATURE)
|
||||
case ESP_AP_IP_VALUE:
|
||||
case ESP_STA_IP_VALUE:
|
||||
@ -327,6 +348,9 @@ uint32_t Settings_ESP3D::get_max_int32_value(int pos)
|
||||
{
|
||||
uint32_t res;
|
||||
switch(pos) {
|
||||
case ESP_BOOT_DELAY:
|
||||
res = MAX_BOOT_DELAY;
|
||||
break;
|
||||
#ifdef HTTP_FEATURE
|
||||
case ESP_HTTP_PORT:
|
||||
res = MAX_HTTP_PORT;
|
||||
@ -353,6 +377,9 @@ uint32_t Settings_ESP3D::get_min_int32_value(int pos)
|
||||
{
|
||||
uint32_t res;
|
||||
switch(pos) {
|
||||
case ESP_BOOT_DELAY:
|
||||
res = MIN_BOOT_DELAY;
|
||||
break;
|
||||
#ifdef HTTP_FEATURE
|
||||
case ESP_HTTP_PORT:
|
||||
res = MIN_HTTP_PORT;
|
||||
@ -393,6 +420,7 @@ uint8_t Settings_ESP3D::get_max_byte(int pos)
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
uint8_t Settings_ESP3D::get_min_byte(int pos)
|
||||
{
|
||||
uint8_t res;
|
||||
@ -413,7 +441,6 @@ uint8_t Settings_ESP3D::get_min_byte(int pos)
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
//Default value for a ip setting
|
||||
uint32_t Settings_ESP3D::get_default_IP_value(int pos)
|
||||
{
|
||||
@ -429,6 +456,7 @@ const String & Settings_ESP3D::get_default_string_value(int pos)
|
||||
case ESP_HOSTNAME:
|
||||
res = DEFAULT_HOSTNAME;
|
||||
break;
|
||||
#endif //WIFI_FEATURE || ETH_FEATURE || defined (ETH_FEATURE)
|
||||
#ifdef TIMESTAMP_FEATURE
|
||||
case ESP_TIME_SERVER1:
|
||||
res = DEFAULT_TIME_SERVER1;
|
||||
@ -440,7 +468,17 @@ const String & Settings_ESP3D::get_default_string_value(int pos)
|
||||
res = DEFAULT_TIME_SERVER3;
|
||||
break;
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
#endif //WIFI_FEATURE || ETH_FEATURE || defined (ETH_FEATURE)
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
case ESP_NOTIFICATION_TOKEN1:
|
||||
res = DEFAULT_NOTIFICATION_TOKEN1;
|
||||
break;
|
||||
case ESP_NOTIFICATION_TOKEN2:
|
||||
res = DEFAULT_NOTIFICATION_TOKEN2;
|
||||
break;
|
||||
case ESP_NOTIFICATION_SETTINGS:
|
||||
res = DEFAULT_NOTIFICATION_SETTINGS;
|
||||
break;
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
#if defined (WIFI_FEATURE)
|
||||
case ESP_STA_SSID:
|
||||
res = DEFAULT_STA_SSID;
|
||||
@ -489,7 +527,15 @@ uint8_t Settings_ESP3D::get_max_string_size(int pos)
|
||||
res = MAX_SERVER_ADDRESS_LENGTH;
|
||||
break;
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
case ESP_NOTIFICATION_TOKEN1:
|
||||
case ESP_NOTIFICATION_TOKEN2:
|
||||
res = MAX_NOTIFICATION_TOKEN_LENGTH;
|
||||
break;
|
||||
case ESP_NOTIFICATION_SETTINGS:
|
||||
res = MAX_NOTIFICATION_SETTINGS_LENGTH;
|
||||
break;
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
#if defined (WIFI_FEATURE)
|
||||
case ESP_STA_SSID:
|
||||
case ESP_AP_SSID:
|
||||
@ -524,6 +570,16 @@ uint8_t Settings_ESP3D::get_min_string_size(int pos)
|
||||
case ESP_HOSTNAME:
|
||||
res = MIN_HOSTNAME_LENGTH;
|
||||
break;
|
||||
#endif //WIFI_FEATURE || ETH_FEATURE || BLUETOOTH_FEATURE
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
case ESP_NOTIFICATION_TOKEN1:
|
||||
case ESP_NOTIFICATION_TOKEN2:
|
||||
res = MIN_NOTIFICATION_TOKEN_LENGTH;
|
||||
break;
|
||||
case ESP_NOTIFICATION_SETTINGS:
|
||||
res = MIN_NOTIFICATION_SETTINGS_LENGTH;
|
||||
break;
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
#ifdef TIMESTAMP_FEATURE
|
||||
case ESP_TIME_SERVER1:
|
||||
case ESP_TIME_SERVER2:
|
||||
@ -531,7 +587,6 @@ uint8_t Settings_ESP3D::get_min_string_size(int pos)
|
||||
res = MIN_SERVER_ADDRESS_LENGTH;
|
||||
break;
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
#endif //WIFI_FEATURE || ETH_FEATURE || BLUETOOTH_FEATURE
|
||||
#if defined (WIFI_FEATURE)
|
||||
case ESP_STA_SSID:
|
||||
case ESP_AP_SSID:
|
||||
@ -876,6 +931,16 @@ bool Settings_ESP3D::reset()
|
||||
//Hostname
|
||||
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
|
||||
//Notification Type
|
||||
Settings_ESP3D::write_byte(ESP_NOTIFICATION_TYPE,Settings_ESP3D::get_default_byte_value(ESP_NOTIFICATION_TYPE));
|
||||
//Notification Token1
|
||||
Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN1,Settings_ESP3D::get_default_string_value(ESP_NOTIFICATION_TOKEN1).c_str());
|
||||
//Notification Token2
|
||||
Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN2,Settings_ESP3D::get_default_string_value(ESP_NOTIFICATION_TOKEN2).c_str());
|
||||
//Notification Settings
|
||||
Settings_ESP3D::write_string(ESP_NOTIFICATION_SETTINGS,Settings_ESP3D::get_default_string_value(ESP_NOTIFICATION_SETTINGS).c_str());
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
//radio mode
|
||||
Settings_ESP3D::write_byte(ESP_RADIO_MODE,Settings_ESP3D::get_default_byte_value(ESP_RADIO_MODE));
|
||||
#if defined (WIFI_FEATURE)
|
||||
@ -957,6 +1022,8 @@ bool Settings_ESP3D::reset()
|
||||
//DHT query interval
|
||||
Settings_ESP3D::write_uint32 (ESP_DHT_INTERVAL, Settings_ESP3D::get_default_int32_value(ESP_DHT_INTERVAL));
|
||||
#endif //DHT_DEVICE
|
||||
//Start Delay
|
||||
Settings_ESP3D::write_uint32 (ESP_BOOT_DELAY, Settings_ESP3D::get_default_int32_value(ESP_BOOT_DELAY));
|
||||
#endif //SETTINGS_IN_EEPROM
|
||||
//set version in settings
|
||||
if (res) {
|
||||
|
@ -43,7 +43,7 @@
|
||||
#define ESP_STA_MASK_VALUE 104 //4 bytes xxx.xxx.xxx.xxx
|
||||
#define ESP_STA_GATEWAY_VALUE 108 //4 bytes xxx.xxx.xxx.xxx
|
||||
#define ESP_BAUD_RATE 112 //4 bytes = int
|
||||
//#define ESP_STA_PHY_MODE 116 //1 byte = flag
|
||||
#define ESP_NOTIFICATION_TYPE 116 //1 byte = flag
|
||||
//#define ESP_SLEEP_MODE 117 //1 byte = flag
|
||||
#define ESP_AP_CHANNEL 118 //1 byte = flag
|
||||
//#define ESP_AP_AUTH_TYPE 119 //1 byte = flag
|
||||
@ -59,13 +59,14 @@
|
||||
#define ESP_AP_SSID 218 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese
|
||||
#define ESP_AP_PASSWORD 251 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese
|
||||
#define ESP_AP_IP_VALUE 316 //4 bytes xxx.xxx.xxx.xxx
|
||||
//#define EP_FREE_INT4 320 //4 bytes xxx.xxx.xxx.xxx
|
||||
#define ESP_BOOT_DELAY 320 //4 bytes xxx.xxx.xxx.xxx
|
||||
//#define EP_FREE_INT5 324 //4 bytes xxx.xxx.xxx.xxx
|
||||
#define ESP_HTTP_ON 328 //1 byte = flag
|
||||
#define ESP_TELNET_ON 329 //1 byte = flag
|
||||
//#define ESP_AP_PHY_MODE 330 //1 byte = flag
|
||||
#define ESP_SD_SPEED_DIV 331 //1 byte = flag
|
||||
//#define EP_FREE_STRING1 332//128 bytes 127+1 = string ; warning does not support multibyte char like chinese
|
||||
#define ESP_NOTIFICATION_TOKEN1 332 //64 bytes 63+1 = string ; warning does not support multibyte char like chinese
|
||||
#define ESP_NOTIFICATION_TOKEN2 396 //64 bytes 63+1 = string ; warning does not support multibyte char like chinese
|
||||
#define ESP_DHT_TYPE 460//1 bytes = flag
|
||||
#define ESP_TARGET_FW 461 //1 bytes = flag
|
||||
#define ESP_TIMEZONE 462//1 bytes = flag
|
||||
@ -78,7 +79,7 @@
|
||||
#define ESP_SECONDARY_SD 852//1 bytes = flag
|
||||
#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
|
||||
//Hidden password
|
||||
#define HIDDEN_PASSWORD "********"
|
||||
|
||||
|
@ -47,6 +47,7 @@
|
||||
//Notifications
|
||||
#define ESP_PUSHOVER_NOTIFICATION 1
|
||||
#define ESP_EMAIL_NOTIFICATION 2
|
||||
#define ESP_LINE_NOTIFICATION 3
|
||||
|
||||
//DHT
|
||||
#define DHT11_DEVICE 1
|
||||
|
88
esp3d/src/modules/boot_delay/boot_delay.cpp
Normal file
88
esp3d/src/modules/boot_delay/boot_delay.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
boot_delay.cpp - boot delay functions class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../../include/esp3d_config.h"
|
||||
#include "boot_delay.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
|
||||
BootDelay::BootDelay()
|
||||
{
|
||||
_started = false;
|
||||
_callbackfn = nullptr;
|
||||
_startdelay = 0;
|
||||
_totalduration = 0;
|
||||
}
|
||||
BootDelay::~BootDelay()
|
||||
{
|
||||
end();
|
||||
}
|
||||
|
||||
bool BootDelay::started()
|
||||
{
|
||||
return _started;
|
||||
}
|
||||
|
||||
bool BootDelay::begin(progress_t* fn)
|
||||
{
|
||||
_totalduration = Settings_ESP3D::read_uint32(ESP_BOOT_DELAY);
|
||||
log_esp3d("Boot delay %d", _totalduration);
|
||||
if (_totalduration > Settings_ESP3D::get_max_int32_value(ESP_BOOT_DELAY)) {
|
||||
_totalduration = Settings_ESP3D::get_max_int32_value(ESP_BOOT_DELAY);
|
||||
log_esp3d("Boot delay modified %d", _totalduration);
|
||||
}
|
||||
_callbackfn = fn;
|
||||
_started = true;
|
||||
if(_callbackfn) {
|
||||
(*_callbackfn)(0);
|
||||
}
|
||||
if (_totalduration > 0) {
|
||||
_startdelay = millis();
|
||||
handle();
|
||||
}
|
||||
if(_callbackfn) {
|
||||
(*_callbackfn)(100);
|
||||
}
|
||||
log_esp3d("Boot delay done");
|
||||
return _started;
|
||||
}
|
||||
void BootDelay::end()
|
||||
{
|
||||
}
|
||||
|
||||
void BootDelay::handle()
|
||||
{
|
||||
uint8_t lastpercent = 0;
|
||||
uint32_t lastSent = millis();
|
||||
while ((millis() - _startdelay) < _totalduration) {
|
||||
//to avoid overfload 2x/sec is enough for progression
|
||||
if ((millis() - lastSent) > 500) {
|
||||
lastSent = millis();
|
||||
uint8_t p = (100*(millis() - _startdelay))/_totalduration;
|
||||
if (p != lastpercent) {
|
||||
lastpercent=p;
|
||||
if(_callbackfn && p!=100) {
|
||||
(*_callbackfn)(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
Hal::wait(10);
|
||||
}
|
||||
}
|
45
esp3d/src/modules/boot_delay/boot_delay.h
Normal file
45
esp3d/src/modules/boot_delay/boot_delay.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
boot_delay.h - boot delay functions class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _BOOT_DELAY_H
|
||||
#define _BOOT_DELAY_H
|
||||
|
||||
typedef void (progress_t)(uint8_t percent);
|
||||
|
||||
class BootDelay
|
||||
{
|
||||
public:
|
||||
BootDelay();
|
||||
~BootDelay();
|
||||
bool begin(progress_t* fn = nullptr);
|
||||
void end();
|
||||
void handle();
|
||||
bool started();
|
||||
private:
|
||||
bool _started;
|
||||
progress_t * _callbackfn;
|
||||
uint32_t _startdelay;
|
||||
uint32_t _totalduration;
|
||||
};
|
||||
|
||||
#endif //_BOOT_DELAY_H
|
||||
|
61
esp3d/src/modules/host/host_services.cpp
Normal file
61
esp3d/src/modules/host/host_services.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
host_services.cpp - host services functions class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../../include/esp3d_config.h"
|
||||
#include "host_services.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
|
||||
|
||||
HostServices::HostServices()
|
||||
{
|
||||
_started = false;
|
||||
}
|
||||
HostServices::~HostServices()
|
||||
{
|
||||
end();
|
||||
}
|
||||
|
||||
bool HostServices::begin()
|
||||
{
|
||||
bool res = true;
|
||||
end();
|
||||
//Check autostart.g on SPIFFS
|
||||
if (!res) {
|
||||
end();
|
||||
}
|
||||
_started = res;
|
||||
return _started;
|
||||
}
|
||||
void HostServices::end()
|
||||
{
|
||||
if(!_started) {
|
||||
return;
|
||||
}
|
||||
_started = false;
|
||||
|
||||
}
|
||||
|
||||
void HostServices::handle()
|
||||
{
|
||||
if (_started) {
|
||||
}
|
||||
}
|
||||
|
40
esp3d/src/modules/host/host_services.h
Normal file
40
esp3d/src/modules/host/host_services.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
host_services.h - host services functions class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _HOST_SERVICES_H
|
||||
#define _HOST_SERVICES_H
|
||||
|
||||
|
||||
class HostServices
|
||||
{
|
||||
public:
|
||||
HostServices();
|
||||
~HostServices();
|
||||
bool begin();
|
||||
void end();
|
||||
void handle();
|
||||
private:
|
||||
bool _started;
|
||||
};
|
||||
|
||||
#endif //_HOST_SERVICES_H
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
//boundaries
|
||||
|
||||
#define MAX_SERVER_ADDRESS_LENGTH 128
|
||||
#define MIN_SERVER_ADDRESS_LENGTH 0
|
||||
|
||||
#define MAX_HTTP_PORT 65001
|
||||
#define MIN_HTTP_PORT 1
|
||||
|
@ -63,7 +63,9 @@ DNSServer dnsServer;
|
||||
#ifdef TIMESTAMP_FEATURE
|
||||
#include "../time/time_server.h"
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
#include "../notifications/notifications_service.h"
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
|
||||
bool NetServices::_started = false;
|
||||
|
||||
@ -231,6 +233,9 @@ bool NetServices::begin()
|
||||
output.printMSG(stmp.c_str());
|
||||
}
|
||||
#endif //SSDP_FEATURE
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
notificationsservice.begin();
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
if (!res) {
|
||||
end();
|
||||
}
|
||||
@ -243,6 +248,9 @@ void NetServices::end()
|
||||
return;
|
||||
}
|
||||
_started = false;
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
notificationsservice.end();
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
#ifdef CAPTIVE_PORTAL_FEATURE
|
||||
if(WiFi.getMode() == WIFI_AP) {
|
||||
dnsServer.stop();
|
||||
@ -307,6 +315,9 @@ void NetServices::handle()
|
||||
#ifdef TELNET_FEATURE
|
||||
telnet_server.handle();
|
||||
#endif //TELNET_FEATURE
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
notificationsservice.handle();
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
}
|
||||
}
|
||||
|
||||
|
415
esp3d/src/modules/notifications/notifications_service.cpp
Normal file
415
esp3d/src/modules/notifications/notifications_service.cpp
Normal file
@ -0,0 +1,415 @@
|
||||
/*
|
||||
notifications_service.cpp - notifications service functions class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
//Inspired by following sources
|
||||
//* Line :
|
||||
// - https://github.com/TridentTD/TridentTD_LineNotify
|
||||
// - https://notify-bot.line.me/doc/en/
|
||||
//* Pushover:
|
||||
// - https://github.com/ArduinoHannover/Pushover
|
||||
// - https://pushover.net/api
|
||||
//* Email:
|
||||
// - https://github.com/CosmicBoris/ESP8266SMTP
|
||||
// - https://www.electronicshub.org/send-an-email-using-esp8266/
|
||||
|
||||
#include "../../include/esp3d_config.h"
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
#include "notifications_service.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../network/netconfig.h"
|
||||
|
||||
#if defined( ARDUINO_ARCH_ESP8266)
|
||||
#define USING_AXTLS
|
||||
#if defined(USING_AXTLS)
|
||||
#include "WiFiClientSecureAxTLS.h"
|
||||
using namespace axTLS;
|
||||
typedef axTLS::WiFiClientSecure TSecureClient;
|
||||
#else
|
||||
#include <WiFiClientSecure.h>
|
||||
typedef WiFiClientSecure TSecureClient;
|
||||
#endif //USING_AXTLS
|
||||
#endif //ARDUINO_ARCH_ESP8266
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include <WiFiClientSecure.h>
|
||||
typedef WiFiClientSecure TSecureClient;
|
||||
#endif //ARDUINO_ARCH_ESP32
|
||||
|
||||
#include <base64.h>
|
||||
|
||||
#define PUSHOVERTIMEOUT 5000
|
||||
#define PUSHOVERSERVER "api.pushover.net"
|
||||
#define PUSHOVERPORT 443
|
||||
|
||||
#define LINETIMEOUT 5000
|
||||
#define LINESERVER "notify-api.line.me"
|
||||
#define LINEPORT 443
|
||||
|
||||
#define EMAILTIMEOUT 5000
|
||||
|
||||
NotificationsService notificationsservice;
|
||||
|
||||
bool Wait4Answer(TSecureClient & client, const char * linetrigger, const char * expected_answer, uint32_t timeout)
|
||||
{
|
||||
if(client.connected()) {
|
||||
String answer;
|
||||
uint32_t starttimeout = millis();
|
||||
while (client.connected() && ((millis() -starttimeout) < timeout)) {
|
||||
answer = client.readStringUntil('\n');
|
||||
log_esp3d("Answer: %s", answer.c_str());
|
||||
if ((answer.indexOf(linetrigger) != -1) || (strlen(linetrigger) == 0)) {
|
||||
break;
|
||||
}
|
||||
Hal::wait(10);
|
||||
}
|
||||
if (strlen(expected_answer) == 0) {
|
||||
log_esp3d("Answer ignored as requested");
|
||||
return true;
|
||||
}
|
||||
if(answer.indexOf(expected_answer) == -1) {
|
||||
log_esp3d("Did not got answer!");
|
||||
return false;
|
||||
} else {
|
||||
log_esp3d("Got expected answer");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
log_esp3d("Failed to send message");
|
||||
return false;
|
||||
}
|
||||
|
||||
NotificationsService::NotificationsService()
|
||||
{
|
||||
_started = false;
|
||||
_notificationType = 0;
|
||||
_token1 = "";
|
||||
_token1 = "";
|
||||
_settings = "";
|
||||
}
|
||||
NotificationsService::~NotificationsService()
|
||||
{
|
||||
end();
|
||||
}
|
||||
|
||||
bool NotificationsService::started()
|
||||
{
|
||||
return _started;
|
||||
}
|
||||
|
||||
const char * NotificationsService::getTypeString()
|
||||
{
|
||||
switch(_notificationType) {
|
||||
case ESP_PUSHOVER_NOTIFICATION:
|
||||
return "Pushover";
|
||||
case ESP_EMAIL_NOTIFICATION:
|
||||
return "Email";
|
||||
case ESP_LINE_NOTIFICATION:
|
||||
return "Line";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "None";
|
||||
}
|
||||
|
||||
bool NotificationsService::sendMSG(const char * title, const char * message)
|
||||
{
|
||||
if (!((strlen(title) == 0) && (strlen(message) == 0))) {
|
||||
switch(_notificationType) {
|
||||
case ESP_PUSHOVER_NOTIFICATION:
|
||||
return sendPushoverMSG(title,message);
|
||||
break;
|
||||
case ESP_EMAIL_NOTIFICATION:
|
||||
return sendEmailMSG(title,message);
|
||||
break;
|
||||
case ESP_LINE_NOTIFICATION :
|
||||
return sendLineMSG(title,message);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//Messages are currently limited to 1024 4-byte UTF-8 characters
|
||||
//but we do not do any check
|
||||
bool NotificationsService::sendPushoverMSG(const char * title, const char * message)
|
||||
{
|
||||
String data;
|
||||
String postcmd;
|
||||
bool res;
|
||||
TSecureClient Notificationclient;
|
||||
#if defined(ARDUINO_ARCH_ESP8266) && !defined(USING_AXTLS)
|
||||
Notificationclient.setInsecure();
|
||||
#endif //ARDUINO_ARCH_ESP8266 && !USING_AXTLS
|
||||
if (!Notificationclient.connect(_serveraddress.c_str(), _port)) {
|
||||
log_esp3d("Error connecting server %s:%d", _serveraddress.c_str(), _port);
|
||||
return false;
|
||||
}
|
||||
//build data for post
|
||||
data = "user=";
|
||||
data += _token1;
|
||||
data += "&token=";
|
||||
data += _token2;;
|
||||
data +="&title=";
|
||||
data += title;
|
||||
data += "&message=";
|
||||
data += message;
|
||||
data += "&device=";
|
||||
data += NetConfig::hostname();
|
||||
//build post query
|
||||
postcmd = "POST /1/messages.json HTTP/1.1\r\nHost: api.pushover.net\r\nConnection: close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nContent-Length: ";
|
||||
postcmd += data.length();
|
||||
postcmd +="\r\n\r\n";
|
||||
postcmd +=data;
|
||||
log_esp3d("Query: %s", postcmd.c_str());
|
||||
//send query
|
||||
Notificationclient.print(postcmd);
|
||||
res = Wait4Answer(Notificationclient, "{", "\"status\":1", PUSHOVERTIMEOUT);
|
||||
Notificationclient.stop();
|
||||
return res;
|
||||
}
|
||||
bool NotificationsService::sendEmailMSG(const char * title, const char * message)
|
||||
{
|
||||
TSecureClient Notificationclient;
|
||||
#if defined(ARDUINO_ARCH_ESP8266) && !defined(USING_AXTLS)
|
||||
Notificationclient.setInsecure();
|
||||
#endif //ARDUINO_ARCH_ESP8266 && !USING_AXTLS
|
||||
log_esp3d("Connect to server");
|
||||
if (!Notificationclient.connect(_serveraddress.c_str(), _port)) {
|
||||
log_esp3d("Error connecting server %s:%d", _serveraddress.c_str(), _port);
|
||||
return false;
|
||||
}
|
||||
//Check answer of connection
|
||||
if(!Wait4Answer(Notificationclient, "220", "220", EMAILTIMEOUT)) {
|
||||
log_esp3d("Connection failed!");
|
||||
return false;
|
||||
}
|
||||
//Do HELO
|
||||
log_esp3d("HELO");
|
||||
Notificationclient.print("HELO friend\r\n");
|
||||
if(!Wait4Answer(Notificationclient, "250", "250", EMAILTIMEOUT)) {
|
||||
log_esp3d("HELO failed!");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("AUTH LOGIN");
|
||||
//Request AUthentication
|
||||
Notificationclient.print("AUTH LOGIN\r\n");
|
||||
if(!Wait4Answer(Notificationclient, "334", "334", EMAILTIMEOUT)) {
|
||||
log_esp3d("AUTH LOGIN failed!");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("Send LOGIN");
|
||||
//sent Login
|
||||
Notificationclient.printf("%s\r\n",_token1.c_str());
|
||||
if(!Wait4Answer(Notificationclient, "334", "334", EMAILTIMEOUT)) {
|
||||
log_esp3d("Sent login failed!");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("Send PASSWORD");
|
||||
//Send password
|
||||
Notificationclient.printf("%s\r\n",_token2.c_str());
|
||||
if(!Wait4Answer(Notificationclient, "235", "235", EMAILTIMEOUT)) {
|
||||
log_esp3d("Sent password failed!");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("MAIL FROM");
|
||||
//Send From
|
||||
Notificationclient.printf("MAIL FROM: <%s>\r\n",_settings.c_str());
|
||||
if(!Wait4Answer(Notificationclient, "250", "250", EMAILTIMEOUT)) {
|
||||
log_esp3d("MAIL FROM failed!");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("RCPT TO");
|
||||
//Send To
|
||||
Notificationclient.printf("RCPT TO: <%s>\r\n",_settings.c_str());
|
||||
if(!Wait4Answer(Notificationclient, "250", "250", EMAILTIMEOUT)) {
|
||||
log_esp3d("RCPT TO failed!");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("DATA");
|
||||
//Send Data
|
||||
Notificationclient.print("DATA\r\n");
|
||||
if(!Wait4Answer(Notificationclient, "354", "354", EMAILTIMEOUT)) {
|
||||
log_esp3d("Preparing DATA failed!");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("Send message");
|
||||
//Send message
|
||||
Notificationclient.printf("From:ESP3D<%s>\r\n",_settings.c_str());
|
||||
Notificationclient.printf("To: <%s>\r\n",_settings.c_str());
|
||||
Notificationclient.printf("Subject: %s\r\n\r\n",title);
|
||||
Notificationclient.println(message);
|
||||
|
||||
log_esp3d("Send final dot");
|
||||
//Send Final dot
|
||||
Notificationclient.print(".\r\n");
|
||||
if(!Wait4Answer(Notificationclient, "250", "250", EMAILTIMEOUT)) {
|
||||
log_esp3d("Sending final dot failed!");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("QUIT");
|
||||
//Quit
|
||||
Notificationclient.print("QUIT\r\n");
|
||||
if(!Wait4Answer(Notificationclient, "221", "221", EMAILTIMEOUT)) {
|
||||
log_esp3d("QUIT failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
Notificationclient.stop();
|
||||
return true;
|
||||
}
|
||||
bool NotificationsService::sendLineMSG(const char * title, const char * message)
|
||||
{
|
||||
String data;
|
||||
String postcmd;
|
||||
bool res;
|
||||
TSecureClient Notificationclient;
|
||||
#if defined(ARDUINO_ARCH_ESP8266) && !defined(USING_AXTLS)
|
||||
Notificationclient.setInsecure();
|
||||
#endif //ARDUINO_ARCH_ESP8266 && !USING_AXTLS
|
||||
(void)title;
|
||||
if (!Notificationclient.connect(_serveraddress.c_str(), _port)) {
|
||||
log_esp3d("Error connecting server %s:%d", _serveraddress.c_str(), _port);
|
||||
return false;
|
||||
}
|
||||
//build data for post
|
||||
data = "message=";
|
||||
data += message;
|
||||
//build post query
|
||||
postcmd = "POST /api/notify HTTP/1.1\r\nHost: notify-api.line.me\r\nConnection: close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nContent-Type: application/x-www-form-urlencoded\r\n";
|
||||
postcmd +="Authorization: Bearer ";
|
||||
postcmd += _token1 + "\r\n";
|
||||
postcmd += "Content-Length: ";
|
||||
postcmd += data.length();
|
||||
postcmd +="\r\n\r\n";
|
||||
postcmd +=data;
|
||||
log_esp3d("Query: %s", postcmd.c_str());
|
||||
//send query
|
||||
Notificationclient.print(postcmd);
|
||||
res = Wait4Answer(Notificationclient, "{", "\"status\":200", LINETIMEOUT);
|
||||
Notificationclient.stop();
|
||||
return res;
|
||||
}
|
||||
//Email#serveraddress:port
|
||||
bool NotificationsService::getPortFromSettings()
|
||||
{
|
||||
String tmp = Settings_ESP3D::read_string(ESP_NOTIFICATION_SETTINGS);
|
||||
int pos = tmp.lastIndexOf(':');
|
||||
if (pos == -1) {
|
||||
return false;
|
||||
}
|
||||
_port= tmp.substring(pos+1).toInt();
|
||||
log_esp3d("port : %d", _port);
|
||||
if (_port > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//Email#serveraddress:port
|
||||
bool NotificationsService::getServerAddressFromSettings()
|
||||
{
|
||||
String tmp = Settings_ESP3D::read_string(ESP_NOTIFICATION_SETTINGS);
|
||||
int pos1 = tmp.indexOf('#');
|
||||
int pos2 = tmp.lastIndexOf(':');
|
||||
if ((pos1 == -1) || (pos2 == -1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO add a check for valid email ?
|
||||
_serveraddress = tmp.substring(pos1+1, pos2);
|
||||
log_esp3d("server : %s", _serveraddress.c_str());
|
||||
return true;
|
||||
}
|
||||
//Email#serveraddress:port
|
||||
bool NotificationsService::getEmailFromSettings()
|
||||
{
|
||||
String tmp = Settings_ESP3D::read_string(ESP_NOTIFICATION_SETTINGS);
|
||||
int pos = tmp.indexOf('#');
|
||||
if (pos == -1) {
|
||||
return false;
|
||||
}
|
||||
_settings = tmp.substring(0, pos);
|
||||
log_esp3d("email : %s", _settings.c_str());
|
||||
//TODO add a check for valid email ?
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool NotificationsService::begin()
|
||||
{
|
||||
bool res = true;
|
||||
end();
|
||||
_notificationType = Settings_ESP3D::read_byte(ESP_NOTIFICATION_TYPE);
|
||||
switch(_notificationType) {
|
||||
case 0: //no notification = no error but no start
|
||||
return true;
|
||||
case ESP_PUSHOVER_NOTIFICATION:
|
||||
_token1 = Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN1);
|
||||
_token2 = Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN2);
|
||||
_port = PUSHOVERPORT;
|
||||
_serveraddress = PUSHOVERSERVER;
|
||||
break;
|
||||
case ESP_LINE_NOTIFICATION:
|
||||
_token1 = Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN1);
|
||||
_port = LINEPORT;
|
||||
_serveraddress = LINESERVER;
|
||||
break;
|
||||
case ESP_EMAIL_NOTIFICATION:
|
||||
_token1 = base64::encode(Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN1));
|
||||
_token2 = base64::encode(Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN2));
|
||||
//log_esp3d("%s",Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN1));
|
||||
//log_esp3d("%s",Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN2));
|
||||
if(!getEmailFromSettings() || !getPortFromSettings()|| !getServerAddressFromSettings()) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!res) {
|
||||
end();
|
||||
}
|
||||
_started = res;
|
||||
return _started;
|
||||
}
|
||||
void NotificationsService::end()
|
||||
{
|
||||
if(!_started) {
|
||||
return;
|
||||
}
|
||||
_started = false;
|
||||
_notificationType = 0;
|
||||
_token1 = "";
|
||||
_token1 = "";
|
||||
_settings = "";
|
||||
_serveraddress = "";
|
||||
_port = 0;
|
||||
}
|
||||
|
||||
void NotificationsService::handle()
|
||||
{
|
||||
if (_started) {
|
||||
}
|
||||
}
|
||||
|
||||
#endif //NOTIFICATION_FEATURE
|
57
esp3d/src/modules/notifications/notifications_service.h
Normal file
57
esp3d/src/modules/notifications/notifications_service.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
notifications_service.h - notifications service functions class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _NOTIFICATIONS_SERVICE_H
|
||||
#define _NOTIFICATIONS_SERVICE_H
|
||||
|
||||
|
||||
class NotificationsService
|
||||
{
|
||||
public:
|
||||
NotificationsService();
|
||||
~NotificationsService();
|
||||
bool begin();
|
||||
void end();
|
||||
void handle();
|
||||
bool sendMSG(const char * title, const char * message);
|
||||
const char * getTypeString();
|
||||
bool started();
|
||||
private:
|
||||
bool _started;
|
||||
uint8_t _notificationType;
|
||||
String _token1;
|
||||
String _token2;
|
||||
String _settings;
|
||||
String _serveraddress;
|
||||
uint16_t _port;
|
||||
bool sendPushoverMSG(const char * title, const char * message);
|
||||
bool sendEmailMSG(const char * title, const char * message);
|
||||
bool sendLineMSG(const char * title, const char * message);
|
||||
bool getPortFromSettings();
|
||||
bool getServerAddressFromSettings();
|
||||
bool getEmailFromSettings();
|
||||
};
|
||||
|
||||
extern NotificationsService notificationsservice;
|
||||
|
||||
#endif //_NOTIFICATIONS_SERVICE_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user