Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez authored Sep 25, 2018
2 parents fcc6827 + 50b21dd commit 56921af
Show file tree
Hide file tree
Showing 81 changed files with 1,614 additions and 1,659 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ cache:
- "~/.npm"
- "~/.platformio"
- "$TRAVIS_BUILD_DIR/code/.piolibdeps"
- "$TRAVIS_BUILD_DIR/code/espurna/node_modules"
install:
- pip install -U platformio
- cd code ; npm install --only=dev ; cd ..
- npm install -g npm@latest
- cd code ; npm ci ; cd ..
env:
global:
- BUILDER_TOTAL_THREADS=4
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ 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.13.3a-brightgreen.svg)](CHANGELOG.md)
[![branch](https://img.shields.io/badge/branch-dev-orange.svg)](https://github.com/xoseperez/espurna.git/tree/dev/)
[![travis](https://travis-ci.org/xoseperez/espurna.git.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna.git)
[![branch](https://img.shields.io/badge/branch-dev-orange.svg)](https://github.com/xoseperez/espurna/tree/dev/)
[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna)
[![codacy](https://api.codacy.com/project/badge/Grade/c9496e25cf07434cba786b462cb15f49)](https://www.codacy.com/app/xoseperez/espurna/dashboard)
[![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE)
<br />
Expand Down
5 changes: 5 additions & 0 deletions code/espurna/config/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,11 @@
#define THINGSPEAK_URL "/update"

#define THINGSPEAK_MIN_INTERVAL 15000 // Minimum interval between POSTs (in millis)
#define THINGSPEAK_FIELDS 8 // Number of fields

#ifndef THINGSPEAK_TRIES
#define THINGSPEAK_TRIES 3 // Number of tries when sending data (minimum 1)
#endif

// -----------------------------------------------------------------------------
// SCHEDULER
Expand Down
24 changes: 24 additions & 0 deletions code/espurna/config/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -2790,6 +2790,30 @@
#define LIGHT_CH3_INVERSE 0
#define LIGHT_CH4_INVERSE 0

// -----------------------------------------------------------------------------
// Bestek Smart Plug with 2 USB ports
// https://www.bestekcorp.com/bestek-smart-plug-works-with-amazon-alexa-google-assistant-and-ifttt-with-2-usb
// -----------------------------------------------------------------------------

#elif defined(BESTEK_MRJ1011)

// Info
#define MANUFACTURER "BESTEK"
#define DEVICE "MRJ1011"

// Buttons
#define BUTTON1_PIN 13
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_SET_PULLUP | BUTTON_DEFAULT_HIGH
#define BUTTON1_RELAY 1

// Relay
#define RELAY1_PIN 12
#define RELAY1_TYPE RELAY_TYPE_NORMAL

// LED
#define LED1_PIN 4
#define LED1_PIN_INVERSE 1

// -----------------------------------------------------------------------------
// TEST boards (do not use!!)
// -----------------------------------------------------------------------------
Expand Down
19 changes: 19 additions & 0 deletions code/espurna/config/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ extern "C" {
void custom_crash_callback(struct rst_info*, uint32_t, uint32_t);
}

// Core version 2.4.2 and higher changed the cont_t structure to a pointer:
// https://github.com/esp8266/Arduino/commit/5d5ea92a4d004ab009d5f642629946a0cb8893dd#diff-3fa12668b289ccb95b7ab334833a4ba8L35
// Core version 2.5.0 introduced EspClass helper method:
// https://github.com/esp8266/Arduino/commit/0e0e34c614fe8a47544c9998201b1d9b3c24eb18
extern "C" {
#include <cont.h>
#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) \
|| defined(ARDUINO_ESP8266_RELEASE_2_4_0) \
|| defined(ARDUINO_ESP8266_RELEASE_2_4_1)
extern cont_t g_cont;
#define getFreeStack() cont_get_free_stack(&g_cont)
#elif defined(ARDUINO_ESP8266_RELEASE_2_4_2)
extern cont_t* g_pcont;
#define getFreeStack() cont_get_free_stack(g_pcont)
#else
#define getFreeStack() ESP.getFreeContStack()
#endif
}

// -----------------------------------------------------------------------------
// Domoticz
// -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion code/espurna/homeassistant.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void _haSendMagnitude(unsigned char i, JsonObject& config) {
config["name"] = _haFixName(getSetting("hostname") + String(" ") + magnitudeTopic(type));
config.set("platform", "mqtt");
config["state_topic"] = mqttTopic(magnitudeTopicIndex(i).c_str(), false);
config["unit_of_measurement"] = magnitudeUnits(type);
config["unit_of_measurement"] = "\"" + magnitudeUnits(type) + "\"";

}

Expand Down
2 changes: 1 addition & 1 deletion code/espurna/migrate.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ void migrate() {
setSetting("relayType", 0, RELAY_TYPE_NORMAL);
setSetting("relayType", 1, RELAY_TYPE_NORMAL);

#elif defined(XIAOMI_SMART_DESK_LAMP)
#elif defined(PHYX_ESP12_RGB)

setSetting("board", 89);

Expand Down
10 changes: 7 additions & 3 deletions code/espurna/sensors/CSE7766Sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CSE7766Sensor : public BaseSensor {
// ---------------------------------------------------------------------

CSE7766Sensor(): BaseSensor(), _data() {
_count = 4;
_count = 6;
_sensor_id = SENSOR_CSE7766_ID;
}

Expand Down Expand Up @@ -161,7 +161,9 @@ class CSE7766Sensor : public BaseSensor {
if (index == 0) return MAGNITUDE_CURRENT;
if (index == 1) return MAGNITUDE_VOLTAGE;
if (index == 2) return MAGNITUDE_POWER_ACTIVE;
if (index == 3) return MAGNITUDE_ENERGY;
if (index == 3) return MAGNITUDE_POWER_APPARENT;
if (index == 4) return MAGNITUDE_POWER_FACTOR;
if (index == 5) return MAGNITUDE_ENERGY;
return MAGNITUDE_NONE;
}

Expand All @@ -170,7 +172,9 @@ class CSE7766Sensor : public BaseSensor {
if (index == 0) return _current;
if (index == 1) return _voltage;
if (index == 2) return _active;
if (index == 3) return _energy;
if (index == 3) return _voltage * _current;
if (index == 4) return ((_voltage > 0) && (_current > 0)) ? 100 * _active / _voltage / _current : 100;
if (index == 5) return _energy;
return 0;
}

Expand Down
46 changes: 37 additions & 9 deletions code/espurna/thinkspeak.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ const char THINGSPEAK_REQUEST_TEMPLATE[] PROGMEM =
"%s\r\n";

bool _tspk_enabled = false;
char * _tspk_queue[8] = {NULL};
char * _tspk_queue[THINGSPEAK_FIELDS] = {NULL};

bool _tspk_flush = false;
unsigned long _tspk_last_flush = 0;
unsigned char _tspk_tries = 0;

// -----------------------------------------------------------------------------

Expand Down Expand Up @@ -97,12 +98,23 @@ void _tspkPost(String data) {
}, 0);

_tspk_client->onData([](void * arg, AsyncClient * c, void * response, size_t len) {

char * b = (char *) response;
b[len] = 0;
char * p = strstr((char *)response, "\r\n\r\n");
unsigned int code = (p != NULL) ? atoi(&p[4]) : 0;
DEBUG_MSG_P(PSTR("[THINGSPEAK] Response value: %d\n"), code);

_tspk_last_flush = millis();
if ((0 == code) && (--_tspk_tries > 0)) {
_tspk_flush = true;
DEBUG_MSG_P(PSTR("[THINGSPEAK] Re-enqueuing\n"));
} else {
_tspkClearQueue();
}

_tspk_client->close(true);

}, NULL);

_tspk_client->onConnect([data](void * arg, AsyncClient * client) {
Expand All @@ -118,7 +130,7 @@ void _tspkPost(String data) {
}
#endif

DEBUG_MSG_P(PSTR("[THINGSPEAK] POST %s\n"), data.c_str());
DEBUG_MSG_P(PSTR("[THINGSPEAK] POST %s?%s\n"), THINGSPEAK_URL, data.c_str());

char buffer[strlen_P(THINGSPEAK_REQUEST_TEMPLATE) + strlen(THINGSPEAK_URL) + strlen(THINGSPEAK_HOST) + data.length()];
snprintf_P(buffer, sizeof(buffer),
Expand Down Expand Up @@ -164,7 +176,7 @@ void _tspkPost(String data) {
DEBUG_MSG_P(PSTR("[THINGSPEAK] Warning: certificate doesn't match\n"));
}

DEBUG_MSG_P(PSTR("[THINGSPEAK] POST %s\n"), data.c_str());
DEBUG_MSG_P(PSTR("[THINGSPEAK] POST %s?%s\n"), THINGSPEAK_URL, data.c_str());
char buffer[strlen_P(THINGSPEAK_REQUEST_TEMPLATE) + strlen(THINGSPEAK_URL) + strlen(THINGSPEAK_HOST) + data.length()];
snprintf_P(buffer, sizeof(buffer),
THINGSPEAK_REQUEST_TEMPLATE,
Expand All @@ -182,6 +194,15 @@ void _tspkPost(String data) {
unsigned int code = (pos > 0) ? response.substring(pos + 4).toInt() : 0;
DEBUG_MSG_P(PSTR("[THINGSPEAK] Response value: %d\n"), code);
_tspk_client.stop();

_tspk_last_flush = millis();
if ((0 == code) && (--_tspk_tries > 0)) {
_tspk_flush = true;
DEBUG_MSG_P(PSTR("[THINGSPEAK] Re-enqueuing\n"));
} else {
_tspkClearQueue();
}

return;

}
Expand All @@ -199,25 +220,33 @@ void _tspkEnqueue(unsigned char index, char * payload) {
_tspk_queue[index] = strdup(payload);
}

void _tspkClearQueue() {
for (unsigned char id=0; id<THINGSPEAK_FIELDS; id++) {
if (_tspk_queue[id] != NULL) {
free(_tspk_queue[id]);
_tspk_queue[id] = NULL;
}
}
}

void _tspkFlush() {

String data;
_tspk_flush = false;

// Walk the fields
for (unsigned char id=0; id<8; id++) {
String data;
for (unsigned char id=0; id<THINGSPEAK_FIELDS; id++) {
if (_tspk_queue[id] != NULL) {
if (data.length() > 0) data = data + String("&");
data = data + String("field") + String(id+1) + String("=") + String(_tspk_queue[id]);
free(_tspk_queue[id]);
_tspk_queue[id] = NULL;
}
}

// POST data if any
if (data.length() > 0) {
data = data + String("&api_key=") + getSetting("tspkKey");
_tspk_tries = THINGSPEAK_TRIES;
_tspkPost(data);
_tspk_last_flush = millis();
}

}
Expand Down Expand Up @@ -278,7 +307,6 @@ void tspkLoop() {
if (!wifiConnected() || (WiFi.getMode() != WIFI_STA)) return;
if (_tspk_flush && (millis() - _tspk_last_flush > THINGSPEAK_MIN_INTERVAL)) {
_tspkFlush();
_tspk_flush = false;
}
}

Expand Down
25 changes: 0 additions & 25 deletions code/espurna/utils.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,6 @@ Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com>
*/

// Core version 2.4.2 and higher changed the cont_t structure to a pointer:
// https://github.com/esp8266/Arduino/commit/5d5ea92a4d004ab009d5f642629946a0cb8893dd#diff-3fa12668b289ccb95b7ab334833a4ba8L35
#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) \
|| defined(ARDUINO_ESP8266_RELEASE_2_4_0) \
|| defined(ARDUINO_ESP8266_RELEASE_2_4_1)
extern "C" {
#include <cont.h>
extern cont_t g_cont;

}

unsigned int getFreeStack() {
return cont_get_free_stack(&g_cont);
}
#else
extern "C" {
#include <cont.h>
extern cont_t* g_pcont;
}

unsigned int getFreeStack() {
return cont_get_free_stack(g_pcont);
}
#endif // defined(ARDUINO_ESP8266_RELEASE_2_3_0/2_4_0/2_4_1)

#include <Ticker.h>
Ticker _defer_reset;

Expand Down
1 change: 0 additions & 1 deletion code/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const runSequence = require('run-sequence');
const through = require('through2');

const htmlmin = require('gulp-htmlmin');
const uglify = require('gulp-uglify');
const inline = require('gulp-inline');
const inlineImages = require('gulp-css-base64');
const favicon = require('gulp-base64-favicon');
Expand Down
74 changes: 60 additions & 14 deletions code/html/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ h2 {
display: block;
}

.content {
margin: 0;
}

.page {
margin-top: 10px;
}
Expand Down Expand Up @@ -98,16 +94,12 @@ div.center {
display: none;
}

#credentials {
font-size: 200%;
height: 100px;
left: 50%;
margin-left: -200px;
margin-top: -50px;
position: fixed;
text-align: center;
top: 50%;
width: 400px;
.content #password {
margin: 0 auto;
}

.content #layout {
margin: 0;
}

div.state {
Expand Down Expand Up @@ -206,6 +198,10 @@ div.state {
background: rgb(255, 128, 0); /* orange */
}

.button-generate-password {
background: rgb(66, 184, 221); /* blue */
}

.button-upgrade-browse,
.button-clear-filters,
.button-clear-messages,
Expand Down Expand Up @@ -448,3 +444,53 @@ table.dataTable.display tbody td {
height: 400px;
margin-bottom: 10px;
}

/* -----------------------------------------------------------------------------
Password input controls
-------------------------------------------------------------------------- */
.password-reveal {
font-family: EmojiSymbols,Segoe UI Symbol;
background: rgba(0,0,0,0);
display: inline-block;
float: right;
z-index: 50;
margin-top: 6px;
margin-left: -30px;
vertical-align: middle;
font-size: 1.2em;
height: 100%;
}

.password-reveal:after {
content: "👁";
}

input[type="password"] + .password-reveal {
color: rgba(205, 205, 205, 0.3);
}

input[type="text"] + .password-reveal {
color: rgba(66, 184, 221, 0.8);
}

.no-select {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

input::-ms-clear,
input::-ms-reveal {
display: none;
}

/* css minifier must not combine these.
* style will not apply otherwise */
input::-ms-input-placeholder {
color: #ccd;
}

input::placeholder {
color: #ccc;
}
Loading

0 comments on commit 56921af

Please sign in to comment.