Skip to content

Commit

Permalink
Merge/v2.0 dev13 to mega (#695)
Browse files Browse the repository at this point in the history
* [switch] Fixed switch behavior and default settings. (#675)

As described in #673 .
The problem was partly related to the default values stored in flash ("0"), which was not a valid value for the switch type.

When upgrading from an older version of ESPeasy, make sure to check the switch type (normal switch or dimmer) and save the settings for the switch device again, even when nothing was changed.
Default configuration and new added switches will now work like intended.

When a controller is enabled (e.g. Domoticz MQTT or -HTTP) and the button is pressed multiple times, the ESP may reboot. See issue #674.

* ABC calibration feature added (#606)

* [Flash info] Detailed flash information (#678)

Last few days a number of issues and forum topic was about the type of flash used on the ESP boards.

This is an extension of the detailed information page.

Perhaps also merge with the newer and more clear layout of pull request #624?
That pull request was only merged to the mega branch.
I kept the changes local, but perhaps they should be placed in the "Storage" section introduced with #624.
Maybe also that pull request should get merged into the v2.0 branch.

* Bugfix/v2.0 crash switch (#682)

* [crashes] Added constructors to initialize all members in structs

Numerous structs are defined, but none of them have default constructors and there is no guarantee the members will be set when used. 
With these default constructors, the parameters at least have an initialized value.

* [PubSubClient] Add bound checks on the internal buffer

Not sure if this was really causing an issue, but proper bound checks are always a good thing.

* [Crash Switch] Disabled delayBackground and added yield() calls

Something really fishy is going on with the delayBackground function, which will result in crashes when pressing the switch multiple times, with Domoticz MQTT enabled as first controller.
Disabled for now and delay(1) added to give background tasks a chance to do their work and make sure the watchdog doesn't perform a reset.

* [CI build errors] Commented out some unused variables

Travis considers them as error and fails the checks.

* [CI check] Out-of-bounds check fix

* actually ignore MQTT messages that are too big.

* moved mqtt stuff outside of backgroundtasks(). fixes #683 in my test scenario

* [Adafruit MPR121] Change deprecated name setThreshholds to setThresholds (#685)

See #684

* fixed plugin id of "Communication - Kamstrup Multical 401". (accidental octal notation)

* changed devicecombobox handling to save a lot of memory on device page. fixes #654 #676 and could be triggered by #683 in some cases.

* [CPPcheck] v2.0 ControllerSettingsStruct some variables not initialized (#692)

Fixing these cppcheck errors:
101.43s$ cppcheck --enable=warning src/*.ino -q --force -I src --include=src/ESPEasy.ino --error-exitcode=1
[src/ESPEasy.ino:500]: (warning) Member variable 'ControllerSettingsStruct::HostName' is not initialized in the constructor.
[src/ESPEasy.ino:500]: (warning) Member variable 'ControllerSettingsStruct::Publish' is not initialized in the constructor.
[src/ESPEasy.ino:500]: (warning) Member variable 'ControllerSettingsStruct::Subscribe' is not initialized in the constructor.
  • Loading branch information
TD-er authored and psy0rz committed Jan 10, 2018
1 parent 8ce1aa0 commit 9a70037
Show file tree
Hide file tree
Showing 9 changed files with 344 additions and 97 deletions.
4 changes: 2 additions & 2 deletions .atom-build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmd: "platformio"
name: "Build with error highlighting (dev_4096)"
name: "Build with error highlighting (dev_ESP8266_4096)"
args:
- run --environment dev_4096
- run --environment dev_ESP8266_4096
sh: true,
cwd: .
# env:
Expand Down
20 changes: 10 additions & 10 deletions lib/Adafruit_MPR121/Adafruit_MPR121.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/***************************************************
/***************************************************
This is a library for the MPR121 I2C 12-chan Capacitive Sensor
Designed specifically to work with the MPR121 sensor from Adafruit
----> https://www.adafruit.com/products/1982
These sensors use I2C to communicate, 2+ pins are required to
These sensors use I2C to communicate, 2+ pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/

Expand All @@ -21,26 +21,26 @@ Adafruit_MPR121::Adafruit_MPR121() {

boolean Adafruit_MPR121::begin(uint8_t i2caddr) {
Wire.begin();

_i2caddr = i2caddr;

// soft reset
writeRegister(MPR121_SOFTRESET, 0x63);
delay(1);
for (uint8_t i=0; i<0x7F; i++) {
// Serial.print("$"); Serial.print(i, HEX);
// Serial.print("$"); Serial.print(i, HEX);
// Serial.print(": 0x"); Serial.println(readRegister8(i));
}


writeRegister(MPR121_ECR, 0x0);

uint8_t c = readRegister8(MPR121_CONFIG2);

if (c != 0x24) return false;


setThreshholds(12, 6);
setThresholds(12, 6);
writeRegister(MPR121_MHDR, 0x01);
writeRegister(MPR121_NHDR, 0x01);
writeRegister(MPR121_NCLR, 0x0E);
Expand Down
4 changes: 2 additions & 2 deletions lib/pubsubclient/src/PubSubClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ uint16_t PubSubClient::readPacket(uint8_t* lengthLength) {
buffer[len++] = digit;
length += (digit & 127) * multiplier;
multiplier *= 128;
} while ((digit & 128) != 0);
} while ((digit & 128) != 0 && len < (MQTT_MAX_PACKET_SIZE -2));
*lengthLength = len-1;

if (isPublish) {
Expand Down Expand Up @@ -525,7 +525,7 @@ uint16_t PubSubClient::writeString(const char* string, uint8_t* buf, uint16_t po
const char* idp = string;
uint16_t i = 0;
pos += 2;
while (*idp) {
while (*idp && pos < (MQTT_MAX_PACKET_SIZE - 2)) {
buf[pos++] = *idp++;
i++;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Controller.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ void sendData(struct EventStruct *event)
uint16_t delayms = Settings.MessageDelay - dif;
//this is logged nowhere else, so might as well disable it here also:
// addLog(LOG_LEVEL_DEBUG_MORE, String(F("CTRL : Message delay (ms): "))+delayms);
delayBackground(delayms);

delayBackground(delayms);

// unsigned long timer = millis() + delayms;
// while (!timeOutReached(timer))
Expand Down Expand Up @@ -64,6 +65,7 @@ void callback(char* c_topic, byte* b_payload, unsigned int length) {
if (length>sizeof(c_payload)-1)
{
addLog(LOG_LEVEL_ERROR, F("MQTT : Ignored too big message"));
return;
}

//convert payload to string, and 0 terminate
Expand Down
97 changes: 94 additions & 3 deletions src/ESPEasy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,47 @@ struct SecurityStruct

struct SettingsStruct
{
SettingsStruct() :
PID(0), Version(0), Build(0), IP_Octet(0), Unit(0), Delay(0),
Pin_i2c_sda(-1), Pin_i2c_scl(-1), Pin_status_led(-1), Pin_sd_cs(-1),
UDPPort(0), SyslogLevel(0), SerialLogLevel(0), WebLogLevel(0), SDLogLevel(0),
BaudRate(0), MessageDelay(0), deepSleep(0),
CustomCSS(false), DST(false), WDI2CAddress(0),
UseRules(false), UseSerial(false), UseSSDP(false), UseNTP(false),
WireClockStretchLimit(0), GlobalSync(false), ConnectionFailuresThreshold(0),
TimeZone(0), MQTTRetainFlag(false), InitSPI(false),
Pin_status_led_Inversed(false), deepSleepOnFail(false), UseValueLogger(false)
{
for (byte i = 0; i < CONTROLLER_MAX; ++i) {
Protocol[i] = 0;
ControllerEnabled[i] = false;
for (byte task = 0; task < TASKS_MAX; ++task) {
TaskDeviceID[i][task] = 0;
TaskDeviceSendData[i][task] = false;
}
}
for (byte task = 0; task < TASKS_MAX; ++task) {
TaskDeviceNumber[task] = 0;
OLD_TaskDeviceID[task] = 0;
TaskDevicePin1PullUp[task] = false;
for (byte cv = 0; cv < PLUGIN_CONFIGVAR_MAX; ++cv) {
TaskDevicePluginConfig[task][cv] = 0;
}
TaskDevicePin1Inversed[task] = false;
for (byte cv = 0; cv < PLUGIN_CONFIGFLOATVAR_MAX; ++cv) {
TaskDevicePluginConfigFloat[task][cv] = 0.0;
}
for (byte cv = 0; cv < PLUGIN_CONFIGLONGVAR_MAX; ++cv) {
TaskDevicePluginConfigLong[task][cv] = 0;
}
OLD_TaskDeviceSendData[task] = false;
TaskDeviceGlobalSync[task] = false;
TaskDeviceDataFeed[task] = 0;
TaskDeviceTimer[task] = 0;
TaskDeviceEnabled[task] = false;
}
}

unsigned long PID;
int Version;
int16_t Build;
Expand Down Expand Up @@ -500,6 +541,11 @@ struct SettingsStruct

struct ControllerSettingsStruct
{
ControllerSettingsStruct() : UseDNS(false), Port(0) {
memset(HostName, 0, sizeof(HostName));
memset(Publish, 0, sizeof(Publish));
memset(Subscribe, 0, sizeof(Subscribe));
}
boolean UseDNS;
byte IP[4];
unsigned int Port;
Expand Down Expand Up @@ -563,6 +609,21 @@ struct NotificationSettingsStruct

struct ExtraTaskSettingsStruct
{
ExtraTaskSettingsStruct() : TaskIndex(0) {
TaskDeviceName[0] = 0;
for (byte i = 0; i < VARS_PER_TASK; ++i) {
for (byte j = 0; j < 41; ++j) {
TaskDeviceFormula[i][j] = 0;
TaskDeviceValueNames[i][j] = 0;
TaskDeviceValueDecimals[i] = 0;
}
}
for (byte i = 0; i < PLUGIN_EXTRACONFIGVAR_MAX; ++i) {
TaskDevicePluginConfigLong[i] = 0;
TaskDevicePluginConfig[i] = 0;
}
}

byte TaskIndex;
char TaskDeviceName[41];
char TaskDeviceFormula[VARS_PER_TASK][41];
Expand All @@ -574,6 +635,10 @@ struct ExtraTaskSettingsStruct

struct EventStruct
{
EventStruct() :
Source(0), TaskIndex(0), ControllerIndex(0), ProtocolIndex(0), NotificationIndex(0),
BaseVarIndex(0), idx(0), sensorType(0), Par1(0), Par2(0), Par3(0), Par4(0), Par5(0),
OriginTaskIndex(0), Data(NULL) {}
byte Source;
byte TaskIndex; // index position in TaskSettings array, 0-11
byte ControllerIndex; // index position in Settings.Controller, 0-3
Expand All @@ -598,13 +663,19 @@ struct EventStruct

struct LogStruct
{
LogStruct() : timeStamp(0), Message(NULL) {}
unsigned long timeStamp;
char* Message;
} Logging[10];
int logcount = -1;

struct DeviceStruct
{
DeviceStruct() :
Number(0), Type(0), VType(0), Ports(0),
PullUpOption(false), InverseLogicOption(false), FormulaOption(false),
ValueCount(0), Custom(false), SendDataOption(false), GlobalSyncOption(false),
TimerOption(false), TimerOptional(false), DecimalsOnly(false) {}
byte Number;
byte Type;
byte VType;
Expand All @@ -623,6 +694,9 @@ struct DeviceStruct

struct ProtocolStruct
{
ProtocolStruct() :
Number(0), usesMQTT(false), usesAccount(false), usesPassword(false),
defaultPort(0), usesTemplate(false), usesID(false) {}
byte Number;
boolean usesMQTT;
boolean usesAccount;
Expand All @@ -634,13 +708,20 @@ struct ProtocolStruct

struct NotificationStruct
{
NotificationStruct() :
Number(0), usesMessaging(false), usesGPIO(0) {}
byte Number;
boolean usesMessaging;
byte usesGPIO;
} Notification[NPLUGIN_MAX];

struct NodeStruct
{
NodeStruct() :
age(0), build(0), nodeName(NULL), nodeType(0)
{
for (byte i = 0; i < 4; ++i) ip[i] = 0;
}
byte ip[4];
byte age;
uint16_t build;
Expand All @@ -650,6 +731,9 @@ struct NodeStruct

struct systemTimerStruct
{
systemTimerStruct() :
timer(0), plugin(0), Par1(0), Par2(0), Par3(0) {}

unsigned long timer;
byte plugin;
byte Par1;
Expand All @@ -659,6 +743,7 @@ struct systemTimerStruct

struct systemCMDTimerStruct
{
systemCMDTimerStruct() : timer(0) {}
unsigned long timer;
String action;
} systemCMDTimers[SYSTEM_CMD_TIMER_MAX];
Expand Down Expand Up @@ -978,6 +1063,11 @@ void loop()
if (timeOutReached(timer1s))
runOncePerSecond();
}

//dont do this in backgroundtasks(), otherwise causes crashes. (https://github.com/letscontrolit/ESPEasy/issues/683)
if(Settings.ControllerEnabled[0])
MQTTclient.loop();

backgroundtasks();

}
Expand Down Expand Up @@ -1322,10 +1412,12 @@ void checkSystemTimers()
bool runningBackgroundTasks=false;
void backgroundtasks()
{
//always start with a yield
yield();

//prevent recursion!
if (runningBackgroundTasks)
{
yield();
return;
}
runningBackgroundTasks=true;
Expand All @@ -1344,8 +1436,7 @@ void backgroundtasks()
dnsServer.processNextRequest();

WebServer.handleClient();
if(Settings.ControllerEnabled[0])
MQTTclient.loop();

checkUDP();

#ifdef FEATURE_ARDUINO_OTA
Expand Down
Loading

0 comments on commit 9a70037

Please sign in to comment.