ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
ESP210.cpp
Go to the documentation of this file.
1 /*
2  ESP210.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 (DHT_DEVICE)
22 #include "../commands.h"
23 #include "../esp3doutput.h"
24 #include "../settings_esp3d.h"
25 #include "../../modules/dht/dht.h"
26 #include "../../modules/authentication/authentication_service.h"
27 //Get DHT Value / type/Set DHT type
28 //[ESP210]<type=NONE/11/22/xxx> <interval=XXX in millisec>
29 bool Commands::ESP210(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
30 {
31  bool response = true;
32  String parameter;
33 #ifdef AUTHENTICATION_FEATURE
34  if (auth_type == LEVEL_GUEST) {
35  output->printERROR("Wrong authentication!", 401);
36  return false;
37  }
38 #else
39  (void)auth_type;
40 #endif //AUTHENTICATION_FEATURE
41  parameter = get_param (cmd_params, "");
42  if (parameter.length() == 0) {
43  String s;
44  if(esp3d_DHT.started()) {
45  s = String(esp3d_DHT.getHumidity(),1);
46  if (s !="nan") {
47  s+="% ";
48  s+= String(esp3d_DHT.getTemperature(),1);
49  } else {
50  s ="Disconnected ";
51  }
52  s+= esp3d_DHT.isCelsiusUnit()?"C ":"F ";
54  s+= " ";
55  s+= esp3d_DHT.interval();
56  s+= "ms";
57 
58  } else {
59  s = "NONE";
60  }
61  output->printMSG(s.c_str());
62  } else {
63 #ifdef AUTHENTICATION_FEATURE
64  if (auth_type != LEVEL_ADMIN) {
65  output->printERROR("Wrong authentication!", 401);
66  return false;
67  }
68 #endif //AUTHENTICATION_FEATURE
69  parameter = get_param (cmd_params, "type=");
70  if (parameter.length() != 0) {
71  parameter.toUpperCase();
72  int8_t v = -1;
73  if (parameter == "NONE") {
74  v = 0;
75  } else if(parameter == "11") {
76  v = DHT11_DEVICE;
77  } else if (parameter == "22") {
78  v = DHT22_DEVICE;
79  } else {
80  output->printERROR ("Invalid parameter!");
81  return false;
82  }
83  if (v!=-1) {
85  output->printERROR ("Set failed!");
86  return false;
87  }
88  if (!esp3d_DHT.begin()) {
89  output->printERROR ("Set failed!");
90  return false;
91  }
92  }
93  }
94  parameter = get_param (cmd_params, "interval=");
95  if (parameter.length() != 0) {
96  if (!Settings_ESP3D::write_uint32(ESP_DHT_INTERVAL,parameter.toInt())) {
97  output->printERROR ("Set failed!");
98  return false;
99  }
100  esp3d_DHT.setInterval(parameter.toInt());
101  }
102  output->printMSG ("ok");
103  }
104  return response;
105 }
106 
107 #endif //DHT_DEVICE
Settings_ESP3D::write_byte
static bool write_byte(int pos, const uint8_t value)
Definition: settings_esp3d.cpp:749
ESP_DHT_INTERVAL
#define ESP_DHT_INTERVAL
Definition: settings_esp3d.h:56
DHT::setInterval
bool setInterval(uint interval)
Commands::get_param
const char * get_param(const char *cmd_params, const char *label)
Definition: commands.cpp:162
ESP_DHT_TYPE
#define ESP_DHT_TYPE
Definition: settings_esp3d.h:71
DHT::interval
uint interval()
DHT22_DEVICE
#define DHT22_DEVICE
Definition: defines.h:92
DHT::started
bool started()
esp3d_DHT
DHT esp3d_DHT
Settings_ESP3D::write_uint32
static bool write_uint32(int pos, const uint32_t value)
Definition: settings_esp3d.cpp:970
DHT::GetModelString
const char * GetModelString()
LEVEL_GUEST
@ LEVEL_GUEST
Definition: authentication_service.h:26
DHT::begin
bool begin()
DHT::getHumidity
float getHumidity()
DHT11_DEVICE
#define DHT11_DEVICE
Definition: defines.h:91
level_authenticate_type
level_authenticate_type
Definition: authentication_service.h:25
DHT::getTemperature
float getTemperature()
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
LEVEL_ADMIN
@ LEVEL_ADMIN
Definition: authentication_service.h:28
DHT::isCelsiusUnit
bool isCelsiusUnit()
ESP3DOutput
Definition: esp3doutput.h:48