From 2dc2b7d176015599831e37a6695d9a74231b696d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 15 Jan 2018 23:48:41 +0100 Subject: [PATCH] Checking code with cppcheck --- code/espurna/alexa.ino | 2 +- code/espurna/button.ino | 11 ++++------- code/espurna/debug.ino | 10 +++++----- code/espurna/domoticz.ino | 8 ++++---- code/espurna/espurna.ino | 4 ++-- code/espurna/gpio.ino | 10 +++++----- code/espurna/i2c.ino | 2 +- code/espurna/influxdb.ino | 2 +- code/espurna/led.ino | 3 --- code/espurna/libs/StreamInjector.h | 2 +- code/espurna/mdns.ino | 6 +++--- code/espurna/sensor.ino | 10 ++++++++-- code/espurna/sensors/DHTSensor.h | 14 +++++++------- code/espurna/sensors/DallasSensor.h | 10 +++++----- code/espurna/sensors/ECH1560Sensor.h | 6 +++--- code/espurna/sensors/EmonADS1X15Sensor.h | 2 +- code/espurna/sensors/HLW8012Sensor.h | 16 ++++++++-------- code/espurna/sensors/MHZ19Sensor.h | 4 ++-- code/espurna/sensors/PMSX003Sensor.h | 10 +++++----- code/espurna/sensors/V9261FSensor.h | 4 ++-- code/espurna/telnet.ino | 6 +++--- code/espurna/thinkspeak.ino | 2 +- code/espurna/utils.ino | 6 +++--- 23 files changed, 75 insertions(+), 75 deletions(-) diff --git a/code/espurna/alexa.ino b/code/espurna/alexa.ino index 8f0ced46..48a26c26 100644 --- a/code/espurna/alexa.ino +++ b/code/espurna/alexa.ino @@ -76,7 +76,7 @@ void alexaLoop() { while (!_alexa_dev_changes.empty()) { AlexaDevChange& change = _alexa_dev_changes.front(); - DEBUG_MSG_P(PSTR("[ALEXA] Device #%d state: %s\n"), change.device_id, change.state ? "ON" : "OFF"); + DEBUG_MSG_P(PSTR("[ALEXA] Device #%u state: %s\n"), change.device_id, change.state ? "ON" : "OFF"); relayStatus(change.device_id, change.state); _alexa_dev_changes.pop(); } diff --git a/code/espurna/button.ino b/code/espurna/button.ino index 40033e11..e12f3119 100644 --- a/code/espurna/button.ino +++ b/code/espurna/button.ino @@ -26,7 +26,7 @@ std::vector _buttons; void buttonMQTT(unsigned char id, uint8_t event) { if (id >= _buttons.size()) return; char payload[2]; - snprintf_P(payload, sizeof(payload), PSTR("%d"), event); + itoa(event, payload, 10); mqttSend(MQTT_TOPIC_BUTTON, id, payload); } #endif @@ -80,7 +80,7 @@ uint8_t mapEvent(uint8_t event, uint8_t count, uint16_t length) { void buttonEvent(unsigned int id, unsigned char event) { - DEBUG_MSG_P(PSTR("[BUTTON] Button #%d event %d\n"), id, event); + DEBUG_MSG_P(PSTR("[BUTTON] Button #%u event %u\n"), id, event); if (event == 0) return; #if MQTT_SUPPORT @@ -182,7 +182,7 @@ void buttonSetup() { #endif - DEBUG_MSG_P(PSTR("[BUTTON] Number of buttons: %d\n"), _buttons.size()); + DEBUG_MSG_P(PSTR("[BUTTON] Number of buttons: %u\n"), _buttons.size()); } @@ -191,11 +191,9 @@ void buttonLoop() { #ifdef ITEAD_SONOFF_DUAL if (Serial.available() >= 4) { - - unsigned char value; if (Serial.read() == 0xA0) { if (Serial.read() == 0x04) { - value = Serial.read(); + unsigned char value = Serial.read(); if (Serial.read() == 0xA1) { // RELAYs and BUTTONs are synchonized in the SIL F330 @@ -228,7 +226,6 @@ void buttonLoop() { } } } - } #else diff --git a/code/espurna/debug.ino b/code/espurna/debug.ino index 942ad3af..dd3d0e72 100644 --- a/code/espurna/debug.ino +++ b/code/espurna/debug.ino @@ -50,7 +50,7 @@ void debugSend(const char * format, ...) { _telnetWrite(buffer, strlen(buffer)); #endif - free(buffer); + delete[] buffer; } @@ -87,7 +87,7 @@ void debugSend_P(PGM_P format_P, ...) { _telnetWrite(buffer, strlen(buffer)); #endif - free(buffer); + delete[] buffer; } @@ -188,9 +188,9 @@ void debugDumpCrashInfo() { return; } - DEBUG_MSG_P(PSTR("[DEBUG] Crash at %ld ms\n"), crash_time); - DEBUG_MSG_P(PSTR("[DEBUG] Reason of restart: %d\n"), EEPROM.read(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_RESTART_REASON)); - DEBUG_MSG_P(PSTR("[DEBUG] Exception cause: %d\n"), EEPROM.read(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_EXCEPTION_CAUSE)); + DEBUG_MSG_P(PSTR("[DEBUG] Crash at %lu ms\n"), crash_time); + DEBUG_MSG_P(PSTR("[DEBUG] Reason of restart: %u\n"), EEPROM.read(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_RESTART_REASON)); + DEBUG_MSG_P(PSTR("[DEBUG] Exception cause: %u\n"), EEPROM.read(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_EXCEPTION_CAUSE)); uint32_t epc1, epc2, epc3, excvaddr, depc; EEPROM.get(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_EPC1, epc1); diff --git a/code/espurna/domoticz.ino b/code/espurna/domoticz.ino index 2351dc8c..daea88a2 100644 --- a/code/espurna/domoticz.ino +++ b/code/espurna/domoticz.ino @@ -64,7 +64,7 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload) int relayID = _domoticzRelay(idx); if (relayID >= 0) { unsigned long value = root["nvalue"]; - DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %d for IDX %d\n"), value, idx); + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %lu for IDX %lu\n"), value, idx); relayStatus(relayID, value == 1); } @@ -117,7 +117,7 @@ template void domoticzSend(const char * key, T nvalue, const char * unsigned int idx = getSetting(key).toInt(); if (idx > 0) { char payload[128]; - snprintf(payload, sizeof(payload), "{\"idx\": %d, \"nvalue\": %s, \"svalue\": \"%s\"}", idx, String(nvalue).c_str(), svalue); + snprintf(payload, sizeof(payload), "{\"idx\": %u, \"nvalue\": %s, \"svalue\": \"%s\"}", idx, String(nvalue).c_str(), svalue); mqttSendRaw(getSetting("dczTopicIn", DOMOTICZ_IN_TOPIC).c_str(), payload); } } @@ -129,13 +129,13 @@ template void domoticzSend(const char * key, T nvalue) { void domoticzSendRelay(unsigned int relayID) { if (!_dcz_enabled) return; char buffer[15]; - snprintf_P(buffer, sizeof(buffer), PSTR("dczRelayIdx%d"), relayID); + snprintf_P(buffer, sizeof(buffer), PSTR("dczRelayIdx%lu"), relayID); domoticzSend(buffer, relayStatus(relayID) ? "1" : "0"); } int domoticzIdx(unsigned int relayID) { char buffer[15]; - snprintf_P(buffer, sizeof(buffer), PSTR("dczRelayIdx%d"), relayID); + snprintf_P(buffer, sizeof(buffer), PSTR("dczRelayIdx%lu"), relayID); return getSetting(buffer).toInt(); } diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index 0cb5b277..577bb7ec 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -79,7 +79,7 @@ void welcome() { DEBUG_MSG_P(PSTR("[INIT] %s\n"), (char *) APP_AUTHOR); DEBUG_MSG_P(PSTR("[INIT] %s\n\n"), (char *) APP_WEBSITE); DEBUG_MSG_P(PSTR("[INIT] CPU chip ID: 0x%06X\n"), ESP.getChipId()); - DEBUG_MSG_P(PSTR("[INIT] CPU frequency: %d MHz\n"), ESP.getCpuFreqMHz()); + DEBUG_MSG_P(PSTR("[INIT] CPU frequency: %u MHz\n"), ESP.getCpuFreqMHz()); DEBUG_MSG_P(PSTR("[INIT] SDK version: %s\n"), ESP.getSdkVersion()); DEBUG_MSG_P(PSTR("[INIT] Core version: %s\n"), getCoreVersion().c_str()); DEBUG_MSG_P(PSTR("[INIT] Core revision: %s\n"), getCoreRevision().c_str()); @@ -268,7 +268,7 @@ void welcome() { DEBUG_MSG_P(PSTR("[INIT] Free heap: %u bytes\n"), getFreeHeap()); #if ADC_VCC_ENABLED - DEBUG_MSG_P(PSTR("[INIT] Power: %d mV\n"), ESP.getVcc()); + DEBUG_MSG_P(PSTR("[INIT] Power: %u mV\n"), ESP.getVcc()); #endif DEBUG_MSG_P(PSTR("[INIT] Power saving delay value: %lu ms\n"), _loopDelay); diff --git a/code/espurna/gpio.ino b/code/espurna/gpio.ino index ed0399fe..c69f437a 100644 --- a/code/espurna/gpio.ino +++ b/code/espurna/gpio.ino @@ -9,7 +9,7 @@ Copyright (C) 2017-2018 by Xose PĂ©rez unsigned int _gpio_locked = 0; bool gpioValid(unsigned char gpio) { - if (0 <= gpio && gpio <= 5) return true; + if (gpio <= 5) return true; if (12 <= gpio && gpio <= 15) return true; return false; } @@ -19,11 +19,11 @@ bool gpioGetLock(unsigned char gpio) { unsigned int mask = 1 << gpio; if ((_gpio_locked & mask) == 0) { _gpio_locked |= mask; - DEBUG_MSG_P(PSTR("[GPIO] GPIO%d locked\n"), gpio); + DEBUG_MSG_P(PSTR("[GPIO] GPIO%u locked\n"), gpio); return true; } } - DEBUG_MSG_P(PSTR("[GPIO] Failed getting lock for GPIO%d\n"), gpio); + DEBUG_MSG_P(PSTR("[GPIO] Failed getting lock for GPIO%u\n"), gpio); return false; } @@ -31,9 +31,9 @@ bool gpioReleaseLock(unsigned char gpio) { if (gpioValid(gpio)) { unsigned int mask = 1 << gpio; _gpio_locked &= ~mask; - DEBUG_MSG_P(PSTR("[GPIO] GPIO%d lock released\n"), gpio); + DEBUG_MSG_P(PSTR("[GPIO] GPIO%u lock released\n"), gpio); return true; } - DEBUG_MSG_P(PSTR("[GPIO] Failed releasing lock for GPIO%d\n"), gpio); + DEBUG_MSG_P(PSTR("[GPIO] Failed releasing lock for GPIO%u\n"), gpio); return false; } diff --git a/code/espurna/i2c.ino b/code/espurna/i2c.ino index 422ff4c8..9c396fe9 100644 --- a/code/espurna/i2c.ino +++ b/code/espurna/i2c.ino @@ -194,7 +194,7 @@ void i2cSetup() { Wire.begin(sda, scl); #endif - DEBUG_MSG_P(PSTR("[I2C] Using GPIO%d for SDA and GPIO%d for SCL\n"), sda, scl); + DEBUG_MSG_P(PSTR("[I2C] Using GPIO%u for SDA and GPIO%u for SCL\n"), sda, scl); } diff --git a/code/espurna/influxdb.ino b/code/espurna/influxdb.ino index 905f661b..e9431f8a 100644 --- a/code/espurna/influxdb.ino +++ b/code/espurna/influxdb.ino @@ -49,7 +49,7 @@ template bool idbSend(const char * topic, T payload) { int port = getSetting("idbPort", INFLUXDB_PORT).toInt(); - DEBUG_MSG("[INFLUXDB] Sending to %s:%d\n", host, port); + DEBUG_MSG("[INFLUXDB] Sending to %s:%u\n", host, port); _idb_client.setTimeout(2); if (!_idb_client.connect(host, port)) { DEBUG_MSG("[INFLUXDB] Connection failed\n"); diff --git a/code/espurna/led.ino b/code/espurna/led.ino index 038bf465..86e1dbf6 100644 --- a/code/espurna/led.ino +++ b/code/espurna/led.ino @@ -30,7 +30,6 @@ bool _ledStatus(unsigned char id) { bool _ledStatus(unsigned char id, bool status) { if (id >=_ledCount()) return false; - bool s = _leds[id].reverse ? !status : status; digitalWrite(_leds[id].pin, _leds[id].reverse ? !status : status); return status; } @@ -69,8 +68,6 @@ void _ledWebSocketOnSend(JsonObject& root) { #if MQTT_SUPPORT void _ledMQTTCallback(unsigned int type, const char * topic, const char * payload) { - static bool isFirstMessage = true; - if (type == MQTT_CONNECT_EVENT) { char buffer[strlen(MQTT_TOPIC_LED) + 3]; snprintf_P(buffer, sizeof(buffer), PSTR("%s/+"), MQTT_TOPIC_LED); diff --git a/code/espurna/libs/StreamInjector.h b/code/espurna/libs/StreamInjector.h index 24568b6a..648473c7 100644 --- a/code/espurna/libs/StreamInjector.h +++ b/code/espurna/libs/StreamInjector.h @@ -12,7 +12,7 @@ class StreamInjector : public Stream { typedef std::function writeCallback; - StreamInjector(Stream& serial) : _stream(serial) {} + StreamInjector(Stream& serial) : _stream(serial), _buffer() {} virtual void callback(writeCallback c) { _callback = c; diff --git a/code/espurna/mdns.ino b/code/espurna/mdns.ino index 630073dd..efa13283 100644 --- a/code/espurna/mdns.ino +++ b/code/espurna/mdns.ino @@ -52,17 +52,17 @@ void mdnsServerSetup() { MDNS.addServiceTxt("arduino", "tcp", "app_version", APP_VERSION); MDNS.addServiceTxt("arduino", "tcp", "target_board", getBoardName()); { - char buffer[6]; + char buffer[6] = {0}; itoa(ESP.getFlashChipRealSize() / 1024, buffer, 10); MDNS.addServiceTxt("arduino", "tcp", "mem_size", (const char *) buffer); } { - char buffer[6]; + char buffer[6] = {0}; itoa(ESP.getFlashChipSize() / 1024, buffer, 10); MDNS.addServiceTxt("arduino", "tcp", "sdk_size", (const char *) buffer); } { - char buffer[6]; + char buffer[6] = {0}; itoa(ESP.getFreeSketchSpace(), buffer, 10); MDNS.addServiceTxt("arduino", "tcp", "free_space", (const char *) buffer); } diff --git a/code/espurna/sensor.ino b/code/espurna/sensor.ino index ac55a5aa..c3b2e7ea 100644 --- a/code/espurna/sensor.ino +++ b/code/espurna/sensor.ino @@ -416,13 +416,13 @@ void _sensorInit() { void _sensorConfigure() { - double value; - for (unsigned char i=0; i<_sensors.size(); i++) { #if EMON_ANALOG_SUPPORT + if (_sensors[i]->getID() == SENSOR_EMON_ANALOG_ID) { + double value; EmonAnalogSensor * sensor = (EmonAnalogSensor *) _sensors[i]; if (value = getSetting("pwrExpectedP", 0).toInt() == 0) { @@ -442,14 +442,18 @@ void _sensorConfigure() { } + #endif // EMON_ANALOG_SUPPORT // Force sensor to reload config _sensors[i]->begin(); #if HLW8012_SUPPORT + + if (_sensors[i]->getID() == SENSOR_HLW8012_ID) { + double value; HLW8012Sensor * sensor = (HLW8012Sensor *) _sensors[i]; if (value = getSetting("pwrExpectedC", 0).toFloat()) { @@ -484,7 +488,9 @@ void _sensorConfigure() { } } + #endif // HLW8012_SUPPORT + } // General sensor settings diff --git a/code/espurna/sensors/DHTSensor.h b/code/espurna/sensors/DHTSensor.h index 4fce7e1a..b7f0809c 100644 --- a/code/espurna/sensors/DHTSensor.h +++ b/code/espurna/sensors/DHTSensor.h @@ -33,7 +33,7 @@ class DHTSensor : public BaseSensor { } ~DHTSensor() { - if (_previous != 0xFF) gpioReleaseLock(_previous); + if (_previous != GPIO_NONE) gpioReleaseLock(_previous); } // --------------------------------------------------------------------- @@ -66,8 +66,8 @@ class DHTSensor : public BaseSensor { _count = 0; // Manage GPIO lock - if (_previous != 0xFF) gpioReleaseLock(_previous); - _previous = 0xFF; + if (_previous != GPIO_NONE) gpioReleaseLock(_previous); + _previous = GPIO_NONE; if (!gpioGetLock(_gpio)) { _error = SENSOR_ERROR_GPIO_USED; return; @@ -232,15 +232,15 @@ class DHTSensor : public BaseSensor { return uSec; } - unsigned char _gpio; - unsigned char _previous = 0xFF; + unsigned char _gpio = GPIO_NONE; + unsigned char _previous = GPIO_NONE; unsigned char _type = DHT_CHIP_DHT22; unsigned long _last_ok = 0; unsigned char _errors = 0; - double _temperature; - unsigned int _humidity; + double _temperature = 0; + unsigned int _humidity = 0; }; diff --git a/code/espurna/sensors/DallasSensor.h b/code/espurna/sensors/DallasSensor.h index ed934605..2fa6ec3c 100644 --- a/code/espurna/sensors/DallasSensor.h +++ b/code/espurna/sensors/DallasSensor.h @@ -41,7 +41,7 @@ class DallasSensor : public BaseSensor { ~DallasSensor() { if (_wire) delete _wire; - if (_previous != 0xFF) gpioReleaseLock(_previous); + if (_previous != GPIO_NONE) gpioReleaseLock(_previous); } // --------------------------------------------------------------------- @@ -69,8 +69,8 @@ class DallasSensor : public BaseSensor { _dirty = false; // Manage GPIO lock - if (_previous != 0xFF) gpioReleaseLock(_previous); - _previous = 0xFF; + if (_previous != GPIO_NONE) gpioReleaseLock(_previous); + _previous = GPIO_NONE; if (!gpioGetLock(_gpio)) { _error = SENSOR_ERROR_GPIO_USED; return; @@ -311,8 +311,8 @@ class DallasSensor : public BaseSensor { } ds_device_t; std::vector _devices; - unsigned char _gpio; - unsigned char _previous = 0xFF; + unsigned char _gpio = GPIO_NONE; + unsigned char _previous = GPIO_NONE; OneWire * _wire = NULL; }; diff --git a/code/espurna/sensors/ECH1560Sensor.h b/code/espurna/sensors/ECH1560Sensor.h index de200811..3cdd5fbd 100644 --- a/code/espurna/sensors/ECH1560Sensor.h +++ b/code/espurna/sensors/ECH1560Sensor.h @@ -18,7 +18,7 @@ class ECH1560Sensor : public BaseSensor { // Public // --------------------------------------------------------------------- - ECH1560Sensor(): BaseSensor() { + ECH1560Sensor(): BaseSensor(), _data() { _count = 3; _sensor_id = SENSOR_ECH1560_ID; } @@ -78,7 +78,7 @@ class ECH1560Sensor : public BaseSensor { // Descriptive name of the sensor String description() { char buffer[25]; - snprintf(buffer, sizeof(buffer), "ECH1560 @ GPIO(%i,%i)", _clk, _miso); + snprintf(buffer, sizeof(buffer), "ECH1560 @ GPIO(%u,%u)", _clk, _miso); return String(buffer); } @@ -90,7 +90,7 @@ class ECH1560Sensor : public BaseSensor { // Address of the sensor (it could be the GPIO or I2C address) String address(unsigned char index) { char buffer[6]; - snprintf(buffer, sizeof(buffer), "%i:%i", _clk, _miso); + snprintf(buffer, sizeof(buffer), "%u:%u", _clk, _miso); return String(buffer); } diff --git a/code/espurna/sensors/EmonADS1X15Sensor.h b/code/espurna/sensors/EmonADS1X15Sensor.h index 3ad437df..1a2bef55 100644 --- a/code/espurna/sensors/EmonADS1X15Sensor.h +++ b/code/espurna/sensors/EmonADS1X15Sensor.h @@ -207,7 +207,7 @@ class EmonADS1X15Sensor : public EmonSensor { String address(unsigned char index) { char buffer[10]; unsigned char channel = getChannel(index % _ports); - snprintf(buffer, sizeof(buffer), "0x%02X:%i", _address, channel); + snprintf(buffer, sizeof(buffer), "0x%02X:%u", _address, channel); return String(buffer); } diff --git a/code/espurna/sensors/HLW8012Sensor.h b/code/espurna/sensors/HLW8012Sensor.h index c3cd3fcb..0e4410af 100644 --- a/code/espurna/sensors/HLW8012Sensor.h +++ b/code/espurna/sensors/HLW8012Sensor.h @@ -158,7 +158,7 @@ class HLW8012Sensor : public BaseSensor { // Descriptive name of the sensor String description() { char buffer[25]; - snprintf(buffer, sizeof(buffer), "HLW8012 @ GPIO(%i,%i,%i)", _sel, _cf, _cf1); + snprintf(buffer, sizeof(buffer), "HLW8012 @ GPIO(%u,%u,%u)", _sel, _cf, _cf1); return String(buffer); } @@ -170,7 +170,7 @@ class HLW8012Sensor : public BaseSensor { // Address of the sensor (it could be the GPIO or I2C address) String address(unsigned char index) { char buffer[10]; - snprintf(buffer, sizeof(buffer), "%i:%i:%i", _sel, _cf, _cf1); + snprintf(buffer, sizeof(buffer), "%u:%u:%u", _sel, _cf, _cf1); return String(buffer); } @@ -255,10 +255,10 @@ class HLW8012Sensor : public BaseSensor { // --------------------------------------------------------------------- - unsigned char _sel; - unsigned char _cf; - unsigned char _cf1; - bool _sel_current; + unsigned char _sel = GPIO_NONE; + unsigned char _cf = GPIO_NONE; + unsigned char _cf1 = GPIO_NONE; + bool _sel_current = true; HLW8012 * _hlw8012 = NULL; @@ -307,7 +307,7 @@ void HLW8012Sensor::_attach(HLW8012Sensor * instance, unsigned char gpio, unsign _hlw8012_sensor_instance[index] = instance; attachInterrupt(gpio, _hlw8012_sensor_isr_list[index], mode); #if SENSOR_DEBUG - DEBUG_MSG_P(PSTR("[SENSOR] GPIO%d interrupt attached to %s\n"), gpio, instance->description().c_str()); + DEBUG_MSG_P(PSTR("[SENSOR] GPIO%u interrupt attached to %s\n"), gpio, instance->description().c_str()); #endif } @@ -317,7 +317,7 @@ void HLW8012Sensor::_detach(unsigned char gpio) { if (_hlw8012_sensor_instance[index]) { detachInterrupt(gpio); #if SENSOR_DEBUG - DEBUG_MSG_P(PSTR("[SENSOR] GPIO%d interrupt detached from %s\n"), gpio, _hlw8012_sensor_instance[index]->description().c_str()); + DEBUG_MSG_P(PSTR("[SENSOR] GPIO%u interrupt detached from %s\n"), gpio, _hlw8012_sensor_instance[index]->description().c_str()); #endif _hlw8012_sensor_instance[index] = NULL; } diff --git a/code/espurna/sensors/MHZ19Sensor.h b/code/espurna/sensors/MHZ19Sensor.h index 2fcc1b85..1c039e6a 100644 --- a/code/espurna/sensors/MHZ19Sensor.h +++ b/code/espurna/sensors/MHZ19Sensor.h @@ -85,7 +85,7 @@ class MHZ19Sensor : public BaseSensor { // Descriptive name of the sensor String description() { char buffer[28]; - snprintf(buffer, sizeof(buffer), "MHZ19 @ SwSerial(%i,%i)", _pin_rx, _pin_tx); + snprintf(buffer, sizeof(buffer), "MHZ19 @ SwSerial(%u,%u)", _pin_rx, _pin_tx); return String(buffer); } @@ -97,7 +97,7 @@ class MHZ19Sensor : public BaseSensor { // Address of the sensor (it could be the GPIO or I2C address) String address(unsigned char index) { char buffer[6]; - snprintf(buffer, sizeof(buffer), "%i:%i", _pin_rx, _pin_tx); + snprintf(buffer, sizeof(buffer), "%u:%u", _pin_rx, _pin_tx); return String(buffer); } diff --git a/code/espurna/sensors/PMSX003Sensor.h b/code/espurna/sensors/PMSX003Sensor.h index f5662292..25cd233d 100644 --- a/code/espurna/sensors/PMSX003Sensor.h +++ b/code/espurna/sensors/PMSX003Sensor.h @@ -79,7 +79,7 @@ class PMSX003Sensor : public BaseSensor { // Descriptive name of the sensor String description() { char buffer[28]; - snprintf(buffer, sizeof(buffer), "PMSX003 @ SwSerial(%i,%i)", _pin_rx, _pin_tx); + snprintf(buffer, sizeof(buffer), "PMSX003 @ SwSerial(%u,%u)", _pin_rx, _pin_tx); return String(buffer); } @@ -88,9 +88,9 @@ class PMSX003Sensor : public BaseSensor { if (index < _count) { _error = SENSOR_ERROR_OK; char buffer[36]; - if (index == 0) snprintf(buffer, sizeof(buffer), "PM1.0 @ PMSX003 @ SwSerial(%i,%i)", _pin_rx, _pin_tx); - if (index == 1) snprintf(buffer, sizeof(buffer), "PM2.5 @ PMSX003 @ SwSerial(%i,%i)", _pin_rx, _pin_tx); - if (index == 2) snprintf(buffer, sizeof(buffer), "PM10 @ PMSX003 @ SwSerial(%i,%i)", _pin_rx, _pin_tx); + if (index == 0) snprintf(buffer, sizeof(buffer), "PM1.0 @ PMSX003 @ SwSerial(%u,%u)", _pin_rx, _pin_tx); + if (index == 1) snprintf(buffer, sizeof(buffer), "PM2.5 @ PMSX003 @ SwSerial(%u,%u)", _pin_rx, _pin_tx); + if (index == 2) snprintf(buffer, sizeof(buffer), "PM10 @ PMSX003 @ SwSerial(%u,%u)", _pin_rx, _pin_tx); return String(buffer); } _error = SENSOR_ERROR_OUT_OF_RANGE; @@ -100,7 +100,7 @@ class PMSX003Sensor : public BaseSensor { // Address of the sensor (it could be the GPIO or I2C address) String address(unsigned char index) { char buffer[6]; - snprintf(buffer, sizeof(buffer), "%i:%i", _pin_rx, _pin_tx); + snprintf(buffer, sizeof(buffer), "%u:%u", _pin_rx, _pin_tx); return String(buffer); } diff --git a/code/espurna/sensors/V9261FSensor.h b/code/espurna/sensors/V9261FSensor.h index 928dfcdd..7d244fba 100644 --- a/code/espurna/sensors/V9261FSensor.h +++ b/code/espurna/sensors/V9261FSensor.h @@ -20,7 +20,7 @@ class V9261FSensor : public BaseSensor { // Public // --------------------------------------------------------------------- - V9261FSensor(): BaseSensor() { + V9261FSensor(): BaseSensor(), _data() { _count = 6; _sensor_id = SENSOR_V9261F_ID; } @@ -73,7 +73,7 @@ class V9261FSensor : public BaseSensor { // Descriptive name of the sensor String description() { char buffer[28]; - snprintf(buffer, sizeof(buffer), "V9261F @ SwSerial(%i,NULL)", _pin_rx); + snprintf(buffer, sizeof(buffer), "V9261F @ SwSerial(%u,NULL)", _pin_rx); return String(buffer); } diff --git a/code/espurna/telnet.ino b/code/espurna/telnet.ino index 228d0b62..f40818a9 100644 --- a/code/espurna/telnet.ino +++ b/code/espurna/telnet.ino @@ -93,15 +93,15 @@ void _telnetNewClient(AsyncClient *client) { }, 0); client->onError([i](void *s, AsyncClient *c, int8_t error) { - DEBUG_MSG_P(PSTR("[TELNET] Error %s (%d) on client #%d\n"), c->errorToString(error), error, i); + DEBUG_MSG_P(PSTR("[TELNET] Error %s (%d) on client #%u\n"), c->errorToString(error), error, i); }, 0); client->onTimeout([i](void *s, AsyncClient *c, uint32_t time) { - DEBUG_MSG_P(PSTR("[TELNET] Timeout on client #%d at %i\n"), i, time); + DEBUG_MSG_P(PSTR("[TELNET] Timeout on client #%u at %lu\n"), i, time); c->close(); }, 0); - DEBUG_MSG_P(PSTR("[TELNET] Client #%d connected\n"), i); + DEBUG_MSG_P(PSTR("[TELNET] Client #%u connected\n"), i); wifiReconnectCheck(); return; diff --git a/code/espurna/thinkspeak.ino b/code/espurna/thinkspeak.ino index 9c689005..294ed76f 100644 --- a/code/espurna/thinkspeak.ino +++ b/code/espurna/thinkspeak.ino @@ -219,7 +219,7 @@ bool tspkEnqueueRelay(unsigned char index, unsigned char status) { if (!_tspk_enabled) return true; unsigned char id = getSetting("tspkRelay", index, 0).toInt(); if (id > 0) { - char payload[3]; + char payload[3] = {0}; itoa(status ? 1 : 0, payload, 10); _tspkEnqueue(id, payload); } diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index cb1ebcd5..ab542d87 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -158,10 +158,10 @@ void heartbeat() { // ------------------------------------------------------------------------- if (serial) { - DEBUG_MSG_P(PSTR("[MAIN] Uptime: %ld seconds\n"), uptime_seconds); - DEBUG_MSG_P(PSTR("[MAIN] Free heap: %d bytes\n"), free_heap); + DEBUG_MSG_P(PSTR("[MAIN] Uptime: %lu seconds\n"), uptime_seconds); + DEBUG_MSG_P(PSTR("[MAIN] Free heap: %lu bytes\n"), free_heap); #if ADC_VCC_ENABLED - DEBUG_MSG_P(PSTR("[MAIN] Power: %d mV\n"), ESP.getVcc()); + DEBUG_MSG_P(PSTR("[MAIN] Power: %lu mV\n"), ESP.getVcc()); #endif } #if NTP_SUPPORT