mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-13 17:49:00 +08:00
Set DHT as sensor and set output more generic
Add Analog entry as sensor Fix DHT initialisation issue
This commit is contained in:
parent
03c9e3868c
commit
2a4dffcea5
@ -112,7 +112,7 @@ but do not give any passwords
|
||||
*Set EEPROM setting
|
||||
position in EEPROM, type: B(byte), I(integer/long), S(string), A(IP address / mask)
|
||||
[ESP401]P=<position> T=<type> V=<value> pwd=<user/admin password>
|
||||
Description: Positions:
|
||||
Description: Positions:
|
||||
ESP_RADIO_MODE 0 //1 byte = flag
|
||||
ESP_STA_SSID 1 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese
|
||||
ESP_STA_PASSWORD 34 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese
|
||||
@ -130,7 +130,7 @@ ESP_HTTP_PORT 121 //4 bytes = int
|
||||
ESP_TELNET_PORT 125 //4 bytes = int
|
||||
ESP_OUTPUT_FLAG 129 //1 bytes = flag
|
||||
ESP_HOSTNAME 130 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese
|
||||
ESP_DHT_INTERVAL 164 //4 bytes = int
|
||||
ESP_SENSOR_INTERVAL 164 //4 bytes = int
|
||||
ESP_SETTINGS_VERSION 168 //8 bytes = 7+1 = string ESP3D + 2 digits
|
||||
ESP_ADMIN_PWD 176 //21 bytes 20+1 = string ; warning does not support multibyte char like chinese
|
||||
ESP_USER_PWD 197 //21 bytes 20+1 = string ; warning does not support multibyte char like chinese
|
||||
@ -145,7 +145,7 @@ ESP_WEBSOCKET_ON 330 //1 byte = flag
|
||||
ESP_SD_SPEED_DIV 331 //1 byte = flag
|
||||
ESP_NOTIFICATION_TOKEN1 332 //64 bytes 63+1 = string ; warning does not support multibyte char like chinese
|
||||
ESP_NOTIFICATION_TOKEN2 396 //64 bytes 63+1 = string ; warning does not support multibyte char like chinese
|
||||
ESP_DHT_TYPE 460//1 bytes = flag
|
||||
ESP_SENSOR_TYPE 460//1 bytes = flag
|
||||
ESP_TARGET_FW 461 //1 bytes = flag
|
||||
ESP_TIMEZONE 462//1 bytes = flag
|
||||
ESP_TIME_IS_DST 463//1 bytes = flag
|
||||
|
@ -95,19 +95,28 @@
|
||||
//ROTARY_ENCODER 1
|
||||
//#define INPUT_DEVICE ROTARY_ENCODER
|
||||
|
||||
//DHT_DEVICE: send update of temperature / humidity based on DHT 11/22
|
||||
//#define DHT_DEVICE
|
||||
//SENSOR_DEVICE: send info based on defined sensor
|
||||
//DHT11_DEVICE 1
|
||||
//DHT22_DEVICE 2
|
||||
//ANALOG_DEVICE 3
|
||||
//BMP280_DEVICE 4
|
||||
//BME280_DEVICE 5
|
||||
#define SENSOR_DEVICE DHT22_DEVICE
|
||||
|
||||
#ifdef BUZZER_DEVICE
|
||||
#define ESP3D_BUZZER_PIN 15
|
||||
#endif //BUZZER_DEVICE
|
||||
|
||||
#ifdef DHT_DEVICE
|
||||
#define ESP3D_DHT_PIN 22
|
||||
//USE_CELSIUS
|
||||
//USE_FAHRENHEIT
|
||||
#define DHT_UNIT USE_CELSIUS
|
||||
#endif //DHT_DEVICE
|
||||
#ifdef SENSOR_DEVICE
|
||||
//pin
|
||||
#define ESP3D_SENSOR_PIN 22
|
||||
//Conversion coefficient
|
||||
#define SENSOR_CONVERTER(v) v*0.588
|
||||
//Unit to use, if not applicaple for sensor will use default one
|
||||
//it is used also for the output format
|
||||
//C for Celsius / F for Fahrenheit / V for volt
|
||||
#define SENSOR__UNIT "C"
|
||||
#endif //SENSOR_DEVICE
|
||||
|
||||
//PIN_RESET_FEATURE : allow to reset settings by setting low a pin
|
||||
//#define PIN_RESET_FEATURE
|
||||
|
@ -427,13 +427,13 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
|
||||
response = ESP201(cmd_params, auth_type, output);
|
||||
break;
|
||||
#endif //DIRECT_PIN_FEATURE
|
||||
#ifdef DHT_DEVICE
|
||||
//Get DHT Value / type/Set DHT type
|
||||
//[ESP210] <TYPE> <type=NONE/11/22/xxx> <interval=XXX in millisec>
|
||||
#ifdef SENSOR_DEVICE
|
||||
//Get SENSOR Value / type/Set SENSOR type
|
||||
//[ESP210] <TYPE> <type=NONE/xxx> <interval=XXX in millisec>
|
||||
case 210:
|
||||
response = ESP210(cmd_params, auth_type, output);
|
||||
break;
|
||||
#endif //#ifdef DHT_DEVICE
|
||||
#endif //#ifdef SENSOR_DEVICE
|
||||
#if defined (DISPLAY_DEVICE)
|
||||
//Output to esp screen status
|
||||
//[ESP214]<Text>pwd=<user password>
|
||||
|
@ -101,9 +101,9 @@ public:
|
||||
bool ESP216(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#endif //DISPLAY_TOUCH_DRIVER
|
||||
#endif //DISPLAY_DEVICE
|
||||
#ifdef DHT_DEVICE
|
||||
#ifdef SENSOR_DEVICE
|
||||
bool ESP210(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#endif //DHT_DEVICE
|
||||
#endif //SENSOR_DEVICE
|
||||
bool ESP290(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
bool ESP400(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
bool ESP401(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
|
@ -229,7 +229,7 @@ size_t ESP3DOutput::printMSG(const char * s, bool withNL)
|
||||
}
|
||||
#endif //HTTP_FEATURE
|
||||
if (_client & ESP_PRINTER_LCD_CLIENT) {
|
||||
if (isOutput(ESP_PRINTER_LCD_CLIENT)) {
|
||||
if (isOutput(ESP_PRINTER_LCD_CLIENT) && (Settings_ESP3D::GetFirmwareTarget()!=GRBL)) {
|
||||
display= "M117 ";
|
||||
display+= s;
|
||||
return printLN(display.c_str());
|
||||
|
@ -78,9 +78,9 @@ const char * help[]= {"[ESP] - display this help",
|
||||
#ifdef DIRECT_PIN_FEATURE
|
||||
"[ESP201](Pxxx) (Vxxx) (PULLUP=YES RAW=YES ANALOG=NO ANALOG_RANGE=255 CLEARCHANNELS=NO) - read / set pin value",
|
||||
#endif //DIRECT_PIN_FEATURE
|
||||
#ifdef DHT_DEVICE
|
||||
"[ESP210](type=NONE/11/22) (interval=xxxx) - display and read/set DHT info",
|
||||
#endif //DHT_DEVICE
|
||||
#ifdef SENSOR_DEVICE
|
||||
"[ESP210](type=NONE/xxx) (interval=xxxx) - display and read/set SENSOR info",
|
||||
#endif //SENSOR_DEVICE
|
||||
#if defined (DISPLAY_DEVICE)
|
||||
"[ESP214](text) - display (text) to ESP screen status",
|
||||
#if defined(DISPLAY_TOUCH_DRIVER)
|
||||
@ -193,9 +193,9 @@ const uint cmdlist[]= {0,
|
||||
#ifdef DIRECT_PIN_FEATURE
|
||||
201,
|
||||
#endif //DIRECT_PIN_FEATURE
|
||||
#ifdef DHT_DEVICE
|
||||
#ifdef SENSOR_DEVICE
|
||||
210,
|
||||
#endif //DHT_DEVICE
|
||||
#endif //SENSOR_DEVICE
|
||||
#if defined (DISPLAY_DEVICE)
|
||||
214,
|
||||
#if defined(DISPLAY_TOUCH_DRIVER)
|
||||
|
@ -18,14 +18,14 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "../../include/esp3d_config.h"
|
||||
#if defined (DHT_DEVICE)
|
||||
#if defined (SENSOR_DEVICE)
|
||||
#include "../commands.h"
|
||||
#include "../esp3doutput.h"
|
||||
#include "../settings_esp3d.h"
|
||||
#include "../../modules/dht/dht.h"
|
||||
#include "../../modules/sensor/sensor.h"
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
//Get DHT Value / type/Set DHT type
|
||||
//[ESP210]<type=NONE/11/22/xxx> <interval=XXX in millisec>
|
||||
//Get Sensor Value / type/Set Sensor type
|
||||
//[ESP210]<type=NONE/xxx> <interval=XXX in millisec>
|
||||
bool Commands::ESP210(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||
{
|
||||
bool response = true;
|
||||
@ -41,19 +41,13 @@ bool Commands::ESP210(const char* cmd_params, level_authenticate_type auth_type,
|
||||
parameter = get_param (cmd_params, "");
|
||||
if (parameter.length() == 0) {
|
||||
String s;
|
||||
if(esp3d_DHT.started()) {
|
||||
s = String(esp3d_DHT.getHumidity(),1);
|
||||
if (s !="nan") {
|
||||
s+="% ";
|
||||
s+= String(esp3d_DHT.getTemperature(),1);
|
||||
} else {
|
||||
s ="Disconnected ";
|
||||
}
|
||||
s+= esp3d_DHT.isCelsiusUnit()?"C ":"F ";
|
||||
s += esp3d_DHT.GetModelString();
|
||||
s+= " ";
|
||||
s+= esp3d_DHT.interval();
|
||||
s+= "ms";
|
||||
if(esp3d_sensor.started()) {
|
||||
s = esp3d_sensor.GetData();
|
||||
s += " ";
|
||||
s += esp3d_sensor.GetModelString();
|
||||
s += " ";
|
||||
s += esp3d_sensor.interval();
|
||||
s += "ms";
|
||||
|
||||
} else {
|
||||
s = "NONE";
|
||||
@ -72,20 +66,18 @@ bool Commands::ESP210(const char* cmd_params, level_authenticate_type auth_type,
|
||||
int8_t v = -1;
|
||||
if (parameter == "NONE") {
|
||||
v = 0;
|
||||
} else if(parameter == "11") {
|
||||
v = DHT11_DEVICE;
|
||||
} else if (parameter == "22") {
|
||||
v = DHT22_DEVICE;
|
||||
} else {
|
||||
} else if(esp3d_sensor.isModelValid(esp3d_sensor.getIDFromString(parameter.c_str()))) {
|
||||
v = esp3d_sensor.getIDFromString(parameter.c_str());
|
||||
} else {
|
||||
output->printERROR ("Invalid parameter!");
|
||||
return false;
|
||||
}
|
||||
if (v!=-1) {
|
||||
if (!Settings_ESP3D::write_byte(ESP_DHT_TYPE,v)) {
|
||||
if (!Settings_ESP3D::write_byte(ESP_SENSOR_TYPE,v)) {
|
||||
output->printERROR ("Set failed!");
|
||||
return false;
|
||||
}
|
||||
if (!esp3d_DHT.begin()) {
|
||||
if (!esp3d_sensor.begin()) {
|
||||
output->printERROR ("Set failed!");
|
||||
return false;
|
||||
}
|
||||
@ -93,15 +85,15 @@ bool Commands::ESP210(const char* cmd_params, level_authenticate_type auth_type,
|
||||
}
|
||||
parameter = get_param (cmd_params, "interval=");
|
||||
if (parameter.length() != 0) {
|
||||
if (!Settings_ESP3D::write_uint32(ESP_DHT_INTERVAL,parameter.toInt())) {
|
||||
if (!Settings_ESP3D::write_uint32(ESP_SENSOR_INTERVAL,parameter.toInt())) {
|
||||
output->printERROR ("Set failed!");
|
||||
return false;
|
||||
}
|
||||
esp3d_DHT.setInterval(parameter.toInt());
|
||||
esp3d_sensor.setInterval(parameter.toInt());
|
||||
}
|
||||
output->printMSG ("ok");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
#endif //DHT_DEVICE
|
||||
#endif //SENSOR_DEVICE
|
||||
|
@ -23,6 +23,10 @@
|
||||
#include "../settings_esp3d.h"
|
||||
#include "../../modules/serial/serial_service.h"
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
#if defined (SENSOR_DEVICE)
|
||||
#include "../../modules/sensor/sensor.h"
|
||||
#endif //SENSOR_DEVICE
|
||||
|
||||
//Get full ESP3D settings
|
||||
//[ESP400]<pwd=admin>
|
||||
bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
|
||||
@ -425,29 +429,33 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->print ("\",\"H\":\"buzzer\",\"O\":[{\"no\":\"0\"},{\"yes\":\"1\"}]}");
|
||||
#endif //BUZZER_DEVICE
|
||||
|
||||
#ifdef DHT_DEVICE
|
||||
//DHT type
|
||||
output->print (",{\"F\":\"device/dht\",\"P\":\"");
|
||||
output->print (ESP_DHT_TYPE);
|
||||
#ifdef SENSOR_DEVICE
|
||||
//Sensor type
|
||||
output->print (",{\"F\":\"device/sensor\",\"P\":\"");
|
||||
output->print (ESP_SENSOR_TYPE);
|
||||
output->print ("\",\"T\":\"B\",\"V\":\"");
|
||||
output->print (Settings_ESP3D::read_byte(ESP_DHT_TYPE));
|
||||
output->print ("\",\"H\":\"type\",\"O\":[{\"none\":\"0\"},{\"11\":\"");
|
||||
output->print (DHT11_DEVICE);
|
||||
output->print ("\"},{\"22\":\"");
|
||||
output->print (DHT22_DEVICE);
|
||||
output->print ("\"}]}");
|
||||
output->print (Settings_ESP3D::read_byte(ESP_SENSOR_TYPE));
|
||||
output->print ("\",\"H\":\"type\",\"O\":[{\"none\":\"0\"}");
|
||||
for (uint8_t p = 0; p < esp3d_sensor.nbType(); p++) {
|
||||
output->print (",{\"");
|
||||
output->print (esp3d_sensor.GetModelString(p));
|
||||
output->print ("\":\"");
|
||||
output->print (esp3d_sensor.GetModel(p));
|
||||
output->print ("\"}");
|
||||
}
|
||||
output->print ("]}");
|
||||
|
||||
//DHT interval
|
||||
output->print (",{\"F\":\"device/dht\",\"P\":\"");
|
||||
output->print (ESP_DHT_INTERVAL);
|
||||
//Sensor interval
|
||||
output->print (",{\"F\":\"device/sensor\",\"P\":\"");
|
||||
output->print (ESP_SENSOR_INTERVAL);
|
||||
output->print ("\",\"T\":\"I\",\"V\":\"");
|
||||
output->print (Settings_ESP3D::read_uint32(ESP_DHT_INTERVAL));
|
||||
output->print (Settings_ESP3D::read_uint32(ESP_SENSOR_INTERVAL));
|
||||
output->print ("\",\"H\":\"intervalms\",\"S\":\"");
|
||||
output->print (Settings_ESP3D::get_max_int32_value(ESP_DHT_INTERVAL));
|
||||
output->print (Settings_ESP3D::get_max_int32_value(ESP_SENSOR_INTERVAL));
|
||||
output->print ("\",\"M\":\"");
|
||||
output->print (Settings_ESP3D::get_min_int32_value(ESP_DHT_INTERVAL));
|
||||
output->print (Settings_ESP3D::get_min_int32_value(ESP_SENSOR_INTERVAL));
|
||||
output->print ("\"}");
|
||||
#endif //DHT_DEVICE
|
||||
#endif //SENSOR_DEVICE
|
||||
#ifdef SD_DEVICE
|
||||
//Direct SD
|
||||
output->print(",{\"F\":\"device/sd\",\"P\":\"");
|
||||
|
@ -25,9 +25,9 @@
|
||||
#ifdef CAMERA_DEVICE
|
||||
#include "../../modules/camera/camera.h"
|
||||
#endif //CAMERA_DEVICE
|
||||
#ifdef DHT_DEVICE
|
||||
#include "../../modules/dht/dht.h"
|
||||
#endif //DHT_DEVICE
|
||||
#ifdef SENSOR_DEVICE
|
||||
#include "../../modules/sensor/sensor.h"
|
||||
#endif //SENSOR_DEVICE
|
||||
#ifdef BUZZER_DEVICE
|
||||
#include "../../modules/buzzer/buzzer.h"
|
||||
#endif //BUZZER_DEVICE
|
||||
@ -94,11 +94,11 @@ bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type,
|
||||
notificationsservice.setAutonotification((sval.toInt() == 0)?false:true);
|
||||
break;
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
#ifdef DHT_DEVICE
|
||||
case ESP_DHT_TYPE:
|
||||
esp3d_DHT.begin();
|
||||
#ifdef SENSOR_DEVICE
|
||||
case ESP_SENSOR_TYPE:
|
||||
esp3d_sensor.begin();
|
||||
break;
|
||||
#endif //DHT_DEVICE
|
||||
#endif //SENSOR_DEVICE
|
||||
#ifdef BUZZER_DEVICE
|
||||
case ESP_BUZZER:
|
||||
if (sval.toInt() == 1) {
|
||||
@ -120,11 +120,11 @@ bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type,
|
||||
} else {
|
||||
//dynamique refresh is better than restart the board
|
||||
switch(spos.toInt()) {
|
||||
#ifdef DHT_DEVICE
|
||||
case ESP_DHT_INTERVAL:
|
||||
esp3d_DHT.setInterval(sval.toInt());
|
||||
#ifdef SENSOR_DEVICE
|
||||
case ESP_SENSOR_INTERVAL:
|
||||
esp3d_sensor.setInterval(sval.toInt());
|
||||
break;
|
||||
#endif //DHT_DEVICE
|
||||
#endif //SENSOR_DEVICE
|
||||
#ifdef CAMERA_DEVICE
|
||||
case ESP_CAMERA_PORT:
|
||||
//esp3d_camera.begin();
|
||||
|
@ -53,9 +53,9 @@
|
||||
#if defined (TIMESTAMP_FEATURE)
|
||||
#include "../../modules/time/time_server.h"
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
#if defined (DHT_DEVICE)
|
||||
#include "../../modules/dht/dht.h"
|
||||
#endif //DHT_DEVICE
|
||||
#if defined (SENSOR_DEVICE)
|
||||
#include "../../modules/sensor/sensor.h"
|
||||
#endif //SENSOR_DEVICE
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
#include "../../modules/notifications/notifications_service.h"
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
@ -1176,26 +1176,26 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printLN("");
|
||||
}
|
||||
#endif //SD_DEVICE
|
||||
#if defined (DHT_DEVICE)
|
||||
#if defined (SENSOR_DEVICE)
|
||||
if (!plain) {
|
||||
output->print (",{\"id\":\"");
|
||||
}
|
||||
output->print ("dht");
|
||||
output->print ("sensor");
|
||||
if (!plain) {
|
||||
output->print ("\",\"value\":\"");
|
||||
} else {
|
||||
output->print (": ");
|
||||
}
|
||||
output->print (esp3d_DHT.started()?"ON":"OFF");
|
||||
output->print (esp3d_sensor.started()?"ON":"OFF");
|
||||
output->print ("(");
|
||||
output->print (esp3d_DHT.GetModelString());
|
||||
output->print (esp3d_sensor.GetModelString());
|
||||
output->print (")");
|
||||
if (!plain) {
|
||||
output->print ("\"}");
|
||||
} else {
|
||||
output->printLN("");
|
||||
}
|
||||
#endif //DHT_DEVICE
|
||||
#endif //SENSOR_DEVICE
|
||||
#if defined (BUZZER_DEVICE)
|
||||
if (!plain) {
|
||||
output->print (",{\"id\":\"");
|
||||
|
@ -46,8 +46,8 @@
|
||||
#define CURRENT_SETTINGS_VERSION "ESP3D04"
|
||||
|
||||
//boundaries
|
||||
#define MAX_DHT_INTERVAL 60000
|
||||
#define MIN_DHT_INTERVAL 0
|
||||
#define MAX_SENSOR_INTERVAL 60000
|
||||
#define MIN_SENSOR_INTERVAL 0
|
||||
#define MAX_LOCAL_PASSWORD_LENGTH 20
|
||||
#define MIN_LOCAL_PASSWORD_LENGTH 1
|
||||
#define MAX_VERSION_LENGTH 7 //ESP3DXX
|
||||
@ -104,7 +104,7 @@
|
||||
#define DEFAULT_SD_MOUNT ESP_SD_ROOT
|
||||
#define DEFAULT_DIRECT_SD_CHECK 0
|
||||
#define DEFAULT_SD_CHECK_UPDATE_AT_BOOT 1
|
||||
#define DEFAULT_DHT_TYPE NO_DHT_DEVICE
|
||||
#define DEFAULT_SENSOR_TYPE NO_SENSOR_DEVICE
|
||||
#ifdef SD_DEVICE
|
||||
#define DEFAULT_SD_DEVICE_TYPE SD_DEVICE_CONNECTION
|
||||
#else
|
||||
@ -131,7 +131,7 @@
|
||||
#define DEFAULT_WEBSOCKET_PORT 8282L
|
||||
#define DEFAULT_CAMERA_PORT 9600L
|
||||
#define DEFAULT_TELNET_PORT 23L
|
||||
#define DEFAULT_DHT_INTERVAL 30000L
|
||||
#define DEFAULT_SENSOR_INTERVAL 30000L
|
||||
#define DEFAULT_BOOT_DELAY 10000L
|
||||
#define DEFAULT_CALIBRATION_VALUE 0
|
||||
#define DEFAULT_CALIBRATION_DONE 0
|
||||
@ -328,11 +328,11 @@ uint8_t Settings_ESP3D::get_default_byte_value(int pos)
|
||||
break;
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
|
||||
#if defined(DHT_DEVICE)
|
||||
case ESP_DHT_TYPE:
|
||||
res = DEFAULT_DHT_TYPE;
|
||||
#if defined(SENSOR_DEVICE)
|
||||
case ESP_SENSOR_TYPE:
|
||||
res = DEFAULT_SENSOR_TYPE;
|
||||
break;
|
||||
#endif //DHT_DEVICE
|
||||
#endif //SENSOR_DEVICE
|
||||
#if defined(DISPLAY_DEVICE) && defined(DISPLAY_TOUCH_DRIVER)
|
||||
case ESP_CALIBRATION:
|
||||
res = DEFAULT_CALIBRATION_DONE;
|
||||
@ -407,11 +407,11 @@ uint32_t Settings_ESP3D::get_default_int32_value(int pos)
|
||||
res = DEFAULT_CAMERA_PORT;
|
||||
break;
|
||||
#endif //CAMERA_DEVICE
|
||||
#if defined(DHT_DEVICE)
|
||||
case ESP_DHT_INTERVAL:
|
||||
res = DEFAULT_DHT_INTERVAL;
|
||||
#if defined(SENSOR_DEVICE)
|
||||
case ESP_SENSOR_INTERVAL:
|
||||
res = DEFAULT_SENSOR_INTERVAL;
|
||||
break;
|
||||
#endif //DHT_DEVICE
|
||||
#endif //SENSOR_DEVICE
|
||||
default:
|
||||
res = DEFAULT_ESP_INT;
|
||||
}
|
||||
@ -453,11 +453,11 @@ uint32_t Settings_ESP3D::get_max_int32_value(int pos)
|
||||
res = MAX_WEBSOCKET_PORT;
|
||||
break;
|
||||
#endif //WS_DATA_FEATURE
|
||||
#if defined(DHT_DEVICE)
|
||||
case ESP_DHT_INTERVAL:
|
||||
res = MAX_DHT_INTERVAL;
|
||||
#if defined(SENSOR_DEVICE)
|
||||
case ESP_SENSOR_INTERVAL:
|
||||
res = MAX_SENSOR_INTERVAL;
|
||||
break;
|
||||
#endif //DHT_DEVICE
|
||||
#endif //SENSOR_DEVICE
|
||||
default:
|
||||
res = DEFAULT_ESP_INT;
|
||||
}
|
||||
@ -499,11 +499,11 @@ uint32_t Settings_ESP3D::get_min_int32_value(int pos)
|
||||
res = MIN_WEBSOCKET_PORT;
|
||||
break;
|
||||
#endif //WS_DATA_FEATURE
|
||||
#if defined(DHT_DEVICE)
|
||||
case ESP_DHT_INTERVAL:
|
||||
res = MIN_DHT_INTERVAL;
|
||||
#if defined(SENSOR_DEVICE)
|
||||
case ESP_SENSOR_INTERVAL:
|
||||
res = MIN_SENSOR_INTERVAL;
|
||||
break;
|
||||
#endif //DHT_DEVICE
|
||||
#endif //SENSOR_DEVICE
|
||||
default:
|
||||
res = DEFAULT_ESP_INT;
|
||||
}
|
||||
@ -1169,12 +1169,12 @@ bool Settings_ESP3D::reset()
|
||||
//Time Server 3 address
|
||||
Settings_ESP3D::write_string(ESP_TIME_SERVER3, Settings_ESP3D::get_default_string_value(ESP_TIME_SERVER3).c_str());
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
#ifdef DHT_DEVICE
|
||||
//DHT device
|
||||
Settings_ESP3D::write_byte(ESP_DHT_TYPE,Settings_ESP3D::get_default_byte_value(ESP_DHT_TYPE));
|
||||
//DHT query interval
|
||||
Settings_ESP3D::write_uint32 (ESP_DHT_INTERVAL, Settings_ESP3D::get_default_int32_value(ESP_DHT_INTERVAL));
|
||||
#endif //DHT_DEVICE
|
||||
#ifdef SENSOR_DEVICE
|
||||
//Sensor device
|
||||
Settings_ESP3D::write_byte(ESP_SENSOR_TYPE,Settings_ESP3D::get_default_byte_value(ESP_SENSOR_TYPE));
|
||||
//Sensor query interval
|
||||
Settings_ESP3D::write_uint32 (ESP_SENSOR_INTERVAL, Settings_ESP3D::get_default_int32_value(ESP_SENSOR_INTERVAL));
|
||||
#endif //SENSOR_DEVICE
|
||||
//Start Delay
|
||||
Settings_ESP3D::write_uint32 (ESP_BOOT_DELAY, Settings_ESP3D::get_default_int32_value(ESP_BOOT_DELAY));
|
||||
#endif //SETTINGS_IN_EEPROM
|
||||
|
@ -53,7 +53,7 @@
|
||||
#define ESP_TELNET_PORT 125 //4 bytes = int
|
||||
#define ESP_OUTPUT_FLAG 129 //1 bytes = flag
|
||||
#define ESP_HOSTNAME 130 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese
|
||||
#define ESP_DHT_INTERVAL 164 //4 bytes = int
|
||||
#define ESP_SENSOR_INTERVAL 164 //4 bytes = int
|
||||
#define ESP_SETTINGS_VERSION 168 //8 bytes = 7+1 = string ESP3D + 2 digits
|
||||
#define ESP_ADMIN_PWD 176 //21 bytes 20+1 = string ; warning does not support multibyte char like chinese
|
||||
#define ESP_USER_PWD 197 //21 bytes 20+1 = string ; warning does not support multibyte char like chinese
|
||||
@ -68,7 +68,7 @@
|
||||
#define ESP_SD_SPEED_DIV 331 //1 byte = flag
|
||||
#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_SENSOR_TYPE 460 //1 bytes = flag
|
||||
#define ESP_TARGET_FW 461 //1 bytes = flag
|
||||
#define ESP_TIMEZONE 462 //1 bytes = flag
|
||||
#define ESP_TIME_IS_DST 463 //1 bytes = flag
|
||||
|
@ -87,10 +87,14 @@
|
||||
#define ESP_LINE_NOTIFICATION 3
|
||||
#define ESP_TELEGRAM_NOTIFICATION 4
|
||||
|
||||
//DHT
|
||||
#define NO_DHT_DEVICE 0
|
||||
//SENSOR
|
||||
#define NO_SENSOR_DEVICE 0
|
||||
#define DHT11_DEVICE 1
|
||||
#define DHT22_DEVICE 2
|
||||
#define ANALOG_DEVICE 3
|
||||
#define BMP280_DEVICE 4
|
||||
#define BME280_DEVICE 5
|
||||
|
||||
#define USE_CELSIUS 1
|
||||
#define USE_FAHRENHEIT 2
|
||||
|
||||
|
@ -40,8 +40,8 @@
|
||||
#define RECOVERY_FEATURE
|
||||
#endif //PIN_RESET_FEATURE || SD_RECOVERY_FEATURE
|
||||
|
||||
#if defined(DISPLAY_DEVICE) || defined(DHT_DEVICE) || defined(RECOVERY_FEATURE) || defined(BUZZER_DEVICE) || defined(CAMERA_DEVICE) || defined(SD_DEVICE)
|
||||
#if defined(DISPLAY_DEVICE) || defined(SENSOR_DEVICE) || defined(RECOVERY_FEATURE) || defined(BUZZER_DEVICE) || defined(CAMERA_DEVICE) || defined(SD_DEVICE)
|
||||
#define CONNECTED_DEVICES_FEATURE
|
||||
#endif //DISPLAY_DEVICE || DHT_DEVICE , etc...
|
||||
#endif //DISPLAY_DEVICE || SENSOR_DEVICE , etc...
|
||||
|
||||
#endif //_ESP3D_CONFIG_H
|
||||
|
@ -22,7 +22,7 @@
|
||||
#define _VERSION_ESP3D_H
|
||||
|
||||
//version and sources location
|
||||
#define FW_VERSION "3.0.0.a50"
|
||||
#define FW_VERSION "3.0.0.a51"
|
||||
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
|
||||
|
||||
#endif //_VERSION_ESP3D_H
|
||||
|
@ -27,9 +27,9 @@
|
||||
#ifdef DISPLAY_DEVICE
|
||||
#include "../display/display.h"
|
||||
#endif //DISPLAY_DEVICE
|
||||
#ifdef DHT_DEVICE
|
||||
#include "../dht/dht.h"
|
||||
#endif //DHT_DEVICE
|
||||
#ifdef SENSOR_DEVICE
|
||||
#include "../sensor/sensor.h"
|
||||
#endif //SENSOR_DEVICE
|
||||
#ifdef BUZZER_DEVICE
|
||||
#include "../buzzer/buzzer.h"
|
||||
#endif //BUZZER_DEVICE
|
||||
@ -61,12 +61,12 @@ bool DevicesServices::begin()
|
||||
res = false;
|
||||
}
|
||||
#endif //DISPLAY_DEVICE
|
||||
#ifdef DHT_DEVICE
|
||||
if (!esp3d_DHT.begin()) {
|
||||
log_esp3d("Error starting DHT device");
|
||||
#ifdef SENSOR_DEVICE
|
||||
if (!esp3d_sensor.begin()) {
|
||||
log_esp3d("Error starting sensor device");
|
||||
res = false;
|
||||
}
|
||||
#endif //DHT_DEVICE
|
||||
#endif //SENSOR_DEVICE
|
||||
#ifdef BUZZER_DEVICE
|
||||
if (!esp3d_buzzer.begin()) {
|
||||
log_esp3d("Error starting buzzer device");
|
||||
@ -112,9 +112,9 @@ void DevicesServices::end()
|
||||
#ifdef DISPLAY_DEVICE
|
||||
esp3d_display.end();
|
||||
#endif //DISPLAY_DEVICE
|
||||
#ifdef DHT_DEVICE
|
||||
esp3d_DHT.end();
|
||||
#endif //DHT_DDEVICE
|
||||
#ifdef SENSOR_DEVICE
|
||||
esp3d_sensor.end();
|
||||
#endif //SENSOR_DEVICE
|
||||
}
|
||||
|
||||
void DevicesServices::handle()
|
||||
@ -123,9 +123,9 @@ void DevicesServices::handle()
|
||||
#ifdef DISPLAY_DEVICE
|
||||
esp3d_display.handle();
|
||||
#endif //DISPLAY_DEVICE
|
||||
#ifdef DHT_DEVICE
|
||||
esp3d_DHT.handle();
|
||||
#endif //DHT_DEVICE
|
||||
#ifdef SENSOR_DEVICE
|
||||
esp3d_sensor.handle();
|
||||
#endif //SENSOR_DEVICE
|
||||
#ifdef BUZZER_DEVICE
|
||||
esp3d_buzzer.handle();
|
||||
#endif //BUZZER_DEVICE
|
||||
|
@ -1,192 +0,0 @@
|
||||
/*
|
||||
dht.cpp - dht functions 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"
|
||||
#ifdef DHT_DEVICE
|
||||
#include "dht.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include <DHTesp.h>
|
||||
#if defined (WIFI_FEATURE) || defined(ETH_FEATURE)
|
||||
#include "../websocket/websocket_server.h"
|
||||
#endif // WIFI_FEATURE || ETH_FEATURE
|
||||
|
||||
DHT esp3d_DHT;
|
||||
DHTesp * dht_device;
|
||||
|
||||
DHT::DHT()
|
||||
{
|
||||
_temperature =0;
|
||||
_humidity =0;
|
||||
_started = false;
|
||||
_interval = 0;
|
||||
dht_device = nullptr;
|
||||
#if DHT_UNIT == USE_FAHRENHEIT
|
||||
_usecelsius = false;
|
||||
#else
|
||||
_usecelsius = true;
|
||||
#endif
|
||||
}
|
||||
DHT::~DHT()
|
||||
{
|
||||
end();
|
||||
}
|
||||
|
||||
bool DHT::begin()
|
||||
{
|
||||
bool res = true;
|
||||
end();
|
||||
uint8_t dhttype= Settings_ESP3D::read_byte(ESP_DHT_TYPE);
|
||||
log_esp3d("DHT %d", dhttype);
|
||||
//No DHT defined - exit is not and error
|
||||
if (dhttype == 0) {
|
||||
return true;
|
||||
}
|
||||
//DHT type is unknown - exit as error
|
||||
if (!((dhttype == DHT11_DEVICE) || (dhttype == DHT22_DEVICE))) {
|
||||
return false;
|
||||
}
|
||||
dht_device = new DHTesp;
|
||||
|
||||
//dht_device = new DHTesp;
|
||||
if (!dht_device) {
|
||||
return false;
|
||||
}
|
||||
//no need to check pin because it is hard coded
|
||||
dht_device->setup(ESP3D_DHT_PIN, (DHTesp::DHT_MODEL_t)dhttype);
|
||||
_interval = Settings_ESP3D::read_uint32(ESP_DHT_INTERVAL);
|
||||
log_esp3d("DHT status %d", dht_device->getStatus());
|
||||
if (!dht_device->getStatus()) {
|
||||
res = false;
|
||||
}
|
||||
if (!res) {
|
||||
end();
|
||||
}
|
||||
_lastReadTime = millis();
|
||||
_started = res;
|
||||
return _started;
|
||||
}
|
||||
|
||||
bool DHT::isCelsiusUnit()
|
||||
{
|
||||
return _usecelsius;
|
||||
}
|
||||
void DHT::setCelsiusUnit(bool set)
|
||||
{
|
||||
_usecelsius = set;
|
||||
}
|
||||
|
||||
void DHT::end()
|
||||
{
|
||||
if(!_started) {
|
||||
return;
|
||||
}
|
||||
if (dht_device) {
|
||||
delete dht_device;
|
||||
dht_device = nullptr;
|
||||
}
|
||||
_started = false;
|
||||
_interval = 0;
|
||||
_temperature =0;
|
||||
_humidity =0;
|
||||
}
|
||||
|
||||
uint8_t DHT::GetModel()
|
||||
{
|
||||
if (_started) {
|
||||
return dht_device->getModel();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
float DHT::getHumidity()
|
||||
{
|
||||
if (_started) {
|
||||
return _humidity;
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float DHT::getTemperature()
|
||||
{
|
||||
if (_started) {
|
||||
if (_usecelsius) {
|
||||
return _temperature;
|
||||
} else {
|
||||
return dht_device->toFahrenheit(dht_device->getTemperature());
|
||||
}
|
||||
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
||||
const char * DHT::GetModelString()
|
||||
{
|
||||
if (_started) {
|
||||
if (dht_device->getModel() == 1) {
|
||||
return "DHT11";
|
||||
} else {
|
||||
return "DHT22";
|
||||
}
|
||||
}
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
bool DHT::started()
|
||||
{
|
||||
return _started;
|
||||
}
|
||||
|
||||
bool DHT::setInterval(uint interval)
|
||||
{
|
||||
_interval = interval;
|
||||
return true;
|
||||
}
|
||||
uint DHT::interval()
|
||||
{
|
||||
return _interval;
|
||||
}
|
||||
|
||||
void DHT::handle()
|
||||
{
|
||||
if (_started) {
|
||||
if ((millis() - _lastReadTime) > _interval) {
|
||||
_temperature = dht_device->getTemperature();
|
||||
_humidity = dht_device->getHumidity();
|
||||
_lastReadTime = millis();
|
||||
#if defined (WIFI_FEATURE) || defined(ETH_FEATURE)
|
||||
String s = "DHT:" ;
|
||||
s += String(_humidity,1);
|
||||
if (s !="nan") {
|
||||
s+="% ";
|
||||
s+= String(_temperature,1);
|
||||
s+= _usecelsius?"C ":"F ";
|
||||
} else {
|
||||
s ="DHT:Disconnected ";
|
||||
}
|
||||
websocket_terminal_server.pushMSG(s.c_str());
|
||||
#endif // WIFI_FEATURE || ETH_FEATURE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif //DHT_DEVICE
|
88
esp3d/src/modules/sensor/analogsensor.cpp
Normal file
88
esp3d/src/modules/sensor/analogsensor.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
dht.cpp - dht functions 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"
|
||||
#ifdef SENSOR_DEVICE
|
||||
#if SENSOR_DEVICE==ANALOG_DEVICE
|
||||
#include "analogsensor.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
|
||||
AnalogSensorDevice::AnalogSensorDevice()
|
||||
{
|
||||
}
|
||||
|
||||
AnalogSensorDevice::~AnalogSensorDevice()
|
||||
{
|
||||
}
|
||||
|
||||
bool AnalogSensorDevice::begin()
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AnalogSensorDevice::end()
|
||||
{
|
||||
}
|
||||
|
||||
bool AnalogSensorDevice::isModelValid(uint8_t model)
|
||||
{
|
||||
if (model == ANALOG_DEVICE) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t AnalogSensorDevice::getIDFromString(const char *s)
|
||||
{
|
||||
if (strcmp(s, "ANALOG")== 0 ) {
|
||||
return ANALOG_DEVICE;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t AnalogSensorDevice::nbType()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t AnalogSensorDevice::GetModel(uint8_t i)
|
||||
{
|
||||
return ANALOG_DEVICE;
|
||||
}
|
||||
|
||||
const char * AnalogSensorDevice::GetModelString(uint8_t i)
|
||||
{
|
||||
return "ANALOG";
|
||||
}
|
||||
|
||||
const char * AnalogSensorDevice::GetData()
|
||||
{
|
||||
static String s;
|
||||
s = String(SENSOR_CONVERTER(analogRead(ESP3D_SENSOR_PIN)));
|
||||
s += SENSOR__UNIT;
|
||||
return s.c_str();
|
||||
}
|
||||
|
||||
|
||||
#endif //ANALOG_DEVICE
|
||||
#endif //SENSOR_DEVICE
|
44
esp3d/src/modules/sensor/analogsensor.h
Normal file
44
esp3d/src/modules/sensor/analogsensor.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
analogsensor.h - sensor functions 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
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _ANALOG_SENSOR_H
|
||||
#define _ANALOG_SENSOR_H
|
||||
|
||||
#include "sensor.h"
|
||||
|
||||
class AnalogSensorDevice : ESP3DSensorDevice
|
||||
{
|
||||
public:
|
||||
AnalogSensorDevice();
|
||||
~AnalogSensorDevice();
|
||||
bool begin();
|
||||
void end();
|
||||
bool isModelValid(uint8_t model);
|
||||
uint8_t getIDFromString(const char *);
|
||||
uint8_t nbType();
|
||||
uint8_t GetModel(uint8_t i=0);
|
||||
const char *GetModelString(uint8_t i=0);
|
||||
const char * GetData();
|
||||
};
|
||||
|
||||
#endif //_ANALOG_SENSOR_H
|
||||
|
152
esp3d/src/modules/sensor/dht.cpp
Normal file
152
esp3d/src/modules/sensor/dht.cpp
Normal file
@ -0,0 +1,152 @@
|
||||
/*
|
||||
dht.cpp - dht functions 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"
|
||||
#ifdef SENSOR_DEVICE
|
||||
#if SENSOR_DEVICE==DHT11_DEVICE || SENSOR_DEVICE==DHT22_DEVICE
|
||||
#include "dht.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include <DHTesp.h>
|
||||
|
||||
|
||||
#define NB_TYPE_SENSOR 2
|
||||
const char * SENSOR_NAME[NB_TYPE_SENSOR] = {"DHT11", "DHT22"};
|
||||
const uint8_t SENSOR_ID[NB_TYPE_SENSOR] = {DHT11_DEVICE, DHT22_DEVICE};
|
||||
const DHTesp::DHT_MODEL_t SENSOR_TYPE[NB_TYPE_SENSOR] = {DHTesp::DHT11, DHTesp::DHT22};
|
||||
DHTesp * dht_device;
|
||||
|
||||
DHTSensorDevice::DHTSensorDevice()
|
||||
{
|
||||
dht_device = nullptr;
|
||||
}
|
||||
|
||||
DHTSensorDevice::~DHTSensorDevice()
|
||||
{
|
||||
end();
|
||||
}
|
||||
|
||||
bool DHTSensorDevice::begin()
|
||||
{
|
||||
end();
|
||||
uint8_t dhttype= Settings_ESP3D::read_byte(ESP_SENSOR_TYPE);
|
||||
if (dhttype == 0) {
|
||||
log_esp3d("No Sensor active");
|
||||
return true;
|
||||
}
|
||||
if (!isModelValid(dhttype)) {
|
||||
log_esp3d("No valid id ");
|
||||
return false;
|
||||
}
|
||||
dht_device = new DHTesp;
|
||||
if (!dht_device) {
|
||||
log_esp3d("Cannot instanciate dht");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("DHT PIN %d",ESP3D_SENSOR_PIN);
|
||||
dht_device->setup(ESP3D_SENSOR_PIN, SENSOR_TYPE[dhttype]);
|
||||
if (strcmp(dht_device->getStatusString(), "OK")!=0) {
|
||||
log_esp3d("No valid dht status: %d, %s",dht_device->getStatus(), dht_device->getStatusString());
|
||||
return false;
|
||||
}
|
||||
log_esp3d("DHT ok");
|
||||
return true;
|
||||
}
|
||||
|
||||
void DHTSensorDevice::end()
|
||||
{
|
||||
if (dht_device) {
|
||||
delete dht_device;
|
||||
}
|
||||
dht_device = nullptr;
|
||||
}
|
||||
|
||||
bool DHTSensorDevice::isModelValid(uint8_t model)
|
||||
{
|
||||
for (uint8_t i = 0; i < NB_TYPE_SENSOR; i++) {
|
||||
if (model == SENSOR_ID[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t DHTSensorDevice::getIDFromString(const char *s)
|
||||
{
|
||||
for (uint8_t i = 0; i < NB_TYPE_SENSOR; i++) {
|
||||
log_esp3d("checking %s with %s",s, SENSOR_NAME[i]);
|
||||
if (strcmp(s, SENSOR_NAME[i])==0) {
|
||||
log_esp3d("found %d",SENSOR_ID[i]);
|
||||
return SENSOR_ID[i];
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t DHTSensorDevice::nbType()
|
||||
{
|
||||
return NB_TYPE_SENSOR;
|
||||
}
|
||||
|
||||
uint8_t DHTSensorDevice::GetModel(uint8_t i)
|
||||
{
|
||||
if (i <NB_TYPE_SENSOR) {
|
||||
return SENSOR_ID[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * DHTSensorDevice::GetModelString(uint8_t i)
|
||||
{
|
||||
if (i <NB_TYPE_SENSOR) {
|
||||
return SENSOR_NAME[i];
|
||||
}
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
const char * DHTSensorDevice::GetData()
|
||||
{
|
||||
static String s;
|
||||
if (dht_device) {
|
||||
float temperature = dht_device->getTemperature();
|
||||
float humidity= dht_device->getHumidity();
|
||||
log_esp3d("T %f H %f",temperature, humidity);
|
||||
if (strcmp(SENSOR__UNIT,"F")==0) {
|
||||
temperature = dht_device->toFahrenheit(temperature);
|
||||
}
|
||||
if ( String(humidity,1)!="nan") {
|
||||
s= String(temperature,1);
|
||||
s+= SENSOR__UNIT;
|
||||
s+=" " + String(humidity,1) + "%";
|
||||
} else {
|
||||
s="DISCONNECTED";
|
||||
log_esp3d("No valid data");
|
||||
}
|
||||
} else {
|
||||
s="DISCONNECTED";
|
||||
log_esp3d("No device");
|
||||
}
|
||||
return s.c_str();
|
||||
}
|
||||
|
||||
|
||||
#endif //DHT11_DEVICE || DHT22_DEVICE
|
||||
#endif //SENSOR_DEVICE
|
44
esp3d/src/modules/sensor/dht.h
Normal file
44
esp3d/src/modules/sensor/dht.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
dht.h - sensor functions 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
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _ANALOG_SENSOR_H
|
||||
#define _ANALOG_SENSOR_H
|
||||
|
||||
#include "sensor.h"
|
||||
|
||||
class DHTSensorDevice : ESP3DSensorDevice
|
||||
{
|
||||
public:
|
||||
DHTSensorDevice();
|
||||
~DHTSensorDevice();
|
||||
bool begin();
|
||||
void end();
|
||||
bool isModelValid(uint8_t model);
|
||||
uint8_t getIDFromString(const char *);
|
||||
uint8_t nbType();
|
||||
uint8_t GetModel(uint8_t i=0);
|
||||
const char *GetModelString(uint8_t i=0);
|
||||
const char * GetData();
|
||||
};
|
||||
|
||||
#endif //_ANALOG_SENSOR_H
|
||||
|
@ -30,11 +30,9 @@ public:
|
||||
~DHT();
|
||||
bool begin();
|
||||
void end();
|
||||
void handle();
|
||||
bool setInterval(uint interval);
|
||||
uint interval();
|
||||
uint8_t GetModel();
|
||||
const char *GetModelString();
|
||||
const char *GetData();
|
||||
float getHumidity();
|
||||
float getTemperature();
|
||||
bool started();
|
||||
@ -43,13 +41,10 @@ public:
|
||||
private:
|
||||
bool _started;
|
||||
bool _usecelsius;
|
||||
uint32_t _interval;
|
||||
uint32_t _lastReadTime;
|
||||
float _temperature;
|
||||
float _humidity;
|
||||
};
|
||||
|
||||
extern DHT esp3d_DHT;
|
||||
|
||||
#endif //_DHT_H
|
||||
|
167
esp3d/src/modules/sensor/sensor.cpp
Normal file
167
esp3d/src/modules/sensor/sensor.cpp
Normal file
@ -0,0 +1,167 @@
|
||||
/*
|
||||
sensor.cpp - sensor functions 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"
|
||||
#ifdef SENSOR_DEVICE
|
||||
#include "sensor.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
//Include file according sensor
|
||||
#if SENSOR_DEVICE==DHT11_DEVICE || SENSOR_DEVICE==DHT22_DEVICE
|
||||
#include "dht.h"
|
||||
#endif //DHT11_DEVICE || DHT22_DEVICE
|
||||
#if SENSOR_DEVICE==ANALOG_DEVICE
|
||||
#include "analogsensor.h"
|
||||
#endif //ANALOG_DEVICE
|
||||
#if defined (WIFI_FEATURE) || defined(ETH_FEATURE)
|
||||
#include "../websocket/websocket_server.h"
|
||||
#endif // WIFI_FEATURE || ETH_FEATURE
|
||||
|
||||
ESP3DSensor esp3d_sensor;
|
||||
|
||||
ESP3DSensor::ESP3DSensor()
|
||||
{
|
||||
_started = false;
|
||||
_interval = 0;
|
||||
_device = nullptr;
|
||||
}
|
||||
|
||||
ESP3DSensor::~ESP3DSensor()
|
||||
{
|
||||
end();
|
||||
}
|
||||
|
||||
bool ESP3DSensor::begin()
|
||||
{
|
||||
log_esp3d("Sensor Begin");
|
||||
bool res = true;
|
||||
end();
|
||||
//new _device
|
||||
#if SENSOR_DEVICE==ANALOG_DEVICE
|
||||
_device = (ESP3DSensorDevice * )new AnalogSensorDevice();
|
||||
#endif //ANALOG_DEVICE
|
||||
#if SENSOR_DEVICE==DHT11_DEVICE || SENSOR_DEVICE==DHT22_DEVICE
|
||||
_device = (ESP3DSensorDevice * )new DHTSensorDevice();
|
||||
#endif //DHT11_DEVICE || DHT22_DEVICE
|
||||
if (!_device) {
|
||||
log_esp3d("No device created");
|
||||
return false;
|
||||
}
|
||||
log_esp3d("Sensor Device created");
|
||||
uint8_t sensortype= Settings_ESP3D::read_byte(ESP_SENSOR_TYPE);
|
||||
log_esp3d("Sensor %d", sensortype);
|
||||
//No Sensor defined - exit is not an error
|
||||
if (sensortype == 0) {
|
||||
log_esp3d("Sensor Device is not active at start");
|
||||
return true;
|
||||
}
|
||||
_interval = Settings_ESP3D::read_uint32(ESP_SENSOR_INTERVAL);
|
||||
if (!_device->begin()) {
|
||||
res = false;
|
||||
}
|
||||
_lastReadTime = millis();
|
||||
_started = res;
|
||||
return _started;
|
||||
}
|
||||
|
||||
void ESP3DSensor::end()
|
||||
{
|
||||
if (_device) {
|
||||
delete _device;
|
||||
_device = nullptr;
|
||||
}
|
||||
_started = false;
|
||||
_interval = 0;
|
||||
}
|
||||
|
||||
uint8_t ESP3DSensor::GetModel(uint8_t i)
|
||||
{
|
||||
if (_device) {
|
||||
return _device->GetModel(i);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ESP3DSensor::nbType()
|
||||
{
|
||||
if (_device) {
|
||||
|
||||
return _device->nbType();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool ESP3DSensor::isModelValid(uint8_t model)
|
||||
{
|
||||
if (_device) {
|
||||
return _device->isModelValid(model);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char * ESP3DSensor::GetModelString(uint8_t i)
|
||||
{
|
||||
if (_device) {
|
||||
|
||||
return _device->GetModelString(i);
|
||||
}
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
uint8_t ESP3DSensor::getIDFromString(const char * s)
|
||||
{
|
||||
if (_device) {
|
||||
return _device->getIDFromString(s);
|
||||
}
|
||||
Serial.println("no device");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ESP3DSensor::setInterval(uint interval)
|
||||
{
|
||||
_interval = interval;
|
||||
return true;
|
||||
}
|
||||
|
||||
const char * ESP3DSensor::GetData()
|
||||
{
|
||||
if (_started && _device) {
|
||||
return _device->GetData();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void ESP3DSensor::handle()
|
||||
{
|
||||
if (_started && _device) {
|
||||
if ((millis() - _lastReadTime) > _interval) {
|
||||
String data = _device->GetData();
|
||||
_lastReadTime = millis();
|
||||
#if defined (WIFI_FEATURE) || defined(ETH_FEATURE)
|
||||
String s = "SENSOR:" + data ;
|
||||
websocket_terminal_server.pushMSG(s.c_str());
|
||||
#endif // WIFI_FEATURE || ETH_FEATURE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif //SENSOR_DEVICE
|
93
esp3d/src/modules/sensor/sensor.h
Normal file
93
esp3d/src/modules/sensor/sensor.h
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
sensor.h - sensor functions 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
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _ESP3D_SENSOR_H
|
||||
#define _ESP3D_SENSOR_H
|
||||
|
||||
class ESP3DSensorDevice
|
||||
{
|
||||
public:
|
||||
ESP3DSensorDevice() {}
|
||||
virtual ~ESP3DSensorDevice() {}
|
||||
virtual bool begin()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual void end() {}
|
||||
virtual bool isModelValid(uint8_t model)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual uint8_t getIDFromString(const char *)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
virtual uint8_t nbType()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
virtual uint8_t GetModel(uint8_t i=0);
|
||||
virtual const char *GetModelString(uint8_t i=0)
|
||||
{
|
||||
return "None";
|
||||
}
|
||||
virtual const char * GetData()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
class ESP3DSensor
|
||||
{
|
||||
public:
|
||||
ESP3DSensor();
|
||||
~ESP3DSensor();
|
||||
bool begin();
|
||||
void end();
|
||||
void handle();
|
||||
bool setInterval(uint interval);
|
||||
bool isModelValid(uint8_t model);
|
||||
uint8_t getIDFromString(const char *s);
|
||||
uint8_t nbType();
|
||||
uint interval()
|
||||
{
|
||||
return _interval;
|
||||
}
|
||||
uint8_t GetModel(uint8_t i=0);
|
||||
const char *GetModelString(uint8_t i=0);
|
||||
const char * GetData();
|
||||
bool started()
|
||||
{
|
||||
return _started;
|
||||
}
|
||||
protected:
|
||||
bool _started;
|
||||
uint32_t _interval;
|
||||
uint32_t _lastReadTime;
|
||||
ESP3DSensorDevice * _device;
|
||||
};
|
||||
|
||||
|
||||
extern ESP3DSensor esp3d_sensor;
|
||||
|
||||
#endif //_ESP3D_SENSOR_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user