Add [ESP620] to send http get URL

This commit is contained in:
Luc 2020-12-14 16:13:44 +01:00
parent 9b1ec9452d
commit dac3e0b716
9 changed files with 108 additions and 4 deletions

View File

@ -528,6 +528,11 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
case 610: case 610:
response = ESP610(cmd_params, auth_type, output); response = ESP610(cmd_params, auth_type, output);
break; break;
//Send Notification using URL
//[ESP620]URL=<encoded url> [pwd=<admin password>]
case 620:
response = ESP620(cmd_params, auth_type, output);
break;
#endif //NOTIFICATION_FEATURE #endif //NOTIFICATION_FEATURE
#if defined(FILESYSTEM_FEATURE) #if defined(FILESYSTEM_FEATURE)
//Format ESP Filesystem //Format ESP Filesystem

View File

@ -121,6 +121,7 @@ public:
#if defined(NOTIFICATION_FEATURE) #if defined(NOTIFICATION_FEATURE)
bool ESP600(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP600(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
bool ESP610(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP610(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
bool ESP620(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
#endif //NOTIFICATION_FEATURE #endif //NOTIFICATION_FEATURE
#if defined(FILESYSTEM_FEATURE) && defined(ESP_GCODE_HOST_FEATURE) #if defined(FILESYSTEM_FEATURE) && defined(ESP_GCODE_HOST_FEATURE)
bool ESP700(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP700(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);

View File

@ -112,6 +112,7 @@ const char * help[]= {"[ESP] - display this help",
#if defined(NOTIFICATION_FEATURE) #if defined(NOTIFICATION_FEATURE)
"[ESP600](message) - send notification", "[ESP600](message) - send notification",
"[ESP610]type=(NONE/PUSHOVER/EMAIL/LINE) (T1=xxx) (T2=xxx) (TS=xxx) - display/set Notification settings", "[ESP610]type=(NONE/PUSHOVER/EMAIL/LINE) (T1=xxx) (T2=xxx) (TS=xxx) - display/set Notification settings",
"[ESP620]URL=http://XXXXXX - send GET notification",
#endif //NOTIFICATION_FEATURE #endif //NOTIFICATION_FEATURE
#if defined(FILESYSTEM_FEATURE) && defined(ESP_GCODE_HOST_FEATURE) #if defined(FILESYSTEM_FEATURE) && defined(ESP_GCODE_HOST_FEATURE)
"[ESP700](filename) - read ESP Filesystem file", "[ESP700](filename) - read ESP Filesystem file",

View File

@ -25,7 +25,7 @@
#include "../../modules/authentication/authentication_service.h" #include "../../modules/authentication/authentication_service.h"
#include "../../modules/notifications/notifications_service.h" #include "../../modules/notifications/notifications_service.h"
//Send Notification //Send Notification
//[ESP600]msg [pwd=<admin password>] //[ESP600]msg [pwd=<admin/user password>]
bool Commands::ESP600(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output) bool Commands::ESP600(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{ {
bool response = true; bool response = true;

View File

@ -0,0 +1,58 @@
/*
ESP620.cpp - ESP3D command class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
This code 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 code 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 code; 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"
//Send Notification using URL
//[ESP620]URL=<encoded url> [pwd=<admin/user password>]
bool Commands::ESP620(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->printERROR ("Invalid message!");
return false;
} else {
parameter = get_param (cmd_params, "URL=");
if (notificationsservice.GET(parameter.c_str())) {
output->printMSG ("ok");
} else {
output->printERROR ("Cannot send notification!");
return false;
}
}
return response;
}
#endif //NOTIFICATION_FEATURE

View File

@ -22,7 +22,7 @@
#define _VERSION_ESP3D_H #define _VERSION_ESP3D_H
//version and sources location //version and sources location
#define FW_VERSION "3.0.0.a75" #define FW_VERSION "3.0.0.a76"
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0" #define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
#endif //_VERSION_ESP3D_H #endif //_VERSION_ESP3D_H

View File

@ -46,11 +46,16 @@ typedef axTLS::WiFiClientSecure TSecureClient;
#include <WiFiClientSecure.h> #include <WiFiClientSecure.h>
typedef WiFiClientSecure TSecureClient; typedef WiFiClientSecure TSecureClient;
#endif //USING_AXTLS #endif //USING_AXTLS
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <libb64/cdecode.h>
#endif //ARDUINO_ARCH_ESP8266 #endif //ARDUINO_ARCH_ESP8266
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
#include <WiFiClientSecure.h> #include <WiFiClientSecure.h>
typedef WiFiClientSecure TSecureClient; typedef WiFiClientSecure TSecureClient;
#include <WiFi.h>
#include <HTTPClient.h>
#endif //ARDUINO_ARCH_ESP32 #endif //ARDUINO_ARCH_ESP32
#include <base64.h> #include <base64.h>
@ -464,6 +469,40 @@ bool NotificationsService::getEmailFromSettings()
return true; return true;
} }
bool NotificationsService::decode64(const char* encodedURL, char *decodedURL)
{
size_t out_len = 0;
#if defined( ARDUINO_ARCH_ESP8266)
out_len = base64_decode_chars(encodedURL, strlen(encodedURL), decodedURL);
#endif //ARDUINO_ARCH_ESP8266
#if defined( ARDUINO_ARCH_ESP32)
strcpy(base64_decode(encodedURL, strlen(encodedURL),&out_len);
#endif //ARDUINO_ARCH_ESP32
log_esp3d("URLE: %s", encodedURL);
log_esp3d("URLD: %s", decodedURL);
return (out_len>0);
}
bool NotificationsService::GET(const char * URL64)
{
//TODO do we need https client ?
WiFiClient client;
HTTPClient http; //must be declared after WiFiClient for correct destruction order, because used by http.begin(client,...)
char * decodedurl[255];
bool res = false;
if (decode64(URL64, (char*)decodedurl)) {
http.begin(client, (const char*)decodedurl);
int httpCode = http.GET();
log_esp3d("HTTP code: %d", httpCode);
if (httpCode > 0) {
if(httpCode == HTTP_CODE_OK) {
res = true;
}
}
http.end();
}
return res;
}
bool NotificationsService::begin() bool NotificationsService::begin()
{ {

View File

@ -33,6 +33,7 @@ public:
void end(); void end();
void handle(); void handle();
bool sendMSG(const char * title, const char * message); bool sendMSG(const char * title, const char * message);
bool GET(const char * URL64);
const char * getTypeString(); const char * getTypeString();
bool started(); bool started();
bool isAutonotification() bool isAutonotification()
@ -53,6 +54,7 @@ private:
String _settings; String _settings;
String _serveraddress; String _serveraddress;
uint16_t _port; uint16_t _port;
bool decode64(const char* encodedURL, char *decodedURL);
bool sendPushoverMSG(const char * title, const char * message); bool sendPushoverMSG(const char * title, const char * message);
bool sendEmailMSG(const char * title, const char * message); bool sendEmailMSG(const char * title, const char * message);
bool sendLineMSG(const char * title, const char * message); bool sendLineMSG(const char * title, const char * message);

View File

@ -232,11 +232,9 @@ bool processingFileFunction (const char * section, const char * key, const char
uint32_t v = 0; uint32_t v = 0;
byte b = 0; byte b = 0;
bool done=false; bool done=false;
uint8_t size = 0;
log_esp3d("[%s]%s=%s",section, key,value); log_esp3d("[%s]%s=%s",section, key,value);
//network / services / system sections //network / services / system sections
if (strcasecmp("network",section)==0) { if (strcasecmp("network",section)==0) {
size = sizeof(NetstringKeysVal)/sizeof(char*);
if (!done) { if (!done) {
done = processString(NetstringKeysVal,NetstringKeysPos,sizeof(NetstringKeysVal)/sizeof(char*), key, value, T, P ); done = processString(NetstringKeysVal,NetstringKeysPos,sizeof(NetstringKeysVal)/sizeof(char*), key, value, T, P );
} }