Browse Source

Further renaming

fastled
Xose Pérez 7 years ago
parent
commit
227c4b03f1
7 changed files with 150 additions and 97 deletions
  1. +46
    -17
      code/espurna/config/general.h
  2. +80
    -56
      code/espurna/config/sensors.h
  3. +5
    -5
      code/espurna/ds18b20.ino
  4. +2
    -2
      code/espurna/espurna.ino
  5. +5
    -5
      code/espurna/led.ino
  6. +10
    -10
      code/espurna/web.ino
  7. +2
    -2
      code/espurna/wifi.ino

+ 46
- 17
code/espurna/config/general.h View File

@ -3,6 +3,12 @@
// Configuration settings are in the settings.h file
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// GENERAL
//------------------------------------------------------------------------------
#define ADMIN_PASS "fibonacci" // Default password (WEB, OTA, WIFI)
//------------------------------------------------------------------------------
// DEBUG
//------------------------------------------------------------------------------
@ -208,38 +214,55 @@ PROGMEM const char* const custom_reset_string[] = {
#define LED_AUTO 1
// LED # to use as WIFI status indicator
#ifndef WIFI_LED
#define WIFI_LED 1
#ifndef LED_WIFI
#define LED_WIFI 1
#endif
// -----------------------------------------------------------------------------
// WIFI & WEB
// WIFI
// -----------------------------------------------------------------------------
#define WIFI_CONNECT_TIMEOUT 30000 // Connecting timeout for WIFI in ms
#define WIFI_RECONNECT_INTERVAL 120000 // If could not connect to WIFI, retry after this time in ms
#define WIFI_MAX_NETWORKS 5 // Max number of WIFI connection configurations
#define HTTP_USERNAME "admin" // HTTP username
#define ADMIN_PASS "fibonacci" // Default password
#define FORCE_CHANGE_PASS 1 // Force the user to change the password if default one
#define WS_BUFFER_SIZE 5 // Max number of secured websocket connections
#define WS_TIMEOUT 1800000 // Timeout for secured websocket
#define WEBSERVER_PORT 80 // HTTP port
#define DNS_PORT 53 // MDNS port
#define MDNS_SUPPORT 1 // Enable MDNS by default
#define ENABLE_API 0 // Do not enable API by default
#define API_BUFFER_SIZE 10 // Size of the buffer for HTTP GET API responses
#define WIFI_AP_MODE AP_MODE_ALONE
// -----------------------------------------------------------------------------
// WEB
// -----------------------------------------------------------------------------
#define WEB_MODE_NORMAL 0
#define WEB_MODE_PASSWORD 1
#define AP_MODE AP_MODE_ALONE
#define WEB_USERNAME "admin" // HTTP username
#define WEB_FORCE_PASS_CHANGE 1 // Force the user to change the password if default one
#define WEB_PORT 80 // HTTP port
// This option builds the firmware with the web interface embedded.
#ifndef EMBEDDED_WEB
#define EMBEDDED_WEB 1
#ifndef WEB_EMBEDDED
#define WEB_EMBEDDED 1
#endif
// -----------------------------------------------------------------------------
// WEBSOCKETS
// -----------------------------------------------------------------------------
#define WS_BUFFER_SIZE 5 // Max number of secured websocket connections
#define WS_TIMEOUT 1800000 // Timeout for secured websocket
// -----------------------------------------------------------------------------
// API
// -----------------------------------------------------------------------------
#define API_ENABLED 0 // Do not enable API by default
#define API_BUFFER_SIZE 10 // Size of the buffer for HTTP GET API responses
// -----------------------------------------------------------------------------
// MDNS
// -----------------------------------------------------------------------------
#define MDNS_SUPPORT 1 // Enable MDNS by default
// -----------------------------------------------------------------------------
// SPIFFS
// -----------------------------------------------------------------------------
@ -250,10 +273,15 @@ PROGMEM const char* const custom_reset_string[] = {
#endif
// -----------------------------------------------------------------------------
// OTA & NOFUSS
// OTA
// -----------------------------------------------------------------------------
#define OTA_PORT 8266 // OTA port
// -----------------------------------------------------------------------------
// NOFUSS
// -----------------------------------------------------------------------------
#define NOFUSS_SERVER "" // Default NoFuss Server
#define NOFUSS_INTERVAL 3600000 // Check for updates every hour
@ -322,6 +350,7 @@ PROGMEM const char* const custom_reset_string[] = {
// Custom get and set postfixes
// Use something like "/status" or "/set", with leading slash
// Since 1.9.0 the default value is "" for getter and "/set" for setter
#define MQTT_USE_GETTER ""
#define MQTT_USE_SETTER "/set"


+ 80
- 56
code/espurna/config/sensors.h View File

@ -4,39 +4,51 @@
// Enable support by passing RF_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
#define RF_PIN 14
#define RF_CHANNEL 31
#define RF_DEVICE 1
#ifndef RF_SUPPORT
#define RF_SUPPORT 0
#endif
#define RF_PIN 14
#define RF_CHANNEL 31
#define RF_DEVICE 1
//--------------------------------------------------------------------------------
// DHTXX temperature/humidity sensor
// Enable support by passing DHT_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
#define DHT_PIN 14
#define DHT_UPDATE_INTERVAL 60000
#define DHT_TYPE DHT22
#define DHT_TIMING 11
#define DHT_TEMPERATURE_TOPIC "temperature"
#define DHT_HUMIDITY_TOPIC "humidity"
#ifndef DHT_SUPPORT
#define DHT_SUPPORT 0
#endif
#define DHT_PIN 14
#define DHT_UPDATE_INTERVAL 60000
#define DHT_TYPE DHT22
#define DHT_TIMING 11
#define DHT_TEMPERATURE_TOPIC "temperature"
#define DHT_HUMIDITY_TOPIC "humidity"
#define HUMIDITY_NORMAL 0
#define HUMIDITY_COMFORTABLE 1
#define HUMIDITY_DRY 2
#define HUMIDITY_WET 3
#define HUMIDITY_NORMAL 0
#define HUMIDITY_COMFORTABLE 1
#define HUMIDITY_DRY 2
#define HUMIDITY_WET 3
//--------------------------------------------------------------------------------
// Analog sensor
// Enable support by passing ANALOG_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
#define ANALOG_PIN 0
#define ANALOG_UPDATE_INTERVAL 60000
#define ANALOG_TOPIC "analog"
#ifndef ANALOG_SUPPORT
#define ANALOG_SUPPORT 0
#endif
#define ANALOG_PIN 0
#define ANALOG_UPDATE_INTERVAL 60000
#define ANALOG_TOPIC "analog"
#if ANALOG_SUPPORT
#undef ENABLE_ADC_VCC
#define ENABLE_ADC_VCC 0
#undef ADC_VCC_ENABLED
#define ADC_VCC_ENABLED 0
#endif
//--------------------------------------------------------------------------------
@ -44,9 +56,13 @@
// Enable support by passing DS18B20_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
#define DS_PIN 14
#define DS_UPDATE_INTERVAL 60000
#define DS_TEMPERATURE_TOPIC "temperature"
#ifndef DS18B20_SUPPORT
#define DS18B20_SUPPORT 0
#endif
#define DS18B20_PIN 14
#define DS18B20_UPDATE_INTERVAL 60000
#define DS18B20_TEMPERATURE_TOPIC "temperature"
//--------------------------------------------------------------------------------
// Custom current sensor
@ -55,11 +71,15 @@
// Enable support by passing EMON_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
#define EMON_ANALOG_PROVIDER 0
#define EMON_ADC121_PROVIDER 1
#ifndef EMON_SUPPORT
#define EMON_SUPPORT 0
#endif
#define EMON_ANALOG_PROVIDER 0
#define EMON_ADC121_PROVIDER 1
// If you select EMON_ADC121_PROVIDER you need to enable and configure I2C in general.h
#define EMON_PROVIDER EMON_ANALOG_PROVIDER
#define EMON_PROVIDER EMON_ANALOG_PROVIDER
#if EMON_PROVIDER == EMON_ANALOG_PROVIDER
#define EMON_CURRENT_PIN 0
@ -68,8 +88,8 @@
#define EMON_CURRENT_PRECISION 1
#define EMON_CURRENT_OFFSET 0.25
#if EMON_SUPPORT
#undef ENABLE_ADC_VCC
#define ENABLE_ADC_VCC 0
#undef ADC_VCC_ENABLED
#define ADC_VCC_ENABLED 0
#endif
#endif
@ -81,51 +101,55 @@
#define EMON_CURRENT_OFFSET 0.10
#endif
#define EMON_CURRENT_RATIO 30
#define EMON_SAMPLES 1000
#define EMON_INTERVAL 10000
#define EMON_MEASUREMENTS 6
#define EMON_MAINS_VOLTAGE 230
#define EMON_APOWER_TOPIC "apower"
#define EMON_ENERGY_TOPIC "energy"
#define EMON_CURRENT_TOPIC "current"
#define EMON_CURRENT_RATIO 30
#define EMON_SAMPLES 1000
#define EMON_INTERVAL 10000
#define EMON_MEASUREMENTS 6
#define EMON_MAINS_VOLTAGE 230
#define EMON_APOWER_TOPIC "apower"
#define EMON_ENERGY_TOPIC "energy"
#define EMON_CURRENT_TOPIC "current"
//--------------------------------------------------------------------------------
// HLW8012 power sensor (Sonoff POW, Espurna H)
// Enable support by passing HLW8012_SUPPORT=1 build flag
//--------------------------------------------------------------------------------
#ifndef HLW8012_SUPPORT
#define HLW8012_SUPPORT 0
#endif
// GPIOs defined in the hardware.h file
#define HLW8012_USE_INTERRUPTS 1
#define HLW8012_SEL_CURRENT HIGH
#define HLW8012_CURRENT_R 0.001
#define HLW8012_VOLTAGE_R_UP ( 5 * 470000 ) // Real: 2280k
#define HLW8012_VOLTAGE_R_DOWN ( 1000 ) // Real 1.009k
#define HLW8012_POWER_TOPIC "power"
#define HLW8012_CURRENT_TOPIC "current"
#define HLW8012_VOLTAGE_TOPIC "voltage"
#define HLW8012_APOWER_TOPIC "apower"
#define HLW8012_RPOWER_TOPIC "rpower"
#define HLW8012_PFACTOR_TOPIC "pfactor"
#define HLW8012_ENERGY_TOPIC "energy"
#define HLW8012_UPDATE_INTERVAL 5000
#define HLW8012_REPORT_EVERY 12
#define HLW8012_MIN_POWER 5
#define HLW8012_MAX_POWER 2500
#define HLW8012_MIN_CURRENT 0.05
#define HLW8012_MAX_CURRENT 10
#define HLW8012_USE_INTERRUPTS 1
#define HLW8012_SEL_CURRENT HIGH
#define HLW8012_CURRENT_R 0.001
#define HLW8012_VOLTAGE_R_UP ( 5 * 470000 ) // Real: 2280k
#define HLW8012_VOLTAGE_R_DOWN ( 1000 ) // Real 1.009k
#define HLW8012_POWER_TOPIC "power"
#define HLW8012_CURRENT_TOPIC "current"
#define HLW8012_VOLTAGE_TOPIC "voltage"
#define HLW8012_APOWER_TOPIC "apower"
#define HLW8012_RPOWER_TOPIC "rpower"
#define HLW8012_PFACTOR_TOPIC "pfactor"
#define HLW8012_ENERGY_TOPIC "energy"
#define HLW8012_UPDATE_INTERVAL 5000
#define HLW8012_REPORT_EVERY 12
#define HLW8012_MIN_POWER 5
#define HLW8012_MAX_POWER 2500
#define HLW8012_MIN_CURRENT 0.05
#define HLW8012_MAX_CURRENT 10
//--------------------------------------------------------------------------------
// Internal power montior
// Enable support by passing ENABLE_ADC_VCC=1 build flag
// Enable support by passing ADC_VCC_ENABLED=1 build flag
// Do not enable this if using the analog GPIO for any other thing
//--------------------------------------------------------------------------------
#ifndef ENABLE_ADC_VCC
#define ENABLE_ADC_VCC 1
#ifndef ADC_VCC_ENABLED
#define ADC_VCC_ENABLED 1
#endif
#if ENABLE_ADC_VCC
#if ADC_VCC_ENABLED
ADC_MODE(ADC_VCC);
#endif

+ 5
- 5
code/espurna/ds18b20.ino View File

@ -11,7 +11,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(DS_PIN);
OneWire oneWire(DS18B20_PIN);
DallasTemperature ds18b20(&oneWire);
bool _dsIsConnected = false;
@ -37,7 +37,7 @@ void dsSetup() {
ds18b20.begin();
ds18b20.setWaitForConversion(false);
apiRegister(DS_TEMPERATURE_TOPIC, DS_TEMPERATURE_TOPIC, [](char * buffer, size_t len) {
apiRegister(DS18B20_TEMPERATURE_TOPIC, DS18B20_TEMPERATURE_TOPIC, [](char * buffer, size_t len) {
dtostrf(_dsTemperature, len-1, 1, buffer);
});
}
@ -47,7 +47,7 @@ void dsLoop() {
// Check if we should read new data
static unsigned long last_update = 0;
static bool requested = false;
if ((millis() - last_update > DS_UPDATE_INTERVAL) || (last_update == 0)) {
if ((millis() - last_update > DS18B20_UPDATE_INTERVAL) || (last_update == 0)) {
if (!requested) {
ds18b20.requestTemperatures();
requested = true;
@ -92,7 +92,7 @@ void dsLoop() {
(_dsIsConnected ? ((tmpUnits == TMP_CELSIUS) ? "ºC" : "ºF") : ""));
// Send MQTT messages
mqttSend(getSetting("dsTmpTopic", DS_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr);
mqttSend(getSetting("dsTmpTopic", DS18B20_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr);
// Send to Domoticz
#if DOMOTICZ_SUPPORT
@ -100,7 +100,7 @@ void dsLoop() {
#endif
#if INFLUXDB_SUPPORT
influxDBSend(getSetting("dsTmpTopic", DS_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr);
influxDBSend(getSetting("dsTmpTopic", DS18B20_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr);
#endif
// Update websocket clients


+ 2
- 2
code/espurna/espurna.ino View File

@ -46,7 +46,7 @@ void heartbeat() {
if (!mqttConnected()) {
DEBUG_MSG_P(PSTR("[MAIN] Uptime: %ld seconds\n"), uptime_seconds);
DEBUG_MSG_P(PSTR("[MAIN] Free heap: %d bytes\n"), free_heap);
#if ENABLE_ADC_VCC
#if ADC_VCC_ENABLED
DEBUG_MSG_P(PSTR("[MAIN] Power: %d mV\n"), ESP.getVcc());
#endif
}
@ -92,7 +92,7 @@ void heartbeat() {
lightMQTT();
#endif
#if (HEARTBEAT_REPORT_VCC)
#if ENABLE_ADC_VCC
#if ADC_VCC_ENABLED
mqttSend(MQTT_TOPIC_VCC, String(ESP.getVcc()).c_str());
#endif
#endif


+ 5
- 5
code/espurna/led.ino View File

@ -44,16 +44,16 @@ void ledBlink(unsigned char id, unsigned long delayOff, unsigned long delayOn) {
}
}
#if WIFI_LED
#if LED_WIFI
void showStatus() {
if (wifiConnected()) {
if (WiFi.getMode() == WIFI_AP) {
ledBlink(WIFI_LED - 1, 2500, 2500);
ledBlink(LED_WIFI - 1, 2500, 2500);
} else {
ledBlink(WIFI_LED - 1, 4900, 100);
ledBlink(LED_WIFI - 1, 4900, 100);
}
} else {
ledBlink(WIFI_LED - 1, 500, 500);
ledBlink(LED_WIFI - 1, 500, 500);
}
}
#endif
@ -138,7 +138,7 @@ void ledSetup() {
}
void ledLoop() {
#if WIFI_LED
#if LED_WIFI
if (ledAuto) showStatus();
#endif
}

+ 10
- 10
code/espurna/web.ino View File

@ -16,7 +16,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
#include <Ticker.h>
#include <vector>
#if EMBEDDED_WEB
#if WEB_EMBEDDED
#include "static/index.html.gz.h"
#endif
@ -397,7 +397,7 @@ void _wsStart(uint32_t client_id) {
JsonObject& root = jsonBuffer.createObject();
bool changePassword = false;
#if FORCE_CHANGE_PASS == 1
#if WEB_PASS_CHANGE == 1
String adminPass = getSetting("adminPass", ADMIN_PASS);
if (adminPass.equals(ADMIN_PASS)) changePassword = true;
#endif
@ -468,9 +468,9 @@ void _wsStart(uint32_t client_id) {
root["btnDelay"] = getSetting("btnDelay", BUTTON_DBLCLICK_DELAY).toInt();
root["webPort"] = getSetting("webPort", WEBSERVER_PORT).toInt();
root["webPort"] = getSetting("webPort", WEB_PORT).toInt();
root["apiEnabled"] = getSetting("apiEnabled", ENABLE_API).toInt() == 1;
root["apiEnabled"] = getSetting("apiEnabled", API_ENABLED).toInt() == 1;
root["apiKey"] = getSetting("apiKey");
root["tmpUnits"] = getSetting("tmpUnits", TMP_UNITS).toInt();
@ -677,12 +677,12 @@ bool _authenticate(AsyncWebServerRequest *request) {
String password = getSetting("adminPass", ADMIN_PASS);
char httpPassword[password.length() + 1];
password.toCharArray(httpPassword, password.length() + 1);
return request->authenticate(HTTP_USERNAME, httpPassword);
return request->authenticate(WEB_USERNAME, httpPassword);
}
bool _authAPI(AsyncWebServerRequest *request) {
if (getSetting("apiEnabled", ENABLE_API).toInt() == 0) {
if (getSetting("apiEnabled", API_ENABLED).toInt() == 0) {
DEBUG_MSG_P(PSTR("[WEBSERVER] HTTP API is not enabled\n"));
request->send(403);
return false;
@ -881,7 +881,7 @@ void _onGetConfig(AsyncWebServerRequest *request) {
}
#if EMBEDDED_WEB
#if WEB_EMBEDDED
void _onHome(AsyncWebServerRequest *request) {
webLogRequest(request);
@ -947,7 +947,7 @@ void _onUpgradeData(AsyncWebServerRequest *request, String filename, size_t inde
void webSetup() {
// Create server
_server = new AsyncWebServer(getSetting("webPort", WEBSERVER_PORT).toInt());
_server = new AsyncWebServer(getSetting("webPort", WEB_PORT).toInt());
// Setup websocket
ws.onEvent(_wsEvent);
@ -963,7 +963,7 @@ void webSetup() {
_server->rewrite("/", "/index.html");
// Serve home (basic authentication protection)
#if EMBEDDED_WEB
#if WEB_EMBEDDED
_server->on("/index.html", HTTP_GET, _onHome);
#endif
_server->on("/config", HTTP_GET, _onGetConfig);
@ -989,6 +989,6 @@ void webSetup() {
// Run server
_server->begin();
DEBUG_MSG_P(PSTR("[WEBSERVER] Webserver running on port %d\n"), getSetting("webPort", WEBSERVER_PORT).toInt());
DEBUG_MSG_P(PSTR("[WEBSERVER] Webserver running on port %d\n"), getSetting("webPort", WEB_PORT).toInt());
}

+ 2
- 2
code/espurna/wifi.ino View File

@ -53,7 +53,7 @@ void wifiConfigure() {
jw.setSoftAP(getSetting("hostname").c_str(), getSetting("adminPass", ADMIN_PASS).c_str());
jw.setConnectTimeout(WIFI_CONNECT_TIMEOUT);
jw.setReconnectTimeout(WIFI_RECONNECT_INTERVAL);
jw.setAPMode(AP_MODE);
jw.setAPMode(WIFI_AP_MODE);
jw.cleanNetworks();
int i;
@ -182,7 +182,7 @@ void wifiSetup() {
#if MDNS_SUPPORT
if (code == MESSAGE_CONNECTED || code == MESSAGE_ACCESSPOINT_CREATED) {
if (MDNS.begin(WiFi.getMode() == WIFI_AP ? APP_NAME : (char *) WiFi.hostname().c_str())) {
MDNS.addService("http", "tcp", getSetting("webPort", WEBSERVER_PORT).toInt());
MDNS.addService("http", "tcp", getSetting("webPort", WEB_PORT).toInt());
DEBUG_MSG_P(PSTR("[MDNS] OK\n"));
} else {
DEBUG_MSG_P(PSTR("[MDNS] FAIL\n"));


Loading…
Cancel
Save