add sensor
This commit is contained in:
107
platformio.ini
107
platformio.ini
@@ -1,49 +1,98 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
extra_configs =
|
extra_configs =
|
||||||
factory_settings.ini
|
factory_settings.ini
|
||||||
features.ini
|
features.ini
|
||||||
default_envs = esp12e
|
default_envs = esp12e
|
||||||
;default_envs = node32s
|
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
build_flags=
|
build_flags =
|
||||||
${factory_settings.build_flags}
|
${factory_settings.build_flags}
|
||||||
${features.build_flags}
|
${features.build_flags}
|
||||||
-D NO_GLOBAL_ARDUINOOTA
|
-D NO_GLOBAL_ARDUINOOTA
|
||||||
; Uncomment ENABLE_CORS to enable Cross-Origin Resource Sharing (required for local React development)
|
-D ENABLE_CORS
|
||||||
-D ENABLE_CORS
|
-D CORS_ORIGIN=\"http://localhost:3000\"
|
||||||
-D CORS_ORIGIN=\"http://localhost:3000\"
|
-D PROGMEM_WWW
|
||||||
; Uncomment PROGMEM_WWW to enable the storage of the WWW data in PROGMEM
|
|
||||||
-D PROGMEM_WWW
|
|
||||||
|
|
||||||
; ensure transitive dependencies are included for correct platforms only
|
|
||||||
lib_compat_mode = strict
|
lib_compat_mode = strict
|
||||||
|
|
||||||
; Uncomment & modify the lines below in order to configure OTA updates
|
|
||||||
;upload_flags =
|
|
||||||
; --port=8266
|
|
||||||
; --auth=esp-react
|
|
||||||
;upload_port = 192.168.0.11
|
|
||||||
|
|
||||||
framework = arduino
|
framework = arduino
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
|
||||||
extra_scripts =
|
extra_scripts =
|
||||||
pre:scripts/build_interface.py
|
pre:scripts/build_interface.py
|
||||||
|
lib_deps =
|
||||||
|
ArduinoJson@>=6.0.0,<7.0.0
|
||||||
|
ESP Async WebServer@>=1.2.0,<2.0.0
|
||||||
|
AsyncMqttClient@>=0.8.2,<1.0.0
|
||||||
|
|
||||||
lib_deps =
|
|
||||||
ArduinoJson@>=6.0.0,<7.0.0
|
|
||||||
ESP Async WebServer@>=1.2.0,<2.0.0
|
|
||||||
AsyncMqttClient@>=0.8.2,<1.0.0
|
|
||||||
|
|
||||||
[env:esp12e]
|
[env:esp12e]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = esp12e
|
board = esp12e
|
||||||
board_build.f_cpu = 160000000L
|
board_build.f_cpu = 160000000L
|
||||||
board_build.filesystem = littlefs
|
board_build.filesystem = littlefs
|
||||||
|
lib_deps = milesburton/DallasTemperature@^3.9.1
|
||||||
|
|
||||||
[env:node32s]
|
[env:node32s]
|
||||||
; Comment out min_spiffs.csv setting if disabling PROGMEM_WWW with ESP32
|
|
||||||
board_build.partitions = min_spiffs.csv
|
board_build.partitions = min_spiffs.csv
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
board = node32s
|
board = node32s
|
||||||
|
lib_deps = milesburton/DallasTemperature@^3.9.1
|
||||||
|
|
||||||
|
[factory_settings]
|
||||||
|
build_flags =
|
||||||
|
|
||||||
|
-D FACTORY_WIFI_SSID=\"\"
|
||||||
|
-D FACTORY_WIFI_PASSWORD=\"\"
|
||||||
|
-D FACTORY_WIFI_HOSTNAME=\"#{platform}-#{unique_id}\"
|
||||||
|
|
||||||
|
-D FACTORY_AP_PROVISION_MODE=AP_MODE_DISCONNECTED
|
||||||
|
-D FACTORY_AP_SSID=\"ESP8266-React-#{unique_id}\"
|
||||||
|
-D FACTORY_AP_PASSWORD=\"esp-react\"
|
||||||
|
-D FACTORY_AP_CHANNEL=1
|
||||||
|
-D FACTORY_AP_SSID_HIDDEN=false
|
||||||
|
-D FACTORY_AP_MAX_CLIENTS=4
|
||||||
|
-D FACTORY_AP_LOCAL_IP=\"192.168.4.1\"
|
||||||
|
-D FACTORY_AP_GATEWAY_IP=\"192.168.4.1\"
|
||||||
|
-D FACTORY_AP_SUBNET_MASK=\"255.255.255.0\"
|
||||||
|
|
||||||
|
-D FACTORY_ADMIN_USERNAME=\"admin\"
|
||||||
|
-D FACTORY_ADMIN_PASSWORD=\"admin\"
|
||||||
|
-D FACTORY_GUEST_USERNAME=\"guest\"
|
||||||
|
-D FACTORY_GUEST_PASSWORD=\"guest\"
|
||||||
|
|
||||||
|
-D FACTORY_NTP_ENABLED=true
|
||||||
|
-D FACTORY_NTP_TIME_ZONE_LABEL=\"Europe/Brussels\"
|
||||||
|
-D FACTORY_NTP_TIME_ZONE_FORMAT=\"GMT0BST,M3.5.0/1,M10.5.0\"
|
||||||
|
-D FACTORY_NTP_SERVER=\"time.google.com\"
|
||||||
|
|
||||||
|
-D FACTORY_OTA_PORT=8266
|
||||||
|
-D FACTORY_OTA_PASSWORD=\"esp-react\"
|
||||||
|
-D FACTORY_OTA_ENABLED=true
|
||||||
|
|
||||||
|
-D FACTORY_MQTT_ENABLED=false
|
||||||
|
-D FACTORY_MQTT_HOST=\"test.mosquitto.org\"
|
||||||
|
-D FACTORY_MQTT_PORT=1883
|
||||||
|
-D FACTORY_MQTT_USERNAME=\"\"
|
||||||
|
-D FACTORY_MQTT_PASSWORD=\"\"
|
||||||
|
-D FACTORY_MQTT_CLIENT_ID=\"#{platform}-#{unique_id}\"
|
||||||
|
-D FACTORY_MQTT_KEEP_ALIVE=60
|
||||||
|
-D FACTORY_MQTT_CLEAN_SESSION=true
|
||||||
|
-D FACTORY_MQTT_MAX_TOPIC_LENGTH=128
|
||||||
|
|
||||||
|
-D FACTORY_JWT_SECRET=\"#{random}-#{random}\"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
build_flags =
|
||||||
|
-D FT_PROJECT=1
|
||||||
|
-D FT_SECURITY=1
|
||||||
|
-D FT_MQTT=1
|
||||||
|
-D FT_NTP=1
|
||||||
|
-D FT_OTA=1
|
||||||
|
-D FT_UPLOAD_FIRMWARE=1
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ FanStateService::FanStateService(AsyncWebServer* server, FS* fs, SecurityManager
|
|||||||
fs,
|
fs,
|
||||||
FAN_SETTINGS_FILE) {
|
FAN_SETTINGS_FILE) {
|
||||||
// pinMode(FAN_PIN, OUTPUT);
|
// pinMode(FAN_PIN, OUTPUT);
|
||||||
pinMode(_state.fanGpio, OUTPUT);
|
pinMode(_state.fanPwmGPIO, OUTPUT);
|
||||||
// configure settings service update handler to update LED state
|
// configure settings service update handler to update LED state
|
||||||
addUpdateHandler([&](const String& originId) { onConfigUpdated(); }, false);
|
addUpdateHandler([&](const String& originId) { onConfigUpdated(); }, false);
|
||||||
}
|
}
|
||||||
@@ -28,9 +28,9 @@ void FanStateService::begin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FanStateService::onConfigUpdated() {
|
void FanStateService::onConfigUpdated() {
|
||||||
Serial.println(" ** Fan UPDATE (pin " + (String)_state.fanGpio + ") to " + _state.fanMaxSpeed);
|
Serial.println(" ** Fan UPDATE (pin " + (String)_state.fanPwmGPIO + ") to " + _state.fanMaxSpeed);
|
||||||
//digitalWrite(FAN_PIN, _state.fanStatus ? FAN_ON : FAN_OFF);
|
//digitalWrite(FAN_PIN, _state.fanStatus ? FAN_ON : FAN_OFF);
|
||||||
analogWrite(_state.fanGpio, _state.fanMaxSpeed);
|
analogWrite(_state.fanPwmGPIO, _state.fanMaxSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FanStateService::save() {
|
void FanStateService::save() {
|
||||||
|
|||||||
@@ -8,13 +8,17 @@
|
|||||||
#define FAN_PIN 13
|
#define FAN_PIN 13
|
||||||
#define PRINT_DELAY 5000
|
#define PRINT_DELAY 5000
|
||||||
|
|
||||||
#define DEFAULT_FAN_STATE false
|
|
||||||
#define DEFAULT_FAN_GPIO 13
|
|
||||||
#define DEFAULT_THRES_LOW 25
|
#define DEFAULT_FAN_STATE false
|
||||||
#define DEFAULT_THRES_HIGH 70
|
#define DEFAULT_FAN_PWM_GPIO 13
|
||||||
#define DEFAULT_FAN_MAX_SPEED 1021
|
#define DEFAULT_FAN_TACH_GPIO 13
|
||||||
#define OFF_STATE "OFF"
|
#define DEFAULT_ONEWIRE_GPIO 16
|
||||||
#define ON_STATE "ON"
|
#define DEFAULT_THRES_LOW 25
|
||||||
|
#define DEFAULT_THRES_HIGH 70
|
||||||
|
#define DEFAULT_FAN_MAX_SPEED 1021
|
||||||
|
#define OFF_STATE "OFF"
|
||||||
|
#define ON_STATE "ON"
|
||||||
|
|
||||||
// Note that the built-in LED is on when the pin is low on most NodeMCU boards.
|
// Note that the built-in LED is on when the pin is low on most NodeMCU boards.
|
||||||
// This is because the anode is tied to VCC and the cathode to the GPIO 4 (Arduino pin 2).
|
// This is because the anode is tied to VCC and the cathode to the GPIO 4 (Arduino pin 2).
|
||||||
@@ -34,14 +38,24 @@ class FanSettings {
|
|||||||
public:
|
public:
|
||||||
bool fanStatus;
|
bool fanStatus;
|
||||||
int fanSpeed;
|
int fanSpeed;
|
||||||
int fanGpio;
|
int fanPwmGPIO;
|
||||||
|
int fanTachGPIO;
|
||||||
int fanMaxSpeed;
|
int fanMaxSpeed;
|
||||||
int thresLow;
|
int thresLow;
|
||||||
int thresHigh;
|
int thresHigh;
|
||||||
|
|
||||||
|
int OneWireGPIO;
|
||||||
|
float sensorInTemp;
|
||||||
|
float sensorOutTemp;
|
||||||
|
|
||||||
static void read(FanSettings& settings, JsonObject& root) {
|
static void read(FanSettings& settings, JsonObject& root) {
|
||||||
|
root["oneWire_gpio"] = settings.OneWireGPIO;
|
||||||
|
root["sensor_in_temp"] = settings.sensorInTemp;
|
||||||
|
root["sensor_out_temp"] = settings.sensorOutTemp;
|
||||||
|
|
||||||
root["fan_status"] = settings.fanStatus;
|
root["fan_status"] = settings.fanStatus;
|
||||||
root["fan_gpio"] = settings.fanGpio;
|
root["fan_pwm_gpio"] = settings.fanPwmGPIO;
|
||||||
|
root["fan_tach_gpio"] = settings.fanTachGPIO;
|
||||||
root["fan_max_speed"] = settings.fanMaxSpeed;
|
root["fan_max_speed"] = settings.fanMaxSpeed;
|
||||||
root["temperature_thres_low"] = settings.thresLow;
|
root["temperature_thres_low"] = settings.thresLow;
|
||||||
root["temperature_thres_high"] = settings.thresHigh;
|
root["temperature_thres_high"] = settings.thresHigh;
|
||||||
@@ -54,22 +68,28 @@ class FanSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static StateUpdateResult update(JsonObject& root, FanSettings& fanState) {
|
static StateUpdateResult update(JsonObject& root, FanSettings& fanState) {
|
||||||
boolean newFanState = root["fan_status"] | DEFAULT_FAN_STATE;
|
boolean newFanState = root["fan_status"] | DEFAULT_FAN_STATE;
|
||||||
int newFanGpio = root["fan_gpio"] | DEFAULT_FAN_GPIO;
|
int newFanPwmGPIO = root["fan_pwm_gpio"] | DEFAULT_FAN_PWM_GPIO;
|
||||||
int newMaxSpeed = root["fan_max_speed"] | DEFAULT_FAN_MAX_SPEED;
|
int newFanTachGPIO = root["fan_tach_gpio"] | DEFAULT_FAN_TACH_GPIO;
|
||||||
int newThresLow = root["temperature_thres_low"] | DEFAULT_THRES_LOW;
|
int newMaxSpeed = root["fan_max_speed"] | DEFAULT_FAN_MAX_SPEED;
|
||||||
int newThresHigh = root["temperature_thres_high"] | DEFAULT_THRES_HIGH;
|
int newThresLow = root["temperature_thres_low"] | DEFAULT_THRES_LOW;
|
||||||
Serial.println(" ** Fan update [status:" + (String)newFanState + "|gpio:" + (String)newFanGpio + "|mxspd:" + (String)newMaxSpeed + "|low:" + (String)newThresLow + "|high:" + (String)newThresHigh + "]");
|
int newThresHigh = root["temperature_thres_high"] | DEFAULT_THRES_HIGH;
|
||||||
|
int newOneWireGPIO = root["sensor_onewire_gpio"] | DEFAULT_ONEWIRE_GPIO;
|
||||||
|
Serial.println(" ** Fan update [status:" + (String)newFanState + "|gpio:" + (String)newFanPwmGPIO + "|mxspd:" + (String)newMaxSpeed + "|low:" + (String)newThresLow + "|high:" + (String)newThresHigh + "]");
|
||||||
if ( fanState.fanStatus != newFanState
|
if ( fanState.fanStatus != newFanState
|
||||||
|| fanState.fanGpio != newFanGpio
|
|| fanState.fanPwmGPIO != newFanPwmGPIO
|
||||||
|
|| fanState.fanTachGPIO != newFanTachGPIO
|
||||||
|| fanState.fanMaxSpeed != newMaxSpeed
|
|| fanState.fanMaxSpeed != newMaxSpeed
|
||||||
|| fanState.thresLow != newThresLow
|
|| fanState.thresLow != newThresLow
|
||||||
|| fanState.thresHigh != newThresHigh ) {
|
|| fanState.thresHigh != newThresHigh
|
||||||
|
|| fanState.OneWireGPIO != newOneWireGPIO ) {
|
||||||
fanState.fanStatus = newFanState;
|
fanState.fanStatus = newFanState;
|
||||||
fanState.fanGpio = newFanGpio;
|
fanState.fanPwmGPIO = newFanPwmGPIO;
|
||||||
|
fanState.fanTachGPIO = newFanTachGPIO;
|
||||||
fanState.fanMaxSpeed = newMaxSpeed;
|
fanState.fanMaxSpeed = newMaxSpeed;
|
||||||
fanState.thresLow = newThresLow;
|
fanState.thresLow = newThresLow;
|
||||||
fanState.thresHigh = newThresHigh;
|
fanState.thresHigh = newThresHigh;
|
||||||
|
fanState.OneWireGPIO = newOneWireGPIO;
|
||||||
Serial.println(" ** Fan CONFIG : CHANGED");
|
Serial.println(" ** Fan CONFIG : CHANGED");
|
||||||
return StateUpdateResult::CHANGED;
|
return StateUpdateResult::CHANGED;
|
||||||
}
|
}
|
||||||
|
|||||||
54
src/main.cpp
54
src/main.cpp
@@ -5,39 +5,25 @@
|
|||||||
*/
|
*/
|
||||||
#include <FanStateService.h>
|
#include <FanStateService.h>
|
||||||
|
|
||||||
#define SERIAL_BAUD_RATE 115200
|
#include <OneWire.h>
|
||||||
|
#include <DallasTemperature.h>
|
||||||
|
|
||||||
|
#define ONE_WIRE_BUS 14
|
||||||
|
#define SERIAL_BAUD_RATE 115200
|
||||||
|
#define PWM_PROBE_MS 5000
|
||||||
|
|
||||||
|
OneWire oneWire1(ONE_WIRE_BUS);
|
||||||
|
DallasTemperature sensor_intake(&oneWire1);
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
// ESP8266React esp8266React(&server);
|
|
||||||
/*
|
|
||||||
LightMqttSettingsService lightMqttSettingsService =
|
|
||||||
LightMqttSettingsService(&server, esp8266React.getFS(), esp8266React.getSecurityManager());
|
|
||||||
|
|
||||||
LightStateService lightStateService = LightStateService(&server,
|
|
||||||
esp8266React.getSecurityManager(),
|
|
||||||
esp8266React.getMqttClient(),
|
|
||||||
&lightMqttSettingsService);
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
#ifdef ESP32
|
|
||||||
SPIFFS.begin(true);
|
|
||||||
ESP8266React EMSESP::esp8266React(&server, &LittleFS);
|
|
||||||
FanStateService fanStateService = FanStateService(&server,&SPIFFS,esp8266React.getSecurityManager());
|
|
||||||
#elif defined(ESP8266)
|
|
||||||
LittleFS.begin();
|
|
||||||
ESP8266React EMSESP::esp8266React(&server, &LittleFS);
|
|
||||||
FanStateService fanStateService = FanStateService(&server,&LittleFS,esp8266React.getSecurityManager());
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
ESP8266React esp8266React(&server);
|
ESP8266React esp8266React(&server);
|
||||||
FanStateService fanStateService = FanStateService(&server,esp8266React.getFS(),esp8266React.getSecurityManager());
|
FanStateService fanStateService = FanStateService(&server,esp8266React.getFS(),esp8266React.getSecurityManager());
|
||||||
|
|
||||||
|
|
||||||
struct fanMonitor {
|
struct fanMonitor {
|
||||||
unsigned int rpmcount;
|
unsigned long last_poll;
|
||||||
unsigned int last_time;
|
unsigned int rpmcount;
|
||||||
|
unsigned int last_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
void ICACHE_RAM_ATTR handleInterrupt( struct fanMonitor &fm ) {
|
void ICACHE_RAM_ATTR handleInterrupt( struct fanMonitor &fm ) {
|
||||||
@@ -48,6 +34,8 @@ void ICACHE_RAM_ATTR handleInterrupt( struct fanMonitor &fm ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fanMonitor fm;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// start serial and filesystem
|
// start serial and filesystem
|
||||||
Serial.begin(SERIAL_BAUD_RATE);
|
Serial.begin(SERIAL_BAUD_RATE);
|
||||||
@@ -57,6 +45,9 @@ void setup() {
|
|||||||
|
|
||||||
// load the initial light settings
|
// load the initial light settings
|
||||||
fanStateService.begin();
|
fanStateService.begin();
|
||||||
|
sensor_intake.begin();
|
||||||
|
|
||||||
|
// Serial.println(" FAN GPIO = " + fanStateService.fan);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// start the light service
|
// start the light service
|
||||||
@@ -66,6 +57,8 @@ void setup() {
|
|||||||
// start the server
|
// start the server
|
||||||
server.begin();
|
server.begin();
|
||||||
|
|
||||||
|
fm.last_poll=millis();
|
||||||
|
|
||||||
pinMode(14,INPUT); // 14 = D5
|
pinMode(14,INPUT); // 14 = D5
|
||||||
// attachInterrupt(digitalPinToInterrupt(14), handleInterrupt, RISING);
|
// attachInterrupt(digitalPinToInterrupt(14), handleInterrupt, RISING);
|
||||||
// attachInterrupt(14,handleInterrupt,RISING);
|
// attachInterrupt(14,handleInterrupt,RISING);
|
||||||
@@ -76,5 +69,16 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// run the framework's loop function
|
// run the framework's loop function
|
||||||
|
|
||||||
|
if( ( millis() - fm.last_poll ) > PWM_PROBE_MS ) {
|
||||||
|
fm.last_poll = millis();
|
||||||
|
Serial.print((String) fm.last_poll + " - Compute");
|
||||||
|
sensor_intake.requestTemperatures();
|
||||||
|
float T1 = sensor_intake.getTempCByIndex(0);
|
||||||
|
float T2 = sensor_intake.getTempCByIndex(1);
|
||||||
|
Serial.print("Intake: " + (String) T1 + " - " + (String) T2 + "\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
esp8266React.loop();
|
esp8266React.loop();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user