Browse Source

Checking code with cppcheck

i18n
Xose Pérez 6 years ago
parent
commit
2dc2b7d176
23 changed files with 75 additions and 75 deletions
  1. +1
    -1
      code/espurna/alexa.ino
  2. +4
    -7
      code/espurna/button.ino
  3. +5
    -5
      code/espurna/debug.ino
  4. +4
    -4
      code/espurna/domoticz.ino
  5. +2
    -2
      code/espurna/espurna.ino
  6. +5
    -5
      code/espurna/gpio.ino
  7. +1
    -1
      code/espurna/i2c.ino
  8. +1
    -1
      code/espurna/influxdb.ino
  9. +0
    -3
      code/espurna/led.ino
  10. +1
    -1
      code/espurna/libs/StreamInjector.h
  11. +3
    -3
      code/espurna/mdns.ino
  12. +8
    -2
      code/espurna/sensor.ino
  13. +7
    -7
      code/espurna/sensors/DHTSensor.h
  14. +5
    -5
      code/espurna/sensors/DallasSensor.h
  15. +3
    -3
      code/espurna/sensors/ECH1560Sensor.h
  16. +1
    -1
      code/espurna/sensors/EmonADS1X15Sensor.h
  17. +8
    -8
      code/espurna/sensors/HLW8012Sensor.h
  18. +2
    -2
      code/espurna/sensors/MHZ19Sensor.h
  19. +5
    -5
      code/espurna/sensors/PMSX003Sensor.h
  20. +2
    -2
      code/espurna/sensors/V9261FSensor.h
  21. +3
    -3
      code/espurna/telnet.ino
  22. +1
    -1
      code/espurna/thinkspeak.ino
  23. +3
    -3
      code/espurna/utils.ino

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

@ -76,7 +76,7 @@ void alexaLoop() {
while (!_alexa_dev_changes.empty()) { while (!_alexa_dev_changes.empty()) {
AlexaDevChange& change = _alexa_dev_changes.front(); 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); relayStatus(change.device_id, change.state);
_alexa_dev_changes.pop(); _alexa_dev_changes.pop();
} }


+ 4
- 7
code/espurna/button.ino View File

@ -26,7 +26,7 @@ std::vector<button_t> _buttons;
void buttonMQTT(unsigned char id, uint8_t event) { void buttonMQTT(unsigned char id, uint8_t event) {
if (id >= _buttons.size()) return; if (id >= _buttons.size()) return;
char payload[2]; char payload[2];
snprintf_P(payload, sizeof(payload), PSTR("%d"), event);
itoa(event, payload, 10);
mqttSend(MQTT_TOPIC_BUTTON, id, payload); mqttSend(MQTT_TOPIC_BUTTON, id, payload);
} }
#endif #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) { 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 (event == 0) return;
#if MQTT_SUPPORT #if MQTT_SUPPORT
@ -182,7 +182,7 @@ void buttonSetup() {
#endif #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 #ifdef ITEAD_SONOFF_DUAL
if (Serial.available() >= 4) { if (Serial.available() >= 4) {
unsigned char value;
if (Serial.read() == 0xA0) { if (Serial.read() == 0xA0) {
if (Serial.read() == 0x04) { if (Serial.read() == 0x04) {
value = Serial.read();
unsigned char value = Serial.read();
if (Serial.read() == 0xA1) { if (Serial.read() == 0xA1) {
// RELAYs and BUTTONs are synchonized in the SIL F330 // RELAYs and BUTTONs are synchonized in the SIL F330
@ -228,7 +226,6 @@ void buttonLoop() {
} }
} }
} }
} }
#else #else


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

@ -50,7 +50,7 @@ void debugSend(const char * format, ...) {
_telnetWrite(buffer, strlen(buffer)); _telnetWrite(buffer, strlen(buffer));
#endif #endif
free(buffer);
delete[] buffer;
} }
@ -87,7 +87,7 @@ void debugSend_P(PGM_P format_P, ...) {
_telnetWrite(buffer, strlen(buffer)); _telnetWrite(buffer, strlen(buffer));
#endif #endif
free(buffer);
delete[] buffer;
} }
@ -188,9 +188,9 @@ void debugDumpCrashInfo() {
return; 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; uint32_t epc1, epc2, epc3, excvaddr, depc;
EEPROM.get(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_EPC1, epc1); EEPROM.get(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_EPC1, epc1);


+ 4
- 4
code/espurna/domoticz.ino View File

@ -64,7 +64,7 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload)
int relayID = _domoticzRelay(idx); int relayID = _domoticzRelay(idx);
if (relayID >= 0) { if (relayID >= 0) {
unsigned long value = root["nvalue"]; 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); relayStatus(relayID, value == 1);
} }
@ -117,7 +117,7 @@ template<typename T> void domoticzSend(const char * key, T nvalue, const char *
unsigned int idx = getSetting(key).toInt(); unsigned int idx = getSetting(key).toInt();
if (idx > 0) { if (idx > 0) {
char payload[128]; 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); mqttSendRaw(getSetting("dczTopicIn", DOMOTICZ_IN_TOPIC).c_str(), payload);
} }
} }
@ -129,13 +129,13 @@ template<typename T> void domoticzSend(const char * key, T nvalue) {
void domoticzSendRelay(unsigned int relayID) { void domoticzSendRelay(unsigned int relayID) {
if (!_dcz_enabled) return; if (!_dcz_enabled) return;
char buffer[15]; 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"); domoticzSend(buffer, relayStatus(relayID) ? "1" : "0");
} }
int domoticzIdx(unsigned int relayID) { int domoticzIdx(unsigned int relayID) {
char buffer[15]; 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(); return getSetting(buffer).toInt();
} }


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

@ -79,7 +79,7 @@ void welcome() {
DEBUG_MSG_P(PSTR("[INIT] %s\n"), (char *) APP_AUTHOR); 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] %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 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] SDK version: %s\n"), ESP.getSdkVersion());
DEBUG_MSG_P(PSTR("[INIT] Core version: %s\n"), getCoreVersion().c_str()); DEBUG_MSG_P(PSTR("[INIT] Core version: %s\n"), getCoreVersion().c_str());
DEBUG_MSG_P(PSTR("[INIT] Core revision: %s\n"), getCoreRevision().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()); DEBUG_MSG_P(PSTR("[INIT] Free heap: %u bytes\n"), getFreeHeap());
#if ADC_VCC_ENABLED #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 #endif
DEBUG_MSG_P(PSTR("[INIT] Power saving delay value: %lu ms\n"), _loopDelay); DEBUG_MSG_P(PSTR("[INIT] Power saving delay value: %lu ms\n"), _loopDelay);


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

@ -9,7 +9,7 @@ Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com>
unsigned int _gpio_locked = 0; unsigned int _gpio_locked = 0;
bool gpioValid(unsigned char gpio) { bool gpioValid(unsigned char gpio) {
if (0 <= gpio && gpio <= 5) return true;
if (gpio <= 5) return true;
if (12 <= gpio && gpio <= 15) return true; if (12 <= gpio && gpio <= 15) return true;
return false; return false;
} }
@ -19,11 +19,11 @@ bool gpioGetLock(unsigned char gpio) {
unsigned int mask = 1 << gpio; unsigned int mask = 1 << gpio;
if ((_gpio_locked & mask) == 0) { if ((_gpio_locked & mask) == 0) {
_gpio_locked |= mask; _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; 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; return false;
} }
@ -31,9 +31,9 @@ bool gpioReleaseLock(unsigned char gpio) {
if (gpioValid(gpio)) { if (gpioValid(gpio)) {
unsigned int mask = 1 << gpio; unsigned int mask = 1 << gpio;
_gpio_locked &= ~mask; _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; 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; return false;
} }

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

@ -194,7 +194,7 @@ void i2cSetup() {
Wire.begin(sda, scl); Wire.begin(sda, scl);
#endif #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);
} }


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

@ -49,7 +49,7 @@ template<typename T> bool idbSend(const char * topic, T payload) {
int port = getSetting("idbPort", INFLUXDB_PORT).toInt(); 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); _idb_client.setTimeout(2);
if (!_idb_client.connect(host, port)) { if (!_idb_client.connect(host, port)) {
DEBUG_MSG("[INFLUXDB] Connection failed\n"); DEBUG_MSG("[INFLUXDB] Connection failed\n");


+ 0
- 3
code/espurna/led.ino View File

@ -30,7 +30,6 @@ bool _ledStatus(unsigned char id) {
bool _ledStatus(unsigned char id, bool status) { bool _ledStatus(unsigned char id, bool status) {
if (id >=_ledCount()) return false; if (id >=_ledCount()) return false;
bool s = _leds[id].reverse ? !status : status;
digitalWrite(_leds[id].pin, _leds[id].reverse ? !status : status); digitalWrite(_leds[id].pin, _leds[id].reverse ? !status : status);
return status; return status;
} }
@ -69,8 +68,6 @@ void _ledWebSocketOnSend(JsonObject& root) {
#if MQTT_SUPPORT #if MQTT_SUPPORT
void _ledMQTTCallback(unsigned int type, const char * topic, const char * payload) { void _ledMQTTCallback(unsigned int type, const char * topic, const char * payload) {
static bool isFirstMessage = true;
if (type == MQTT_CONNECT_EVENT) { if (type == MQTT_CONNECT_EVENT) {
char buffer[strlen(MQTT_TOPIC_LED) + 3]; char buffer[strlen(MQTT_TOPIC_LED) + 3];
snprintf_P(buffer, sizeof(buffer), PSTR("%s/+"), MQTT_TOPIC_LED); snprintf_P(buffer, sizeof(buffer), PSTR("%s/+"), MQTT_TOPIC_LED);


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

@ -12,7 +12,7 @@ class StreamInjector : public Stream {
typedef std::function<void(uint8_t ch)> writeCallback; typedef std::function<void(uint8_t ch)> writeCallback;
StreamInjector(Stream& serial) : _stream(serial) {}
StreamInjector(Stream& serial) : _stream(serial), _buffer() {}
virtual void callback(writeCallback c) { virtual void callback(writeCallback c) {
_callback = c; _callback = c;


+ 3
- 3
code/espurna/mdns.ino View File

@ -52,17 +52,17 @@ void mdnsServerSetup() {
MDNS.addServiceTxt("arduino", "tcp", "app_version", APP_VERSION); MDNS.addServiceTxt("arduino", "tcp", "app_version", APP_VERSION);
MDNS.addServiceTxt("arduino", "tcp", "target_board", getBoardName()); MDNS.addServiceTxt("arduino", "tcp", "target_board", getBoardName());
{ {
char buffer[6];
char buffer[6] = {0};
itoa(ESP.getFlashChipRealSize() / 1024, buffer, 10); itoa(ESP.getFlashChipRealSize() / 1024, buffer, 10);
MDNS.addServiceTxt("arduino", "tcp", "mem_size", (const char *) buffer); MDNS.addServiceTxt("arduino", "tcp", "mem_size", (const char *) buffer);
} }
{ {
char buffer[6];
char buffer[6] = {0};
itoa(ESP.getFlashChipSize() / 1024, buffer, 10); itoa(ESP.getFlashChipSize() / 1024, buffer, 10);
MDNS.addServiceTxt("arduino", "tcp", "sdk_size", (const char *) buffer); MDNS.addServiceTxt("arduino", "tcp", "sdk_size", (const char *) buffer);
} }
{ {
char buffer[6];
char buffer[6] = {0};
itoa(ESP.getFreeSketchSpace(), buffer, 10); itoa(ESP.getFreeSketchSpace(), buffer, 10);
MDNS.addServiceTxt("arduino", "tcp", "free_space", (const char *) buffer); MDNS.addServiceTxt("arduino", "tcp", "free_space", (const char *) buffer);
} }


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

@ -416,13 +416,13 @@ void _sensorInit() {
void _sensorConfigure() { void _sensorConfigure() {
double value;
for (unsigned char i=0; i<_sensors.size(); i++) { for (unsigned char i=0; i<_sensors.size(); i++) {
#if EMON_ANALOG_SUPPORT #if EMON_ANALOG_SUPPORT
if (_sensors[i]->getID() == SENSOR_EMON_ANALOG_ID) { if (_sensors[i]->getID() == SENSOR_EMON_ANALOG_ID) {
double value;
EmonAnalogSensor * sensor = (EmonAnalogSensor *) _sensors[i]; EmonAnalogSensor * sensor = (EmonAnalogSensor *) _sensors[i];
if (value = getSetting("pwrExpectedP", 0).toInt() == 0) { if (value = getSetting("pwrExpectedP", 0).toInt() == 0) {
@ -442,14 +442,18 @@ void _sensorConfigure() {
} }
#endif // EMON_ANALOG_SUPPORT #endif // EMON_ANALOG_SUPPORT
// Force sensor to reload config // Force sensor to reload config
_sensors[i]->begin(); _sensors[i]->begin();
#if HLW8012_SUPPORT #if HLW8012_SUPPORT
if (_sensors[i]->getID() == SENSOR_HLW8012_ID) { if (_sensors[i]->getID() == SENSOR_HLW8012_ID) {
double value;
HLW8012Sensor * sensor = (HLW8012Sensor *) _sensors[i]; HLW8012Sensor * sensor = (HLW8012Sensor *) _sensors[i];
if (value = getSetting("pwrExpectedC", 0).toFloat()) { if (value = getSetting("pwrExpectedC", 0).toFloat()) {
@ -484,7 +488,9 @@ void _sensorConfigure() {
} }
} }
#endif // HLW8012_SUPPORT #endif // HLW8012_SUPPORT
} }
// General sensor settings // General sensor settings


+ 7
- 7
code/espurna/sensors/DHTSensor.h View File

@ -33,7 +33,7 @@ class DHTSensor : public BaseSensor {
} }
~DHTSensor() { ~DHTSensor() {
if (_previous != 0xFF) gpioReleaseLock(_previous);
if (_previous != GPIO_NONE) gpioReleaseLock(_previous);
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@ -66,8 +66,8 @@ class DHTSensor : public BaseSensor {
_count = 0; _count = 0;
// Manage GPIO lock // Manage GPIO lock
if (_previous != 0xFF) gpioReleaseLock(_previous);
_previous = 0xFF;
if (_previous != GPIO_NONE) gpioReleaseLock(_previous);
_previous = GPIO_NONE;
if (!gpioGetLock(_gpio)) { if (!gpioGetLock(_gpio)) {
_error = SENSOR_ERROR_GPIO_USED; _error = SENSOR_ERROR_GPIO_USED;
return; return;
@ -232,15 +232,15 @@ class DHTSensor : public BaseSensor {
return uSec; 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 char _type = DHT_CHIP_DHT22;
unsigned long _last_ok = 0; unsigned long _last_ok = 0;
unsigned char _errors = 0; unsigned char _errors = 0;
double _temperature;
unsigned int _humidity;
double _temperature = 0;
unsigned int _humidity = 0;
}; };


+ 5
- 5
code/espurna/sensors/DallasSensor.h View File

@ -41,7 +41,7 @@ class DallasSensor : public BaseSensor {
~DallasSensor() { ~DallasSensor() {
if (_wire) delete _wire; 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; _dirty = false;
// Manage GPIO lock // Manage GPIO lock
if (_previous != 0xFF) gpioReleaseLock(_previous);
_previous = 0xFF;
if (_previous != GPIO_NONE) gpioReleaseLock(_previous);
_previous = GPIO_NONE;
if (!gpioGetLock(_gpio)) { if (!gpioGetLock(_gpio)) {
_error = SENSOR_ERROR_GPIO_USED; _error = SENSOR_ERROR_GPIO_USED;
return; return;
@ -311,8 +311,8 @@ class DallasSensor : public BaseSensor {
} ds_device_t; } ds_device_t;
std::vector<ds_device_t> _devices; std::vector<ds_device_t> _devices;
unsigned char _gpio;
unsigned char _previous = 0xFF;
unsigned char _gpio = GPIO_NONE;
unsigned char _previous = GPIO_NONE;
OneWire * _wire = NULL; OneWire * _wire = NULL;
}; };


+ 3
- 3
code/espurna/sensors/ECH1560Sensor.h View File

@ -18,7 +18,7 @@ class ECH1560Sensor : public BaseSensor {
// Public // Public
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
ECH1560Sensor(): BaseSensor() {
ECH1560Sensor(): BaseSensor(), _data() {
_count = 3; _count = 3;
_sensor_id = SENSOR_ECH1560_ID; _sensor_id = SENSOR_ECH1560_ID;
} }
@ -78,7 +78,7 @@ class ECH1560Sensor : public BaseSensor {
// Descriptive name of the sensor // Descriptive name of the sensor
String description() { String description() {
char buffer[25]; 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); return String(buffer);
} }
@ -90,7 +90,7 @@ class ECH1560Sensor : public BaseSensor {
// Address of the sensor (it could be the GPIO or I2C address) // Address of the sensor (it could be the GPIO or I2C address)
String address(unsigned char index) { String address(unsigned char index) {
char buffer[6]; char buffer[6];
snprintf(buffer, sizeof(buffer), "%i:%i", _clk, _miso);
snprintf(buffer, sizeof(buffer), "%u:%u", _clk, _miso);
return String(buffer); return String(buffer);
} }


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

@ -207,7 +207,7 @@ class EmonADS1X15Sensor : public EmonSensor {
String address(unsigned char index) { String address(unsigned char index) {
char buffer[10]; char buffer[10];
unsigned char channel = getChannel(index % _ports); 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); return String(buffer);
} }


+ 8
- 8
code/espurna/sensors/HLW8012Sensor.h View File

@ -158,7 +158,7 @@ class HLW8012Sensor : public BaseSensor {
// Descriptive name of the sensor // Descriptive name of the sensor
String description() { String description() {
char buffer[25]; 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); return String(buffer);
} }
@ -170,7 +170,7 @@ class HLW8012Sensor : public BaseSensor {
// Address of the sensor (it could be the GPIO or I2C address) // Address of the sensor (it could be the GPIO or I2C address)
String address(unsigned char index) { String address(unsigned char index) {
char buffer[10]; 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); 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; HLW8012 * _hlw8012 = NULL;
@ -307,7 +307,7 @@ void HLW8012Sensor::_attach(HLW8012Sensor * instance, unsigned char gpio, unsign
_hlw8012_sensor_instance[index] = instance; _hlw8012_sensor_instance[index] = instance;
attachInterrupt(gpio, _hlw8012_sensor_isr_list[index], mode); attachInterrupt(gpio, _hlw8012_sensor_isr_list[index], mode);
#if SENSOR_DEBUG #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 #endif
} }
@ -317,7 +317,7 @@ void HLW8012Sensor::_detach(unsigned char gpio) {
if (_hlw8012_sensor_instance[index]) { if (_hlw8012_sensor_instance[index]) {
detachInterrupt(gpio); detachInterrupt(gpio);
#if SENSOR_DEBUG #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 #endif
_hlw8012_sensor_instance[index] = NULL; _hlw8012_sensor_instance[index] = NULL;
} }


+ 2
- 2
code/espurna/sensors/MHZ19Sensor.h View File

@ -85,7 +85,7 @@ class MHZ19Sensor : public BaseSensor {
// Descriptive name of the sensor // Descriptive name of the sensor
String description() { String description() {
char buffer[28]; 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); return String(buffer);
} }
@ -97,7 +97,7 @@ class MHZ19Sensor : public BaseSensor {
// Address of the sensor (it could be the GPIO or I2C address) // Address of the sensor (it could be the GPIO or I2C address)
String address(unsigned char index) { String address(unsigned char index) {
char buffer[6]; 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); return String(buffer);
} }


+ 5
- 5
code/espurna/sensors/PMSX003Sensor.h View File

@ -79,7 +79,7 @@ class PMSX003Sensor : public BaseSensor {
// Descriptive name of the sensor // Descriptive name of the sensor
String description() { String description() {
char buffer[28]; 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); return String(buffer);
} }
@ -88,9 +88,9 @@ class PMSX003Sensor : public BaseSensor {
if (index < _count) { if (index < _count) {
_error = SENSOR_ERROR_OK; _error = SENSOR_ERROR_OK;
char buffer[36]; 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); return String(buffer);
} }
_error = SENSOR_ERROR_OUT_OF_RANGE; _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) // Address of the sensor (it could be the GPIO or I2C address)
String address(unsigned char index) { String address(unsigned char index) {
char buffer[6]; 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); return String(buffer);
} }


+ 2
- 2
code/espurna/sensors/V9261FSensor.h View File

@ -20,7 +20,7 @@ class V9261FSensor : public BaseSensor {
// Public // Public
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
V9261FSensor(): BaseSensor() {
V9261FSensor(): BaseSensor(), _data() {
_count = 6; _count = 6;
_sensor_id = SENSOR_V9261F_ID; _sensor_id = SENSOR_V9261F_ID;
} }
@ -73,7 +73,7 @@ class V9261FSensor : public BaseSensor {
// Descriptive name of the sensor // Descriptive name of the sensor
String description() { String description() {
char buffer[28]; 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); return String(buffer);
} }


+ 3
- 3
code/espurna/telnet.ino View File

@ -93,15 +93,15 @@ void _telnetNewClient(AsyncClient *client) {
}, 0); }, 0);
client->onError([i](void *s, AsyncClient *c, int8_t error) { 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); }, 0);
client->onTimeout([i](void *s, AsyncClient *c, uint32_t time) { 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(); c->close();
}, 0); }, 0);
DEBUG_MSG_P(PSTR("[TELNET] Client #%d connected\n"), i);
DEBUG_MSG_P(PSTR("[TELNET] Client #%u connected\n"), i);
wifiReconnectCheck(); wifiReconnectCheck();
return; return;


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

@ -219,7 +219,7 @@ bool tspkEnqueueRelay(unsigned char index, unsigned char status) {
if (!_tspk_enabled) return true; if (!_tspk_enabled) return true;
unsigned char id = getSetting("tspkRelay", index, 0).toInt(); unsigned char id = getSetting("tspkRelay", index, 0).toInt();
if (id > 0) { if (id > 0) {
char payload[3];
char payload[3] = {0};
itoa(status ? 1 : 0, payload, 10); itoa(status ? 1 : 0, payload, 10);
_tspkEnqueue(id, payload); _tspkEnqueue(id, payload);
} }


+ 3
- 3
code/espurna/utils.ino View File

@ -158,10 +158,10 @@ void heartbeat() {
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
if (serial) { 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 #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 #endif
} }
#if NTP_SUPPORT #if NTP_SUPPORT


Loading…
Cancel
Save