Browse Source

Using strlen with snprintf statements

fastled
Xose Pérez 7 years ago
parent
commit
4ccdeb3526
4 changed files with 9 additions and 9 deletions
  1. +1
    -1
      code/espurna/domoticz.ino
  2. +3
    -3
      code/espurna/emon.ino
  3. +4
    -4
      code/espurna/hlw8012.ino
  4. +1
    -1
      code/espurna/web.ino

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

@ -72,7 +72,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, 128, "{\"idx\": %d, \"nvalue\": %s, \"svalue\": \"%s\"}", idx, String(nvalue).c_str(), svalue);
snprintf(payload, strlen(payload), "{\"idx\": %d, \"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);
} }
} }


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

@ -191,11 +191,11 @@ void powerMonitorLoop() {
#if ENABLE_DOMOTICZ #if ENABLE_DOMOTICZ
{ {
char buffer[20]; char buffer[20];
snprintf_P(buffer, 20, PSTR("%d;%s"), _emonPower, String(energy_delta, 3).c_str());
snprintf_P(buffer, strlen(buffer), PSTR("%d;%s"), _emonPower, String(energy_delta, 3).c_str());
domoticzSend("dczPowIdx", 0, buffer); domoticzSend("dczPowIdx", 0, buffer);
snprintf_P(buffer, 20, PSTR("%s"), String(energy_delta, 3).c_str());
snprintf_P(buffer, strlen(buffer), PSTR("%s"), String(energy_delta, 3).c_str());
domoticzSend("dczEnergyIdx", 0, buffer); domoticzSend("dczEnergyIdx", 0, buffer);
snprintf_P(buffer, 20, PSTR("%s"), String(_emonCurrent, 3).c_str());
snprintf_P(buffer, strlen(buffer), PSTR("%s"), String(_emonCurrent, 3).c_str());
domoticzSend("dczCurrentIdx", 0, buffer); domoticzSend("dczCurrentIdx", 0, buffer);
} }
#endif #endif


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

@ -295,13 +295,13 @@ void hlw8012Loop() {
#if ENABLE_DOMOTICZ #if ENABLE_DOMOTICZ
{ {
char buffer[20]; char buffer[20];
snprintf_P(buffer, 20, PSTR("%d;%s"), _hlwPower, String(energy_delta, 3).c_str());
snprintf_P(buffer, strlen(buffer), PSTR("%d;%s"), _hlwPower, String(energy_delta, 3).c_str());
domoticzSend("dczPowIdx", 0, buffer); domoticzSend("dczPowIdx", 0, buffer);
snprintf_P(buffer, 20, PSTR("%s"), String(energy_delta, 3).c_str());
snprintf_P(buffer, strlen(buffer), PSTR("%s"), String(energy_delta, 3).c_str());
domoticzSend("dczEnergyIdx", 0, buffer); domoticzSend("dczEnergyIdx", 0, buffer);
snprintf_P(buffer, 20, PSTR("%d"), _hlwVoltage);
snprintf_P(buffer, strlen(buffer), PSTR("%d"), _hlwVoltage);
domoticzSend("dczVoltIdx", 0, buffer); domoticzSend("dczVoltIdx", 0, buffer);
snprintf_P(buffer, 20, PSTR("%s"), String(_hlwCurrent).c_str());
snprintf_P(buffer, strlen(buffer), PSTR("%s"), String(_hlwCurrent).c_str());
domoticzSend("dczCurrentIdx", 0, buffer); domoticzSend("dczCurrentIdx", 0, buffer);
} }
#endif #endif


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

@ -762,7 +762,7 @@ void apiRegister(const char * url, const char * key, apiGetCallbackFunction getF
// Store it // Store it
web_api_t api; web_api_t api;
char buffer[40]; char buffer[40];
snprintf_P(buffer, 39, PSTR("/api/%s"), url);
snprintf_P(buffer, strlen(buffer), PSTR("/api/%s"), url);
api.url = strdup(buffer); api.url = strdup(buffer);
api.key = strdup(key); api.key = strdup(key);
api.getFn = getFn; api.getFn = getFn;


Loading…
Cancel
Save