Browse Source

Merge branch 'dev' of https://github.com/xoseperez/espurna into CCT_Support

rfm69
Niklas Wagner 6 years ago
parent
commit
6524a8d8fc
28 changed files with 1014 additions and 730 deletions
  1. +1
    -1
      README.md
  2. +2
    -1
      code/build.sh
  3. +2
    -2
      code/espurna/api.ino
  4. +1
    -0
      code/espurna/button.ino
  5. +5
    -0
      code/espurna/config/arduino.h
  6. +7
    -1
      code/espurna/config/general.h
  7. +83
    -10
      code/espurna/config/hardware.h
  8. +2
    -1
      code/espurna/config/prototypes.h
  9. +61
    -38
      code/espurna/config/sensors.h
  10. BIN
      code/espurna/data/index.html.gz
  11. +13
    -1
      code/espurna/debug.ino
  12. +6
    -1
      code/espurna/espurna.ino
  13. +47
    -27
      code/espurna/libs/StreamInjector.h
  14. +1
    -1
      code/espurna/libs/WebSocketIncommingBuffer.h
  15. +17
    -0
      code/espurna/migrate.ino
  16. +1
    -1
      code/espurna/scheduler.ino
  17. +21
    -19
      code/espurna/sensor.ino
  18. +5
    -3
      code/espurna/sensors/AM2320Sensor.h
  19. +1
    -1
      code/espurna/sensors/GUVAS12SDSensor.h
  20. +21
    -24
      code/espurna/settings.ino
  21. +524
    -523
      code/espurna/static/index.html.gz.h
  22. +0
    -7
      code/espurna/system.ino
  23. +5
    -1
      code/espurna/thinkspeak.ino
  24. +6
    -0
      code/espurna/utils.ino
  25. +30
    -0
      code/espurna/wifi.ino
  26. +4
    -2
      code/html/custom.js
  27. +43
    -6
      code/platformio.ini
  28. +105
    -59
      pre-commit

+ 1
- 1
README.md View File

@ -4,7 +4,7 @@ ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smar
It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries.
[![version](https://img.shields.io/badge/version-1.12.6a-brightgreen.svg)](CHANGELOG.md)
![branch](https://img.shields.io/badge/branch-dev-orange.svg)
[![branch](https://img.shields.io/badge/branch-dev-orange.svg)](https://github.org/xoseperez/espurna/tree/dev/)
[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna)
[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/dev.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard)
[![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE)


+ 2
- 1
code/build.sh View File

@ -26,7 +26,8 @@ if [ $# -eq 0 ]; then
# Hook to build travis test envs
if [[ "${TRAVIS_BRANCH}" != "" ]]; then
if [[ ${TRAVIS_BRANCH} != "master" ]]; then
re='^[0-9]+\.[0-9]+\.[0-9]+$'
if ! [[ ${TRAVIS_BRANCH} =~ $re ]]; then
environments=$travis
fi
fi


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

@ -88,11 +88,11 @@ ArRequestHandlerFunction _bindAPI(unsigned int apiID) {
}
// Get response from callback
char value[API_BUFFER_SIZE];
char value[API_BUFFER_SIZE] = {0};
(api.getFn)(value, API_BUFFER_SIZE);
// The response will be a 404 NOT FOUND if the resource is not available
if (!value) {
if (0 == value[0]) {
DEBUG_MSG_P(PSTR("[API] Sending 404 response\n"));
request->send(404);
return;


+ 1
- 0
code/espurna/button.ino View File

@ -84,6 +84,7 @@ uint8_t mapEvent(uint8_t event, uint8_t count, uint16_t length) {
}
if (count == 2) return BUTTON_EVENT_DBLCLICK;
}
return BUTTON_EVENT_NONE;
}
void buttonEvent(unsigned int id, unsigned char event) {


+ 5
- 0
code/espurna/config/arduino.h View File

@ -77,6 +77,7 @@
//#define GENERIC_ESP01S_DHT11_V10
//#define GENERIC_ESP01S_DS18B20_V10
//#define HELTEC_TOUCHRELAY
//#define ZHILDE_EU44_W
//--------------------------------------------------------------------------------
// Features (values below are non-default values)
@ -87,6 +88,7 @@
//#define DEBUG_SERIAL_SUPPORT 0
//#define DEBUG_TELNET_SUPPORT 0
//#define DEBUG_UDP_SUPPORT 1
//#define DEBUG_WEB_SUPPORT 0
//#define DOMOTICZ_SUPPORT 0
//#define HOMEASSISTANT_SUPPORT 0
//#define I2C_SUPPORT 1
@ -117,6 +119,7 @@
//#define ANALOG_SUPPORT 1
//#define BH1750_SUPPORT 1
//#define BMX280_SUPPORT 1
//#define CSE7766_SUPPORT 1
//#define DALLAS_SUPPORT 1
//#define DHT_SUPPORT 1
//#define DIGITAL_SUPPORT 1
@ -126,10 +129,12 @@
//#define EMON_ANALOG_SUPPORT 1
//#define EVENTS_SUPPORT 1
//#define GUVAS12SD_SUPPORT 1
//#define HCSR04_SUPPORT 1
//#define HLW8012_SUPPORT 1
//#define MHZ19_SUPPORT 1
//#define PMSX003_SUPPORT 1
//#define PZEM004T_SUPPORT 1
//#define SHT3X_I2C_SUPPORT 1
//#define SI7021_SUPPORT 1
//#define TMP3X_SUPPORT 1
//#define V9261F_SUPPORT 1

+ 7
- 1
code/espurna/config/general.h View File

@ -78,7 +78,7 @@
#define DEBUG_UDP_PORT 514
#endif
// If DEBUG_UDP_PORT is set to 514 syslog format is assumed
// If DEBUG_UDP_PORT is set to 514 syslog format is assumed
// (https://tools.ietf.org/html/rfc3164)
// DEBUG_UDP_FAC_PRI is the facility+priority
#define DEBUG_UDP_FAC_PRI (SYSLOG_LOCAL0 | SYSLOG_DEBUG)
@ -268,7 +268,13 @@
#define WIFI_RECONNECT_INTERVAL 180000 // If could not connect to WIFI, retry after this time in ms
#endif
#ifndef WIFI_MAX_NETWORKS
#define WIFI_MAX_NETWORKS 5 // Max number of WIFI connection configurations
#endif
#ifndef WIFI_AP_CAPTIVE
#define WIFI_AP_CAPTIVE 1 // Captive portal enabled when in AP mode
#endif
#ifndef WIFI_AP_MODE
#define WIFI_AP_MODE AP_MODE_ALONE


+ 83
- 10
code/espurna/config/hardware.h View File

@ -388,7 +388,6 @@
#define RELAY_PROVIDER RELAY_PROVIDER_DUAL
#define DUMMY_RELAY_COUNT 2
#define DEBUG_SERIAL_SUPPORT 0
#define TERMINAL_SUPPORT 0
// Buttons
#define BUTTON3_RELAY 1
@ -608,7 +607,6 @@
#endif
// Remove UART noise on serial line
#define TERMINAL_SUPPORT 0
#define DEBUG_SERIAL_SUPPORT 0
// Buttons
@ -789,7 +787,6 @@
#define LED1_PIN_INVERSE 1
// Disable UART noise
#define TERMINAL_SUPPORT 0
#define DEBUG_SERIAL_SUPPORT 0
// CSE7766
@ -1552,10 +1549,8 @@
#define RELAY_PROVIDER RELAY_PROVIDER_STM
// Remove UART noise on serial line
#define TERMINAL_SUPPORT 0
#define DEBUG_SERIAL_SUPPORT 0
#define SERIAL_BAUDRATE 115200
// -----------------------------------------------------------------------------
// Tonbux Powerstrip02
// -----------------------------------------------------------------------------
@ -1921,6 +1916,42 @@
#define RELAY1_PIN 12
#define RELAY1_TYPE RELAY_TYPE_NORMAL
// -----------------------------------------------------------------------------
// Zhilde ZLD-EU44-W
// http://www.zhilde.com/product/60705150109-805652505/EU_WiFi_Surge_Protector_Extension_Socket_4_Outlets_works_with_Amazon_Echo_Smart_Power_Strip.html
// -----------------------------------------------------------------------------
#elif defined(ZHILDE_EU44_W)
// Info
#define MANUFACTURER "ZHILDE"
#define DEVICE "EU44_W"
// Based on the reporter, this product uses GPIO1 and 3 for the button
// and onboard LED, so hardware serial should be disabled...
#define DEBUG_SERIAL_SUPPORT 0
// Buttons
#define BUTTON1_PIN 3
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
// Relays
#define RELAY1_PIN 5
#define RELAY2_PIN 4
#define RELAY3_PIN 12
#define RELAY4_PIN 13
#define RELAY5_PIN 14
#define RELAY1_TYPE RELAY_TYPE_NORMAL
#define RELAY2_TYPE RELAY_TYPE_NORMAL
#define RELAY3_TYPE RELAY_TYPE_NORMAL
#define RELAY4_TYPE RELAY_TYPE_NORMAL
#define RELAY5_TYPE RELAY_TYPE_NORMAL
// LEDs
#define LED1_PIN 1
#define LED1_PIN_INVERSE 1
// -----------------------------------------------------------------------------
// TEST boards (do not use!!)
// -----------------------------------------------------------------------------
@ -1955,6 +1986,7 @@
// We got silk sensor, velvet sensor, naugahyde sensor. We even got horse sensor, dog sensor, chicken sensor.
// C'mon, you want sensor, come on in sensor lovers!
// If we dont got it, you don't want it!
#define AM2320_SUPPORT 1
#define BH1750_SUPPORT 1
#define BMX280_SUPPORT 1
#define SHT3X_I2C_SUPPORT 1
@ -2000,11 +2032,11 @@
#define MANUFACTURER "TravisCI"
#define DEVICE "Virtual board 02"
// A bit of DHT - pin 1
#ifndef DHT_SUPPORT
#define DHT_SUPPORT 1
// A bit of CSE7766 - pin 1
#ifndef CSE7766_SUPPORT
#define CSE7766_SUPPORT 1
#endif
#define DHT_PIN 1
#define CSE7766_PIN 1
// Relay type dual - pins 2,3
#define RELAY_PROVIDER RELAY_PROVIDER_DUAL
@ -2018,6 +2050,42 @@
#define IR_PIN 4
#define IR_BUTTON_SET 1
// A bit of DHT - pin 5
#ifndef DHT_SUPPORT
#define DHT_SUPPORT 1
#endif
#define DHT_PIN 5
// A bit of TMP3X (analog)
#define TMP3X_SUPPORT 1
// A bit of EVENTS - pin 10
#define EVENTS_SUPPORT 1
#define EVENTS_PIN 6
// HC-RS04
#define HCSR04_SUPPORT 1
#define HCSR04_TRIGGER 7
#define HCSR04_ECHO 8
// MHZ19
#define MHZ19_SUPPORT 1
#define MHZ19_RX_PIN 9
#define MHZ19_TX_PIN 10
// PZEM004T
#define PZEM004T_SUPPORT 0 // not working?
#define PZEM004T_RX_PIN 11
#define PZEM004T_TX_PIN 12
// V9261F
#define V9261F_SUPPORT 1
#define V9261F_PIN 13
// GUVAS12SD
#define GUVAS12SD_SUPPORT 1
#define GUVAS12SD_PIN 14
#elif defined(TRAVIS03)
// Relay provider light/my92XX
@ -2036,6 +2104,11 @@
#define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT
#define MY92XX_MAPPING 4, 3, 5, 0, 1
// A bit of Analog EMON (analog)
#ifndef EMON_ANALOG_SUPPORT
#define EMON_ANALOG_SUPPORT 1
#endif
#endif
// -----------------------------------------------------------------------------


+ 2
- 1
code/espurna/config/prototypes.h View File

@ -63,7 +63,7 @@ template<typename T> bool setSetting(const String& key, T value);
template<typename T> bool setSetting(const String& key, unsigned int index, T value);
template<typename T> String getSetting(const String& key, T defaultValue);
template<typename T> String getSetting(const String& key, unsigned int index, T defaultValue);
bool settingsGetJson(JsonObject& data);
void settingsGetJson(JsonObject& data);
bool settingsRestoreJson(JsonObject& data);
void settingsRegisterCommand(const String& name, void (*call)(Embedis*));
void settingsInject(void *data, size_t len);
@ -77,6 +77,7 @@ bool i2cGetLock(unsigned char address);
bool i2cReleaseLock(unsigned char address);
unsigned char i2cFindAndLock(size_t size, unsigned char * addresses);
void i2c_wakeup(uint8_t address);
uint8_t i2c_write_buffer(uint8_t address, uint8_t * buffer, size_t len);
uint8_t i2c_write_uint8(uint8_t address, uint8_t value);
uint8_t i2c_write_uint8(uint8_t address, uint8_t reg, uint8_t value);


+ 61
- 38
code/espurna/config/sensors.h View File

@ -57,6 +57,19 @@
// Specific data for each sensor
// =============================================================================
//------------------------------------------------------------------------------
// AM2320 Humidity & Temperature sensor over I2C
// Enable support by passing AM2320_SUPPORT=1 build flag
//------------------------------------------------------------------------------
#ifndef AM2320_SUPPORT
#define AM2320_SUPPORT 0
#endif
#ifndef AM2320_ADDRESS
#define AM2320_ADDRESS 0x00 // 0x00 means auto
#endif
//------------------------------------------------------------------------------
// Analog sensor
// Enable support by passing ANALOG_SUPPORT=1 build flag
@ -274,6 +287,19 @@
#define EVENTS_DEBOUNCE 50 // Do not register events within less than 10 millis
//------------------------------------------------------------------------------
// GUVAS12SD UV Sensor (analog)
// Enable support by passing GUVAS12SD_SUPPORT=1 build flag
//------------------------------------------------------------------------------
#ifndef GUVAS12SD_SUPPORT
#define GUVAS12SD_SUPPORT 0
#endif
#ifndef GUVAS12SD_PIN
#define GUVAS12SD_PIN 14
#endif
//------------------------------------------------------------------------------
// HC-SR04
// Enable support by passing HCSR04_SUPPORT=1 build flag
@ -339,8 +365,13 @@
#define MHZ19_SUPPORT 0
#endif
#ifndef MHZ19_RX_PIN
#define MHZ19_RX_PIN 13
#endif
#ifndef MHZ19_TX_PIN
#define MHZ19_TX_PIN 15
#endif
//------------------------------------------------------------------------------
// Particle Monitor based on Plantower PMSX003
@ -351,8 +382,13 @@
#define PMSX003_SUPPORT 0
#endif
#ifndef PMS_RX_PIN
#define PMS_RX_PIN 13
#endif
#ifndef PMS_TX_PIN
#define PMS_TX_PIN 15
#endif
//------------------------------------------------------------------------------
// PZEM004T based power monitor
@ -444,49 +480,36 @@
#define V9261F_POWER_FACTOR 153699.0
#define V9261F_RPOWER_FACTOR V9261F_CURRENT_FACTOR
//------------------------------------------------------------------------------
// AM2320 Humidity & Temperature sensor over I2C
// Enable support by passing AM2320_SUPPORT=1 build flag
//------------------------------------------------------------------------------
#ifndef AM2320_SUPPORT
#define AM2320_SUPPORT 0
#endif
#ifndef AM2320_ADDRESS
#define AM2320_ADDRESS 0x00 // 0x00 means auto
#endif
//------------------------------------------------------------------------------
// GUVAS12SD UV Sensor (analog)
// Enable support by passing GUVAS12SD_SUPPORT=1 build flag
//------------------------------------------------------------------------------
#ifndef GUVAS12SD_SUPPORT
#define GUVAS12SD_SUPPORT 0
#endif
#ifndef GUVAS12SD_PIN
#define GUVAS12SD_PIN 14
#endif
// =============================================================================
// Sensor helpers configuration - can't move to dependencies.h
// =============================================================================
#ifndef SENSOR_SUPPORT
#if ANALOG_SUPPORT || BH1750_SUPPORT || BMX280_SUPPORT || DALLAS_SUPPORT \
|| DHT_SUPPORT || DIGITAL_SUPPORT || ECH1560_SUPPORT \
|| EMON_ADC121_SUPPORT || EMON_ADS1X15_SUPPORT \
|| EMON_ANALOG_SUPPORT || EVENTS_SUPPORT || HLW8012_SUPPORT \
|| MHZ19_SUPPORT || PMSX003_SUPPORT || SHT3X_I2C_SUPPORT \
|| SI7021_SUPPORT || V9261F_SUPPORT || AM2320_SUPPORT \
|| GUVAS12SD_SUPPORT || CSE7766_SUPPORT || TMP3X_SUPPORT \
|| HCSR04_SUPPORT
#define SENSOR_SUPPORT 1
#else
#define SENSOR_SUPPORT 0
#endif
#define SENSOR_SUPPORT ( \
AM2320_SUPPORT || \
ANALOG_SUPPORT || \
BH1750_SUPPORT || \
BMX280_SUPPORT || \
CSE7766_SUPPORT || \
DALLAS_SUPPORT || \
DHT_SUPPORT || \
DIGITAL_SUPPORT || \
ECH1560_SUPPORT || \
EMON_ADC121_SUPPORT || \
EMON_ADS1X15_SUPPORT || \
EMON_ANALOG_SUPPORT || \
EVENTS_SUPPORT || \
GUVAS12SD_SUPPORT || \
HCSR04_SUPPORT || \
HLW8012_SUPPORT || \
MHZ19_SUPPORT || \
PMSX003_SUPPORT || \
PZEM004T_SUPPORT || \
SHT3X_I2C_SUPPORT || \
SI7021_SUPPORT || \
TMP3X_SUPPORT || \
V9261F_SUPPORT \
)
#endif
// -----------------------------------------------------------------------------


BIN
code/espurna/data/index.html.gz View File


+ 13
- 1
code/espurna/debug.ino View File

@ -119,7 +119,7 @@ void debugSend_P(PGM_P format_P, ...) {
#if DEBUG_WEB_SUPPORT
void debugSetup() {
void debugWebSetup() {
wsOnSendRegister([](JsonObject& root) {
root["dbgVisible"] = 1;
@ -145,6 +145,17 @@ void debugSetup() {
#endif // DEBUG_WEB_SUPPORT
void debugSetup() {
#if DEBUG_SERIAL_SUPPORT
DEBUG_PORT.begin(SERIAL_BAUDRATE);
#if DEBUG_ESP_WIFI
DEBUG_PORT.setDebugOutput(true);
#endif
#endif
}
// -----------------------------------------------------------------------------
// Save crash info
// Taken from krzychb EspSaveCrash
@ -274,4 +285,5 @@ void debugDumpCrashInfo() {
DEBUG_MSG_P(PSTR("<<<stack<<<\n"));
}
#endif // DEBUG_SUPPORT

+ 6
- 1
code/espurna/espurna.ino View File

@ -42,6 +42,11 @@ void setup() {
// Basic modules, will always run
// -------------------------------------------------------------------------
// Serial debug
#if DEBUG_SUPPORT
debugSetup();
#endif
// Init EEPROM, Serial, SPIFFS and system check
systemSetup();
@ -81,7 +86,7 @@ void setup() {
wsSetup();
apiSetup();
#if DEBUG_WEB_SUPPORT
debugSetup();
debugWebSetup();
#endif
#endif


+ 47
- 27
code/espurna/libs/StreamInjector.h View File

@ -1,6 +1,23 @@
// -----------------------------------------------------------------------------
// Stream Injector
// -----------------------------------------------------------------------------
/*
StreamInjector
Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
@ -12,7 +29,7 @@ class StreamInjector : public Stream {
typedef std::function<void(uint8_t ch)> writeCallback;
StreamInjector(Stream& serial, size_t buflen = 128) : _stream(serial), _buffer_size(buflen) {
StreamInjector(size_t buflen = 128) : _buffer_size(buflen) {
_buffer = new char[buflen];
}
@ -20,28 +37,43 @@ class StreamInjector : public Stream {
delete[] _buffer;
}
// ---------------------------------------------------------------------
virtual uint8_t inject(char ch) {
_buffer[_buffer_write] = ch;
_buffer_write = (_buffer_write + 1) % _buffer_size;
return 1;
}
virtual uint8_t inject(char *data, size_t len) {
for (uint8_t i=0; i<len; i++) {
inject(data[i]);
}
return len;
}
virtual void callback(writeCallback c) {
_callback = c;
}
// ---------------------------------------------------------------------
virtual size_t write(uint8_t ch) {
if (_callback) _callback(ch);
return _stream.write(ch);
return 1;
}
virtual int read() {
int ch = _stream.read();
if (ch == -1) {
if (_buffer_read != _buffer_write) {
ch = _buffer[_buffer_read];
_buffer_read = (_buffer_read + 1) % _buffer_size;
}
int ch = -1;
if (_buffer_read != _buffer_write) {
ch = _buffer[_buffer_read];
_buffer_read = (_buffer_read + 1) % _buffer_size;
}
return ch;
}
virtual int available() {
unsigned int bytes = _stream.available();
unsigned int bytes = 0;
if (_buffer_read > _buffer_write) {
bytes += (_buffer_write - _buffer_read + _buffer_size);
} else if (_buffer_read < _buffer_write) {
@ -51,35 +83,23 @@ class StreamInjector : public Stream {
}
virtual int peek() {
int ch = _stream.peek();
if (ch == -1) {
if (_buffer_read != _buffer_write) {
ch = _buffer[_buffer_read];
}
int ch = -1;
if (_buffer_read != _buffer_write) {
ch = _buffer[_buffer_read];
}
return ch;
}
virtual void flush() {
_stream.flush();
_buffer_read = _buffer_write;
}
virtual void inject(char *data, size_t len) {
for (int i=0; i<len; i++) {
_buffer[_buffer_write] = data[i];
_buffer_write = (_buffer_write + 1) % _buffer_size;
}
}
private:
Stream& _stream;
char * _buffer;
unsigned char _buffer_size;
unsigned char _buffer_write = 0;
unsigned char _buffer_read = 0;
writeCallback _callback = NULL;
};

+ 1
- 1
code/espurna/libs/WebSocketIncommingBuffer.h View File

@ -80,8 +80,8 @@ class WebSocketIncommingBuffer {
private:
AwsMessageHandler _cb;
bool _cb_on_fragments;
bool _terminate_string;
bool _cb_on_fragments;
std::vector<uint8_t> *_buffer;
};

+ 17
- 0
code/espurna/migrate.ino View File

@ -888,6 +888,23 @@ void migrate() {
setSetting("board", 69);
#elif defined(ZHILDE_EU44_W)
setSetting("board", 70);
setSetting("btnGPIO", 0, 3);
setSetting("ledGPIO", 0, 1);
setSetting("ledLogic", 0, 1);
setSetting("relayGPIO", 0, 5);
setSetting("relayGPIO", 1, 4);
setSetting("relayGPIO", 2, 12);
setSetting("relayGPIO", 3, 13);
setSetting("relayGPIO", 4, 14);
setSetting("relayType", 0, RELAY_TYPE_NORMAL);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);
setSetting("relayType", 2, RELAY_TYPE_NORMAL);
setSetting("relayType", 3, RELAY_TYPE_NORMAL);
setSetting("relayType", 4, RELAY_TYPE_NORMAL);
#else
// Allow users to define new settings without migration config


+ 1
- 1
code/espurna/scheduler.ino View File

@ -104,7 +104,7 @@ bool _schIsThisWeekday(time_t t, String weekdays){
char pch;
char * p = (char *) weekdays.c_str();
unsigned char position = 0;
while (pch = p[position++]) {
while ((pch = p[position++])) {
if ((pch - '0') == w) return true;
}
return false;


+ 21
- 19
code/espurna/sensor.ino View File

@ -286,9 +286,11 @@ void _sensorPost() {
}
void _sensorReset() {
if (ntpSynced()) {
_sensor_energy_reset_ts = String(" (since ") + ntpDateTime() + String(")");
}
#if NTP_SUPPORT
if (ntpSynced()) {
_sensor_energy_reset_ts = String(" (since ") + ntpDateTime() + String(")");
}
#endif
}
// -----------------------------------------------------------------------------
@ -310,6 +312,14 @@ void _sensorLoad() {
*/
#if AM2320_SUPPORT
{
AM2320Sensor * sensor = new AM2320Sensor();
sensor->setAddress(AM2320_ADDRESS);
_sensors.push_back(sensor);
}
#endif
#if ANALOG_SUPPORT
{
AnalogSensor * sensor = new AnalogSensor();
@ -440,6 +450,14 @@ void _sensorLoad() {
}
#endif
#if GUVAS12SD_SUPPORT
{
GUVAS12SDSensor * sensor = new GUVAS12SDSensor();
sensor->setGPIO(GUVAS12SD_PIN);
_sensors.push_back(sensor);
}
#endif
#if HCSR04_SUPPORT
{
HCSR04Sensor * sensor = new HCSR04Sensor();
@ -524,22 +542,6 @@ void _sensorLoad() {
}
#endif
#if AM2320_SUPPORT
{
AM2320Sensor * sensor = new AM2320Sensor();
sensor->setAddress(AM2320_ADDRESS);
_sensors.push_back(sensor);
}
#endif
#if GUVAS12SD_SUPPORT
{
GUVAS12SDSensor * sensor = new GUVAS12SDSensor();
sensor->setGPIO(GUVAS12SD_PIN);
_sensors.push_back(sensor);
}
#endif
}
void _sensorCallback(unsigned char i, unsigned char type, const char * payload) {


+ 5
- 3
code/espurna/sensors/AM2320Sensor.h View File

@ -101,7 +101,7 @@ class AM2320Sensor : public I2CSensor {
// Get device model, version, device_id
void _init() {
i2c_wakeup();
i2c_wakeup(_address);
delayMicroseconds(800);
unsigned char _buffer[11];
@ -120,7 +120,9 @@ class AM2320Sensor : public I2CSensor {
*/
void _read() {
i2c_wakeup();
i2c_wakeup(_address);
// waiting time of at least 800 μs, the maximum 3000 μs
delayMicroseconds(800); // just to be on safe side
@ -128,7 +130,7 @@ class AM2320Sensor : public I2CSensor {
// 4 = number of bytes to read
if (i2c_write_uint8(_address, AM2320_I2C_READ_REGISTER_DATA, 0x00, 4) != I2C_TRANS_SUCCESS) {
_error = SENSOR_ERROR_TIMEOUT;
return false;
return;
}
unsigned char _buffer[8];


+ 1
- 1
code/espurna/sensors/GUVAS12SDSensor.h View File

@ -122,6 +122,7 @@ class GUVAS12SDSensor : public BaseSensor {
// ---------------------------------------------------------------------
void _read() {
int _average = 0;
#if UV_SAMPLE_RATE == 1
@ -161,7 +162,6 @@ class GUVAS12SDSensor : public BaseSensor {
_uvindex = 10;
}
return _uvindex;
}
unsigned char _gpio = GPIO_NONE;


+ 21
- 24
code/espurna/settings.ino View File

@ -10,21 +10,10 @@ Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
#include <vector>
#include "libs/EmbedisWrap.h"
#include <Stream.h>
#include "libs/StreamInjector.h"
#ifdef DEBUG_PORT
#define EMBEDIS_PORT DEBUG_PORT
#else
#define EMBEDIS_PORT Serial
#endif
#if TELNET_SUPPORT
#include "libs/StreamInjector.h"
StreamInjector _serial = StreamInjector(EMBEDIS_PORT, TERMINAL_BUFFER_SIZE);
#undef EMBEDIS_PORT
#define EMBEDIS_PORT _serial
#endif
EmbedisWrap embedis(EMBEDIS_PORT, TERMINAL_BUFFER_SIZE);
StreamInjector _serial = StreamInjector(TERMINAL_BUFFER_SIZE);
EmbedisWrap embedis(_serial, TERMINAL_BUFFER_SIZE);
#if TERMINAL_SUPPORT
#if SERIAL_RX_ENABLED
@ -360,11 +349,9 @@ void resetSettings() {
// Settings
// -----------------------------------------------------------------------------
#if TELNET_SUPPORT
void settingsInject(void *data, size_t len) {
_serial.inject((char *) data, len);
}
#endif
void settingsInject(void *data, size_t len) {
_serial.inject((char *) data, len);
}
size_t settingsMaxSize() {
size_t size = EEPROM_SIZE;
@ -395,7 +382,7 @@ bool settingsRestoreJson(JsonObject& data) {
}
bool settingsGetJson(JsonObject& root) {
void settingsGetJson(JsonObject& root) {
// Get sorted list of keys
std::vector<String> keys = _settingsKeys();
@ -420,11 +407,14 @@ void settingsSetup() {
EEPROM.begin(SPI_FLASH_SEC_SIZE);
#if TELNET_SUPPORT
_serial.callback([](uint8_t ch) {
_serial.callback([](uint8_t ch) {
#if TELNET_SUPPORT
telnetWrite(ch);
});
#endif
#endif
#if DEBUG_SERIAL_SUPPORT
DEBUG_PORT.write(ch);
#endif
});
Embedis::dictionary( F("EEPROM"),
SPI_FLASH_SEC_SIZE,
@ -457,8 +447,15 @@ void settingsLoop() {
_settings_save = false;
}
#if TERMINAL_SUPPORT
#if DEBUG_SERIAL_SUPPORT
while (DEBUG_PORT.available()) {
_serial.inject(DEBUG_PORT.read());
}
#endif
embedis.process();
#if SERIAL_RX_ENABLED


+ 524
- 523
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 0
- 7
code/espurna/system.ino View File

@ -150,13 +150,6 @@ void systemSetup() {
EEPROM.begin(EEPROM_SIZE);
#if DEBUG_SERIAL_SUPPORT
DEBUG_PORT.begin(SERIAL_BAUDRATE);
#if DEBUG_ESP_WIFI
DEBUG_PORT.setDebugOutput(true);
#endif
#endif
#if SPIFFS_SUPPORT
SPIFFS.begin();
#endif


+ 5
- 1
code/espurna/thinkspeak.ino View File

@ -192,7 +192,7 @@ void _tspkPost(String data) {
#endif // THINGSPEAK_USE_ASYNC
bool _tspkEnqueue(unsigned char index, char * payload) {
void _tspkEnqueue(unsigned char index, char * payload) {
DEBUG_MSG_P(PSTR("[THINGSPEAK] Enqueuing field #%d with value %s\n"), index, payload);
--index;
if (_tspk_queue[index] != NULL) free(_tspk_queue[index]);
@ -230,7 +230,9 @@ bool tspkEnqueueRelay(unsigned char index, unsigned char status) {
char payload[3] = {0};
itoa(status ? 1 : 0, payload, 10);
_tspkEnqueue(id, payload);
return true;
}
return false;
}
bool tspkEnqueueMeasurement(unsigned char index, char * payload) {
@ -238,7 +240,9 @@ bool tspkEnqueueMeasurement(unsigned char index, char * payload) {
unsigned char id = getSetting("tspkMagnitude", index, 0).toInt();
if (id > 0) {
_tspkEnqueue(id, payload);
return true;
}
return false;
}
void tspkFlush() {


+ 6
- 0
code/espurna/utils.ino View File

@ -386,6 +386,9 @@ void info() {
#if GUVAS12SD_SUPPORT
DEBUG_MSG_P(PSTR(" GUVAS12SD"));
#endif
#if HCSR04_SUPPORT
DEBUG_MSG_P(PSTR(" HCSR04"));
#endif
#if HLW8012_SUPPORT
DEBUG_MSG_P(PSTR(" HLW8012"));
#endif
@ -404,6 +407,9 @@ void info() {
#if SI7021_SUPPORT
DEBUG_MSG_P(PSTR(" SI7021"));
#endif
#if TMP3X_SUPPORT
DEBUG_MSG_P(PSTR(" TMP3X"));
#endif
#if V9261F_SUPPORT
DEBUG_MSG_P(PSTR(" V9261F"));
#endif


+ 30
- 0
code/espurna/wifi.ino View File

@ -196,6 +196,27 @@ void _wifiInject() {
}
}
#if WIFI_AP_CAPTIVE
DNSServer _wifi_dnsServer;
void _wifiCaptivePortal(justwifi_messages_t code, char * parameter) {
if (MESSAGE_ACCESSPOINT_CREATED == code) {
_wifi_dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
_wifi_dnsServer.start(53, "*", WiFi.softAPIP());
DEBUG_MSG_P(PSTR("[WIFI] Captive portal enabled\n"));
}
if (MESSAGE_CONNECTED == code) {
_wifi_dnsServer.stop();
DEBUG_MSG_P(PSTR("[WIFI] Captive portal disabled\n"));
}
}
#endif // WIFI_AP_CAPTIVE
#if DEBUG_SUPPORT
void _wifiDebug(justwifi_messages_t code, char * parameter) {
@ -422,6 +443,9 @@ void wifiSetup() {
_wifiConfigure();
// Message callbacks
#if WIFI_AP_CAPTIVE
wifiRegister(_wifiCaptivePortal);
#endif
#if DEBUG_SUPPORT
wifiRegister(_wifiDebug);
#endif
@ -446,6 +470,12 @@ void wifiLoop() {
jw.loop();
#if WIFI_AP_CAPTIVE
if ((WiFi.getMode() & WIFI_AP) == WIFI_AP) {
_wifi_dnsServer.processNextRequest();
}
#endif
if (_wifi_scan_client_id > 0) {
_wifiScan(_wifi_scan_client_id);
_wifi_scan_client_id = 0;


+ 4
- 2
code/html/custom.js View File

@ -878,13 +878,15 @@ function initChannels(num) {
var line = $(template).clone();
$("span.slider", line).attr("data", channel_id);
$("input.slider", line).attr("data", channel_id).on("change", onChannelSliderChange);
$("label", line).html("Channel " + (channel_id + 1));
$("label", line).html("Channel #" + channel_id);
line.appendTo("#channels");
}
for (var i=0; i<num; i++) {
$("select.islight").append(
$("<option></option>").attr("value",i).text("Channel #" + i));
}
}


+ 43
- 6
code/platformio.ini View File

@ -6,13 +6,16 @@ data_dir = espurna/data
[common]
# ------------------------------------------------------------------------------
# PLATFORM:
# !! DO NOT confuse platformio's Esp8266 development platform with Arduino core for ESP8266
# !! DO NOT confuse platformio's ESP8266 development platform with Arduino core for ESP8266
# We use platformIO 1.5.0 as default
#
# we use platformIO 1.5.0 as default
# platform 1.6.0 = arduino core 2.4.0 is required for newer features/boards
# platformIO 1.5.0 = arduino core 2.3.0
# platformIO 1.6.0 = arduino core 2.4.0
# platformIO 1.7.0 = arduino core 2.4.1
# ------------------------------------------------------------------------------
platform_150 = espressif8266@1.5.0
platform_160 = espressif8266@1.6.0
platform_170 = espressif8266@1.7.0
platform = ${common.platform_150}
# ------------------------------------------------------------------------------
@ -26,8 +29,13 @@ debug_flags = -DDEBUG_ESP_CORE -DDEBUG_ESP_SSL -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP
# build flags for 512k/1m ESP's are different because we use Linker Scripts to adjust flash split
# 512 KB = 487 KB sketch, 20 KB eeprom
# 1 MB = 999 KB sketch, 20 KB eeprom
#
# Available lwIP variants (macros):
# -DPIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH v1.4 Higher Bandwidth (default)
# -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY v2 Lower Memory
# -DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH v2 Higher Bandwidth
# ------------------------------------------------------------------------------
build_flags = -g -DMQTT_MAX_PACKET_SIZE=400 ${env.ESPURNA_FLAGS}
build_flags = -g -DMQTT_MAX_PACKET_SIZE=400 ${env.ESPURNA_FLAGS} -DPIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH
build_flags_512k = ${common.build_flags} -Wl,-Tesp8266.flash.512k0.ld
build_flags_1m = ${common.build_flags} -Wl,-Tesp8266.flash.1m0.ld
@ -50,13 +58,13 @@ lib_deps =
Brzo I2C
https://bitbucket.org/xoseperez/debounceevent.git#2.0.1
Embedis
https://github.com/plerup/espsoftwareserial#7077979
https://github.com/plerup/espsoftwareserial#3.4.1
https://github.com/me-no-dev/ESPAsyncTCP#55cd520
https://github.com/me-no-dev/ESPAsyncWebServer#232b87a
https://bitbucket.org/xoseperez/fauxmoesp.git#2.4.2
https://github.com/xoseperez/hlw8012.git#1.1.0
https://github.com/markszabo/IRremoteESP8266#v2.2.0
https://bitbucket.org/xoseperez/justwifi.git#1.1.7
https://bitbucket.org/xoseperez/justwifi.git#1.1.8
https://github.com/madpilot/mDNSResolver#4cfcda1
https://github.com/xoseperez/my92xx#3.0.1
https://bitbucket.org/xoseperez/nofuss.git#0.2.5
@ -1874,6 +1882,35 @@ upload_port = "${env.ESPURNA_IP}"
upload_flags = --auth=${env.ESPURNA_AUTH} --port 8266
extra_scripts = ${common.extra_scripts}
[env:zhilde-eu44-w]
platform = ${common.platform}
framework = arduino
board = esp01_1m
board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DZHILDE_EU44_W
monitor_baud = 115200
extra_scripts = ${common.extra_scripts}
[env:zhilde-eu44-w-ota]
platform = ${common.platform}
framework = arduino
board = esp01_1m
board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DZHILDE_EU44_W
upload_speed = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200
extra_scripts = ${common.extra_scripts}
# ------------------------------------------------------------------------------
# GENERIC OTA ENVIRONMENTS
# ------------------------------------------------------------------------------
[env:generic-esp01s-relay-40]
platform = ${common.platform}
framework = arduino


+ 105
- 59
pre-commit View File

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
"""
Referencing current branch in github README.md [1]
@ -17,61 +17,107 @@ Copy this file to .git/hooks/
import os
import sys
import re
import subprocess
BASE = os.path.dirname(os.path.realpath(__file__)) + "/../../"
README = BASE + "README.md"
remote = subprocess.check_output(["git", "remote", "-v"]).strip().split('\n')[0]
parts = re.split('[/\.: ]', remote)
REPO = parts[ len(parts) - 3]
USER = parts[ len(parts) - 4]
BRANCH = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip()
def getVersion():
file_name = BASE + "code/espurna/config/version.h"
lines = open(file_name).readlines()
for line in lines:
if "APP_VERSION" in line:
parts = line.split('"')
return parts[1]
return "unknown"
VERSION = getVersion()
version = "[![version](https://img.shields.io/badge/version-{VERSION}-brightgreen.svg)](CHANGELOG.md)\n".format(
VERSION = VERSION
)
branch = "![branch](https://img.shields.io/badge/branch-{BRANCH}-orange.svg)\n".format(
BRANCH = BRANCH
)
travis = "[![travis](https://travis-ci.org/{USER}/{REPO}.svg?branch={BRANCH})]" \
"(https://travis-ci.org/{USER}/{REPO})\n".format(
USER = USER,
REPO = REPO,
BRANCH = BRANCH
)
codacy = "[![codacy](https://img.shields.io/codacy/grade/{HASH}/{BRANCH}.svg)]" \
"(https://www.codacy.com/app/{USER}/{REPO}/dashboard)\n".format(
HASH = "c9496e25cf07434cba786b462cb15f49",
USER = USER,
REPO = REPO,
BRANCH = BRANCH
)
lines = open(README).readlines()
with open(README, "w") as fh:
for line in lines:
if "![travis]" in line:
fh.write(travis)
elif "![version]" in line:
fh.write(version)
elif "![branch]" in line:
fh.write(branch)
elif "![codacy]" in line:
fh.write(codacy)
else:
fh.write(line)
subprocess.check_output(["git", "add", README ])
from subprocess import call, check_output
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
from fileinput import FileInput
# https://github.com/python/cpython/commit/6cb7b659#diff-78790b53ff259619377058acd4f74672
if sys.version_info[0] < 3:
class FileInputCtx(FileInput):
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.close()
FileInput = FileInputCtx
def run(cmd, cwd=None):
out = check_output(cmd, cwd=cwd)
out = out.decode("latin1").strip()
return out
def parse_h_string(define, r_quotes=re.compile("\"(.*)\"")):
string = r_quotes.search(define).group(1)
return string
def git_parse_remote(cwd=None, remote="origin"):
remote_url = run([
"git", "config", "--local",
"--get", "remote.{}.url".format(remote)], cwd)
if remote_url.startswith("git"):
_, _, repo = remote_url.partition(":")
path = repo.replace(".git", "")
elif remote_url.startswith("https"):
parsed = urlparse(remote_url)
path = parsed.path[1:]
return path.split("/")
def git_branch(cwd=None):
return run(["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd)
def espurna_get_version(base, version_h="code/espurna/config/version.h"):
version = "unknown"
path = os.path.join(base, version_h)
with open(path, "r") as version_f:
for line in version_f:
if line.startswith("#define") and "APP_VERSION" in line:
version = parse_h_string(line)
break
return version
TEMPLATES = {
"![travis]": "[![travis](https://travis-ci.org/{USER}/{REPO}.svg?branch={BRANCH})]" \
"(https://travis-ci.org/{USER}/{REPO})\n",
"![version]": "[![version](https://img.shields.io/badge/version-{VERSION}-brightgreen.svg)](CHANGELOG.md)\n",
"![branch]": "[![branch](https://img.shields.io/badge/branch-{BRANCH}-orange.svg)]" \
"(https://github.org/{USER}/{REPO}/tree/{BRANCH}/)\n",
"![codacy]": "[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/{BRANCH}.svg)]" \
"(https://www.codacy.com/app/{USER}/{REPO}/dashboard)\n"
}
README = "README.md"
if __name__ == "__main__":
base = os.getcwd()
user, repo = git_parse_remote()
fmt = {
"USER": user,
"REPO": repo,
"BRANCH": git_branch(),
"VERSION": espurna_get_version(base)
}
templates = [
(k, tmpl.format(**fmt))
for k, tmpl in TEMPLATES.items()
]
def fmt_line(line):
for match, tmpl in templates:
if match in line:
return tmpl
return line
path = os.path.join(base, README)
with FileInput(path, inplace=True) as readme:
for line in readme:
sys.stdout.write(fmt_line(line))
sys.exit(call(["git", "add", README]))

Loading…
Cancel
Save