Browse Source

Align left dtostrf output

fastled
Xose Pérez 7 years ago
parent
commit
b03af79ffd
6 changed files with 14 additions and 15 deletions
  1. +2
    -2
      code/espurna/dht.ino
  2. +2
    -2
      code/espurna/ds18b20.ino
  3. +1
    -1
      code/espurna/emon.ino
  4. +1
    -1
      code/espurna/hlw8012.ino
  5. +5
    -5
      code/espurna/v9261f.ino
  6. +3
    -4
      code/espurna/web.ino

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

@ -34,7 +34,7 @@ void dhtSetup() {
#if WEB_SUPPORT #if WEB_SUPPORT
apiRegister(DHT_TEMPERATURE_TOPIC, DHT_TEMPERATURE_TOPIC, [](char * buffer, size_t len) { apiRegister(DHT_TEMPERATURE_TOPIC, DHT_TEMPERATURE_TOPIC, [](char * buffer, size_t len) {
dtostrf(_dhtTemperature, len-1, 1, buffer);
dtostrf(_dhtTemperature, 1-len, 1, buffer);
}); });
apiRegister(DHT_HUMIDITY_TOPIC, DHT_HUMIDITY_TOPIC, [](char * buffer, size_t len) { apiRegister(DHT_HUMIDITY_TOPIC, DHT_HUMIDITY_TOPIC, [](char * buffer, size_t len) {
snprintf_P(buffer, len, PSTR("%d"), _dhtHumidity); snprintf_P(buffer, len, PSTR("%d"), _dhtHumidity);
@ -68,7 +68,7 @@ void dhtLoop() {
char temperature[6]; char temperature[6];
char humidity[6]; char humidity[6];
dtostrf(t, 4, 1, temperature);
dtostrf(t, 1-sizeof(temperature), 1, temperature);
itoa((unsigned int) h, humidity, 10); itoa((unsigned int) h, humidity, 10);
DEBUG_MSG_P(PSTR("[DHT] Temperature: %s%s\n"), temperature, (tmpUnits == TMP_CELSIUS) ? "ºC" : "ºF"); DEBUG_MSG_P(PSTR("[DHT] Temperature: %s%s\n"), temperature, (tmpUnits == TMP_CELSIUS) ? "ºC" : "ºF");


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

@ -40,7 +40,7 @@ void dsSetup() {
#if WEB_SUPPORT #if WEB_SUPPORT
apiRegister(DS18B20_TEMPERATURE_TOPIC, DS18B20_TEMPERATURE_TOPIC, [](char * buffer, size_t len) { apiRegister(DS18B20_TEMPERATURE_TOPIC, DS18B20_TEMPERATURE_TOPIC, [](char * buffer, size_t len) {
dtostrf(_dsTemperature, len-1, 1, buffer);
dtostrf(_dsTemperature, 1-len, 1, buffer);
}); });
#endif #endif
@ -89,7 +89,7 @@ void dsLoop() {
else else
_dsIsConnected = true; _dsIsConnected = true;
dtostrf(t, 5, 1, _dsTemperatureStr);
dtostrf(t, 1-sizeof(_dsTemperatureStr), 1, _dsTemperatureStr);
DEBUG_MSG_P(PSTR("[DS18B20] Temperature: %s%s\n"), DEBUG_MSG_P(PSTR("[DS18B20] Temperature: %s%s\n"),
getDSTemperatureStr(), getDSTemperatureStr(),


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

@ -116,7 +116,7 @@ void powerMonitorSetup() {
apiRegister(EMON_CURRENT_TOPIC, EMON_CURRENT_TOPIC, [](char * buffer, size_t len) { apiRegister(EMON_CURRENT_TOPIC, EMON_CURRENT_TOPIC, [](char * buffer, size_t len) {
if (_emonReady) { if (_emonReady) {
dtostrf(_emonCurrent, len-1, 3, buffer);
dtostrf(_emonCurrent, 1-len, 3, buffer);
} else { } else {
buffer = NULL; buffer = NULL;
} }


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

@ -170,7 +170,7 @@ void hlw8012Setup() {
}); });
apiRegister(HLW8012_CURRENT_TOPIC, HLW8012_CURRENT_TOPIC, [](char * buffer, size_t len) { apiRegister(HLW8012_CURRENT_TOPIC, HLW8012_CURRENT_TOPIC, [](char * buffer, size_t len) {
if (_hlwReady) { if (_hlwReady) {
dtostrf(_hlwCurrent, len-1, 3, buffer);
dtostrf(_hlwCurrent, 1-len, 3, buffer);
} else { } else {
buffer = NULL; buffer = NULL;
} }


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

@ -193,7 +193,7 @@ void v9261fSetup() {
snprintf_P(buffer, len, PSTR("%d"), _v9261f_power); snprintf_P(buffer, len, PSTR("%d"), _v9261f_power);
}); });
apiRegister(HLW8012_CURRENT_TOPIC, HLW8012_CURRENT_TOPIC, [](char * buffer, size_t len) { apiRegister(HLW8012_CURRENT_TOPIC, HLW8012_CURRENT_TOPIC, [](char * buffer, size_t len) {
dtostrf(_v9261f_current, len-1, 3, buffer);
dtostrf(_v9261f_current, 1-len, 3, buffer);
}); });
apiRegister(HLW8012_VOLTAGE_TOPIC, HLW8012_VOLTAGE_TOPIC, [](char * buffer, size_t len) { apiRegister(HLW8012_VOLTAGE_TOPIC, HLW8012_VOLTAGE_TOPIC, [](char * buffer, size_t len) {
snprintf_P(buffer, len, PSTR("%d"), _v9261f_voltage); snprintf_P(buffer, len, PSTR("%d"), _v9261f_voltage);
@ -232,11 +232,11 @@ void v9261fLoop() {
JsonObject& root = jsonBuffer.createObject(); JsonObject& root = jsonBuffer.createObject();
char buf_current[10]; char buf_current[10];
dtostrf(getCurrent(), 6, 3, buf_current);
dtostrf(getCurrent(), 1-sizeof(buf_current), 3, buf_current);
root["powVisible"] = 1; root["powVisible"] = 1;
root["powActivePower"] = getActivePower(); root["powActivePower"] = getActivePower();
root["powCurrent"] = String(ltrim(buf_current));
root["powCurrent"] = String(buf_current);
root["powVoltage"] = getVoltage(); root["powVoltage"] = getVoltage();
root["powApparentPower"] = getApparentPower(); root["powApparentPower"] = getApparentPower();
root["powReactivePower"] = getReactivePower(); root["powReactivePower"] = getReactivePower();
@ -262,11 +262,11 @@ void v9261fLoop() {
unsigned int voltage = sum_voltage / count; unsigned int voltage = sum_voltage / count;
double current = sum_current / count; double current = sum_current / count;
char buf_current[10]; char buf_current[10];
dtostrf(current, 6, 3, buf_current);
dtostrf(current, 1-sizeof(buf_current), 3, buf_current);
unsigned int apparent = sqrt(power * power + reactive * reactive); unsigned int apparent = sqrt(power * power + reactive * reactive);
double energy_delta = (double) power * V9261F_REPORT_INTERVAL / 1000.0 / 3600.0; double energy_delta = (double) power * V9261F_REPORT_INTERVAL / 1000.0 / 3600.0;
char buf_energy[10]; char buf_energy[10];
dtostrf(energy_delta, 6, 3, buf_energy);
dtostrf(energy_delta, 1-sizeof(buf_energy), 3, buf_energy);
unsigned int factor = 100 * ((double) power / apparent); unsigned int factor = 100 * ((double) power / apparent);
// Report values to MQTT broker // Report values to MQTT broker


+ 3
- 4
code/espurna/web.ino View File

@ -809,7 +809,6 @@ ArRequestHandlerFunction _bindAPI(unsigned int apiID) {
// Get response from callback // Get response from callback
char value[API_BUFFER_SIZE]; char value[API_BUFFER_SIZE];
(api.getFn)(value, API_BUFFER_SIZE); (api.getFn)(value, API_BUFFER_SIZE);
char *p = ltrim(value);
// The response will be a 404 NOT FOUND if the resource is not available // The response will be a 404 NOT FOUND if the resource is not available
if (!value) { if (!value) {
@ -817,15 +816,15 @@ ArRequestHandlerFunction _bindAPI(unsigned int apiID) {
request->send(404); request->send(404);
return; return;
} }
DEBUG_MSG_P(PSTR("[API] Sending response '%s'\n"), p);
DEBUG_MSG_P(PSTR("[API] Sending response '%s'\n"), value);
// Format response according to the Accept header // Format response according to the Accept header
if (_asJson(request)) { if (_asJson(request)) {
char buffer[64]; char buffer[64];
snprintf_P(buffer, sizeof(buffer), PSTR("{ \"%s\": %s }"), api.key, p);
snprintf_P(buffer, sizeof(buffer), PSTR("{ \"%s\": %s }"), api.key, value);
request->send(200, "application/json", buffer); request->send(200, "application/json", buffer);
} else { } else {
request->send(200, "text/plain", p);
request->send(200, "text/plain", value);
} }
}; };


Loading…
Cancel
Save