ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
ESP610.cpp
Go to the documentation of this file.
1 /*
2  ESP610.cpp - ESP3D command class
3 
4  Copyright (c) 2014 Luc Lebosse. All rights reserved.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 #include "../../include/esp3d_config.h"
21 #if defined (NOTIFICATION_FEATURE)
22 #include "../commands.h"
23 #include "../esp3doutput.h"
24 #include "../settings_esp3d.h"
25 #include "../../modules/authentication/authentication_service.h"
26 #include "../../modules/notifications/notifications_service.h"
27 //Set/Get Notification settings
28 //[ESP610]type=<NONE/PUSHOVER/EMAIL/LINE> T1=<token1> T2=<token2> TS=<Settings> [pwd=<admin password>]
29 //Get will give type and settings only not the protected T1/T2
30 bool Commands::ESP610(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
31 {
32  bool response = true;
33  String parameter;
34 #ifdef AUTHENTICATION_FEATURE
35  if (auth_type == LEVEL_GUEST) {
36  output->printERROR("Wrong authentication!", 401);
37  return false;
38  }
39 #else
40  (void)auth_type;
41 #endif //AUTHENTICATION_FEATURE
42  parameter = get_param (cmd_params, "");
43  //get
44  if (parameter.length() == 0) {
46  static String tmp;
47  tmp = (Ntype == ESP_PUSHOVER_NOTIFICATION)?"PUSHOVER":(Ntype == ESP_EMAIL_NOTIFICATION)?"EMAIL":(Ntype == ESP_LINE_NOTIFICATION)?"LINE":"NONE";
48  tmp+= " ";
50  output->printMSG (tmp.c_str());
51  } else {
52  response = false;
53  //type
54  parameter = get_param (cmd_params, "type=");
55  if (parameter.length() > 0) {
56  uint8_t Ntype;
57  parameter.toUpperCase();
58  if (parameter == "NONE") {
59  Ntype = 0;
60  } else if (parameter == "PUSHOVER") {
62  } else if (parameter == "EMAIL") {
63  Ntype = ESP_EMAIL_NOTIFICATION;
64  } else if (parameter == "LINE") {
65  Ntype = ESP_LINE_NOTIFICATION;
66  } else {
67  output->printERROR("Only NONE, PUSHOVER, EMAIL, LINE are supported!");
68  return false;
69  }
71  output->printERROR ("Set failed!");
72  return false;
73  } else {
74  response = true;
75  }
76  }
77  //Settings
78  parameter = get_param (cmd_params, "TS=");
79  if (parameter.length() > 0) {
81  output->printERROR ("Set failed!");
82  return false;
83  } else {
84  response = true;
85  }
86  }
87  //Token1
88  parameter = get_param (cmd_params, "T1=");
89  if (parameter.length() > 0) {
90  if(!Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN1, parameter.c_str())) {
91  output->printERROR ("Set failed!");
92  return false;
93  } else {
94  response = true;
95  }
96  }
97  //Token2
98  parameter = get_param (cmd_params, "T2=");
99  if (parameter.length() > 0) {
100  if(!Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN2, parameter.c_str())) {
101  output->printERROR ("Set failed!");
102  return false;
103  } else {
104  response = true;
105  }
106  }
107  if (response) {
108  //Restart service
110  output->printMSG ("ok");
111  } else {
112  output->printERROR ("Invalid parameter! Only type, T1, T2 and TS are supported");
113  }
114  }
115  return response;
116 }
117 
118 #endif //NOTIFICATION_FEATURE
Settings_ESP3D::write_byte
static bool write_byte(int pos, const uint8_t value)
Definition: settings_esp3d.cpp:749
ESP_EMAIL_NOTIFICATION
#define ESP_EMAIL_NOTIFICATION
Definition: defines.h:86
Commands::get_param
const char * get_param(const char *cmd_params, const char *label)
Definition: commands.cpp:162
Settings_ESP3D::read_string
static const char * read_string(int pos, bool *haserror=NULL)
Definition: settings_esp3d.cpp:794
ESP_LINE_NOTIFICATION
#define ESP_LINE_NOTIFICATION
Definition: defines.h:87
NotificationsService::begin
bool begin()
Definition: notifications_service.cpp:389
notificationsservice
NotificationsService notificationsservice
Definition: notifications_service.cpp:67
ESP_NOTIFICATION_TYPE
#define ESP_NOTIFICATION_TYPE
Definition: settings_esp3d.h:47
Commands::ESP610
bool ESP610(const char *cmd_params, level_authenticate_type auth_level, ESP3DOutput *output)
Definition: ESP610.cpp:30
ESP_NOTIFICATION_TOKEN1
#define ESP_NOTIFICATION_TOKEN1
Definition: settings_esp3d.h:69
LEVEL_GUEST
@ LEVEL_GUEST
Definition: authentication_service.h:26
ESP_NOTIFICATION_SETTINGS
#define ESP_NOTIFICATION_SETTINGS
Definition: settings_esp3d.h:83
level_authenticate_type
level_authenticate_type
Definition: authentication_service.h:25
ESP3DOutput::printMSG
size_t printMSG(const char *s, bool withNL=true)
Definition: esp3doutput.cpp:190
ESP3DOutput::printERROR
size_t printERROR(const char *s, int code_error=200)
Definition: esp3doutput.cpp:247
Settings_ESP3D::write_string
static bool write_string(int pos, const char *byte_buffer)
Definition: settings_esp3d.cpp:870
ESP_PUSHOVER_NOTIFICATION
#define ESP_PUSHOVER_NOTIFICATION
Definition: defines.h:85
Settings_ESP3D::read_byte
static uint8_t read_byte(int pos, bool *haserror=NULL)
Definition: settings_esp3d.cpp:715
ESP_NOTIFICATION_TOKEN2
#define ESP_NOTIFICATION_TOKEN2
Definition: settings_esp3d.h:70
ESP3DOutput
Definition: esp3doutput.h:48