Browse Source

Fix bug using snprintf

fastled
Xose Pérez 7 years ago
parent
commit
68c90c1cc0
16 changed files with 50 additions and 48 deletions
  1. +1
    -1
      code/espurna/analog.ino
  2. +1
    -1
      code/espurna/button.ino
  3. +2
    -2
      code/espurna/dht.ino
  4. +3
    -3
      code/espurna/domoticz.ino
  5. +1
    -1
      code/espurna/ds18b20.ino
  6. +4
    -4
      code/espurna/emon.ino
  7. +1
    -1
      code/espurna/espurna.ino
  8. +5
    -5
      code/espurna/hlw8012.ino
  9. +2
    -2
      code/espurna/influxdb.ino
  10. +1
    -1
      code/espurna/led.ino
  11. +5
    -5
      code/espurna/light.ino
  12. +1
    -1
      code/espurna/mqtt.ino
  13. +1
    -1
      code/espurna/ntp.ino
  14. +9
    -7
      code/espurna/relay.ino
  15. +7
    -7
      code/espurna/rfbridge.ino
  16. +6
    -6
      code/espurna/web.ino

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

@ -55,7 +55,7 @@ void analogLoop() {
// Update websocket clients // Update websocket clients
#if WEB_SUPPORT #if WEB_SUPPORT
char buffer[100]; char buffer[100];
snprintf_P(buffer, strlen(buffer), PSTR("{\"analogVisible\": 1, \"analogValue\": %d}"), analog);
snprintf_P(buffer, sizeof(buffer), PSTR("{\"analogVisible\": 1, \"analogValue\": %d}"), analog);
wsSend(buffer); wsSend(buffer);
#endif #endif


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

@ -25,7 +25,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, strlen(payload), PSTR("%d"), event);
snprintf_P(payload, sizeof(payload), PSTR("%d"), event);
mqttSend(MQTT_TOPIC_BUTTON, id, payload); mqttSend(MQTT_TOPIC_BUTTON, id, payload);
} }
#endif #endif


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

@ -93,7 +93,7 @@ void dhtLoop() {
status = HUMIDITY_DRY; status = HUMIDITY_DRY;
} }
char buffer[2]; char buffer[2];
snprintf_P(buffer, strlen(buffer), PSTR("%d"), status);
snprintf_P(buffer, sizeof(buffer), PSTR("%d"), status);
domoticzSend("dczHumIdx", humidity, buffer); domoticzSend("dczHumIdx", humidity, buffer);
} }
#endif #endif
@ -106,7 +106,7 @@ void dhtLoop() {
// Update websocket clients // Update websocket clients
#if WEB_SUPPORT #if WEB_SUPPORT
char buffer[100]; char buffer[100];
snprintf_P(buffer, strlen(buffer), PSTR("{\"dhtVisible\": 1, \"dhtTmp\": %s, \"dhtHum\": %s, \"tmpUnits\": %d}"), temperature, humidity, tmpUnits);
snprintf_P(buffer, sizeof(buffer), PSTR("{\"dhtVisible\": 1, \"dhtTmp\": %s, \"dhtHum\": %s, \"tmpUnits\": %d}"), temperature, humidity, tmpUnits);
wsSend(buffer); wsSend(buffer);
#endif #endif


+ 3
- 3
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, strlen(payload), "{\"idx\": %d, \"nvalue\": %s, \"svalue\": \"%s\"}", idx, String(nvalue).c_str(), svalue);
snprintf(payload, sizeof(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);
} }
} }
@ -84,13 +84,13 @@ template<typename T> void domoticzSend(const char * key, T nvalue) {
void domoticzSendRelay(unsigned int relayID) { void domoticzSendRelay(unsigned int relayID) {
if (!_dczEnabled) return; if (!_dczEnabled) return;
char buffer[15]; char buffer[15];
snprintf_P(buffer, strlen(buffer), PSTR("dczRelayIdx%d"), relayID);
snprintf_P(buffer, sizeof(buffer), PSTR("dczRelayIdx%d"), 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, strlen(buffer), PSTR("dczRelayIdx%d"), relayID);
snprintf_P(buffer, sizeof(buffer), PSTR("dczRelayIdx%d"), relayID);
return getSetting(buffer).toInt(); return getSetting(buffer).toInt();
} }


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

@ -110,7 +110,7 @@ void dsLoop() {
// Update websocket clients // Update websocket clients
#if WEB_SUPPORT #if WEB_SUPPORT
char buffer[100]; char buffer[100];
snprintf_P(buffer, strlen(buffer), PSTR("{\"dsVisible\": 1, \"dsTmp\": %s, \"tmpUnits\": %d}"), getDSTemperatureStr(), tmpUnits);
snprintf_P(buffer, sizeof(buffer), PSTR("{\"dsVisible\": 1, \"dsTmp\": %s, \"tmpUnits\": %d}"), getDSTemperatureStr(), tmpUnits);
wsSend(buffer); wsSend(buffer);
#endif #endif


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

@ -169,7 +169,7 @@ void powerMonitorLoop() {
// Update websocket clients // Update websocket clients
#if WEB_SUPPORT #if WEB_SUPPORT
char buffer[100]; char buffer[100];
snprintf_P(buffer, strlen(buffer), PSTR("{\"emonVisible\": 1, \"emonApparentPower\": %d, \"emonCurrent\": %s}"), int(current * voltage), String(current, 3).c_str());
snprintf_P(buffer, sizeof(buffer), PSTR("{\"emonVisible\": 1, \"emonApparentPower\": %d, \"emonCurrent\": %s}"), int(current * voltage), String(current, 3).c_str());
wsSend(buffer); wsSend(buffer);
#endif #endif
@ -195,11 +195,11 @@ void powerMonitorLoop() {
#if DOMOTICZ_SUPPORT #if DOMOTICZ_SUPPORT
{ {
char buffer[20]; char buffer[20];
snprintf_P(buffer, strlen(buffer), PSTR("%d;%s"), _emonPower, String(energy_delta, 3).c_str());
snprintf_P(buffer, sizeof(buffer), PSTR("%d;%s"), _emonPower, String(energy_delta, 3).c_str());
domoticzSend("dczPowIdx", 0, buffer); domoticzSend("dczPowIdx", 0, buffer);
snprintf_P(buffer, strlen(buffer), PSTR("%s"), String(energy_delta, 3).c_str());
snprintf_P(buffer, sizeof(buffer), PSTR("%s"), String(energy_delta, 3).c_str());
domoticzSend("dczEnergyIdx", 0, buffer); domoticzSend("dczEnergyIdx", 0, buffer);
snprintf_P(buffer, strlen(buffer), PSTR("%s"), String(_emonCurrent, 3).c_str());
snprintf_P(buffer, sizeof(buffer), PSTR("%s"), String(_emonCurrent, 3).c_str());
domoticzSend("dczCurrentIdx", 0, buffer); domoticzSend("dczCurrentIdx", 0, buffer);
} }
#endif #endif


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

@ -28,7 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
String getIdentifier() { String getIdentifier() {
char buffer[20]; char buffer[20];
snprintf_P(buffer, strlen(buffer), PSTR("%s_%06X"), DEVICE, ESP.getChipId());
snprintf_P(buffer, sizeof(buffer), PSTR("%s_%06X"), DEVICE, ESP.getChipId());
return String(buffer); return String(buffer);
} }


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

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


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

@ -28,11 +28,11 @@ template<typename T> bool influxDBSend(const char * topic, T payload) {
} }
char data[128]; char data[128];
snprintf(data, strlen(data), "%s,device=%s value=%s", topic, getSetting("hostname").c_str(), String(payload).c_str());
snprintf(data, sizeof(data), "%s,device=%s value=%s", topic, getSetting("hostname").c_str(), String(payload).c_str());
DEBUG_MSG("[INFLUXDB] Data: %s\n", data); DEBUG_MSG("[INFLUXDB] Data: %s\n", data);
char request[256]; char request[256];
snprintf(request, strlen(request), "POST /write?db=%s&u=%s&p=%s HTTP/1.1\r\nHost: %s:%d\r\nContent-Length: %d\r\n\r\n%s",
snprintf(request, sizeof(request), "POST /write?db=%s&u=%s&p=%s HTTP/1.1\r\nHost: %s:%d\r\nContent-Length: %d\r\n\r\n%s",
getSetting("idbDatabase").c_str(), getSetting("idbUsername").c_str(), getSetting("idbPassword").c_str(), getSetting("idbDatabase").c_str(), getSetting("idbUsername").c_str(), getSetting("idbPassword").c_str(),
getSetting("idbHost").c_str(), getSetting("idbPort", INFLUXDB_PORT).toInt(), getSetting("idbHost").c_str(), getSetting("idbPort", INFLUXDB_PORT).toInt(),
strlen(data), data); strlen(data), data);


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

@ -64,7 +64,7 @@ void ledMQTTCallback(unsigned int type, const char * topic, const char * payload
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, strlen(buffer), PSTR("%s/+"), MQTT_TOPIC_LED);
snprintf_P(buffer, sizeof(buffer), PSTR("%s/+"), MQTT_TOPIC_LED);
mqttSubscribe(buffer); mqttSubscribe(buffer);
} }


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

@ -293,7 +293,7 @@ void _lightMQTTCallback(unsigned int type, const char * topic, const char * payl
} }
char buffer[strlen(MQTT_TOPIC_CHANNEL) + 3]; char buffer[strlen(MQTT_TOPIC_CHANNEL) + 3];
snprintf_P(buffer, strlen(buffer), PSTR("%s/+"), MQTT_TOPIC_CHANNEL);
snprintf_P(buffer, sizeof(buffer), PSTR("%s/+"), MQTT_TOPIC_CHANNEL);
mqttSubscribe(buffer); mqttSubscribe(buffer);
} }
@ -370,14 +370,14 @@ void lightMQTT() {
mqttSend(MQTT_TOPIC_COLOR, buffer); mqttSend(MQTT_TOPIC_COLOR, buffer);
// Brightness // Brightness
snprintf_P(buffer, strlen(buffer), PSTR("%d"), _brightness);
snprintf_P(buffer, sizeof(buffer), PSTR("%d"), _brightness);
mqttSend(MQTT_TOPIC_BRIGHTNESS, buffer); mqttSend(MQTT_TOPIC_BRIGHTNESS, buffer);
} }
// Channels // Channels
for (unsigned int i=0; i < _channels.size(); i++) { for (unsigned int i=0; i < _channels.size(); i++) {
snprintf_P(buffer, strlen(buffer), PSTR("%d"), _channels[i].value);
snprintf_P(buffer, sizeof(buffer), PSTR("%d"), _channels[i].value);
mqttSend(MQTT_TOPIC_CHANNEL, i, buffer); mqttSend(MQTT_TOPIC_CHANNEL, i, buffer);
} }
@ -509,10 +509,10 @@ void _lightAPISetup() {
for (unsigned int id=0; id<lightChannels(); id++) { for (unsigned int id=0; id<lightChannels(); id++) {
char url[15]; char url[15];
snprintf_P(url, strlen(url), PSTR("%s/%d"), MQTT_TOPIC_CHANNEL, id);
snprintf_P(url, sizeof(url), PSTR("%s/%d"), MQTT_TOPIC_CHANNEL, id);
char key[10]; char key[10];
snprintf_P(key, strlen(key), PSTR("%s%d"), MQTT_TOPIC_CHANNEL, id);
snprintf_P(key, sizeof(key), PSTR("%s%d"), MQTT_TOPIC_CHANNEL, id);
apiRegister(url, key, apiRegister(url, key,
[id](char * buffer, size_t len) { [id](char * buffer, size_t len) {


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

@ -129,7 +129,7 @@ void mqttSend(const char * topic, const char * message) {
void mqttSend(const char * topic, unsigned int index, const char * message, bool force) { void mqttSend(const char * topic, unsigned int index, const char * message, bool force) {
char buffer[strlen(topic)+5]; char buffer[strlen(topic)+5];
snprintf_P(buffer, strlen(buffer), PSTR("%s/%d"), topic, index);
snprintf_P(buffer, sizeof(buffer), PSTR("%s/%d"), topic, index);
mqttSend(buffer, message, force); mqttSend(buffer, message, force);
} }


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

@ -39,7 +39,7 @@ String ntpDateTime() {
int month = value.substring(12, 14).toInt(); int month = value.substring(12, 14).toInt();
int year = value.substring(15, 19).toInt(); int year = value.substring(15, 19).toInt();
char buffer[20]; char buffer[20];
snprintf_P(buffer, strlen(buffer), PSTR("%04d/%02d/%02dT%02d:%02d:%02d"), year, month, day, hour, minute, second);
snprintf_P(buffer, sizeof(buffer), PSTR("%04d/%02d/%02dT%02d:%02d:%02d"), year, month, day, hour, minute, second);
return String(buffer); return String(buffer);
} }


+ 9
- 7
code/espurna/relay.ino View File

@ -144,16 +144,16 @@ void relayPulseMode(unsigned int value, bool report) {
/* /*
if (report) { if (report) {
char topic[strlen(MQTT_TOPIC_RELAY) + 10]; char topic[strlen(MQTT_TOPIC_RELAY) + 10];
snprintf_P(topic, strlen(topic), PSTR("%s/pulse"), MQTT_TOPIC_RELAY);
snprintf_P(topic, sizeof(topic), PSTR("%s/pulse"), MQTT_TOPIC_RELAY);
char value[2]; char value[2];
snprintf_P(value, strlen(value), PSTR("%d"), value);
snprintf_P(value, sizeof(value), PSTR("%d"), value);
mqttSend(topic, value); mqttSend(topic, value);
} }
*/ */
#if WEB_SUPPORT #if WEB_SUPPORT
char message[20]; char message[20];
snprintf_P(message, strlen(message), PSTR("{\"relayPulseMode\": %d}"), value);
snprintf_P(message, sizeof(message), PSTR("{\"relayPulseMode\": %d}"), value);
wsSend(message); wsSend(message);
#endif #endif
@ -324,10 +324,10 @@ void relaySetupAPI() {
for (unsigned int relayID=0; relayID<relayCount(); relayID++) { for (unsigned int relayID=0; relayID<relayCount(); relayID++) {
char url[15]; char url[15];
snprintf_P(url, strlen(url), PSTR("%s/%d"), MQTT_TOPIC_RELAY, relayID);
snprintf_P(url, sizeof(url), PSTR("%s/%d"), MQTT_TOPIC_RELAY, relayID);
char key[10]; char key[10];
snprintf_P(key, strlen(key), PSTR("%s%d"), MQTT_TOPIC_RELAY, relayID);
snprintf_P(key, sizeof(key), PSTR("%s%d"), MQTT_TOPIC_RELAY, relayID);
apiRegister(url, key, apiRegister(url, key,
[relayID](char * buffer, size_t len) { [relayID](char * buffer, size_t len) {
@ -354,6 +354,7 @@ void relaySetupAPI() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#if WEB_SUPPORT #if WEB_SUPPORT
void relayWS() { void relayWS() {
DynamicJsonBuffer jsonBuffer; DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject(); JsonObject& root = jsonBuffer.createObject();
@ -365,6 +366,7 @@ void relayWS() {
root.printTo(output); root.printTo(output);
wsSend(output.c_str()); wsSend(output.c_str());
} }
#endif #endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -391,7 +393,7 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo
#endif #endif
char buffer[strlen(MQTT_TOPIC_RELAY) + 3]; char buffer[strlen(MQTT_TOPIC_RELAY) + 3];
snprintf_P(buffer, strlen(buffer), PSTR("%s/+"), MQTT_TOPIC_RELAY);
snprintf_P(buffer, sizeof(buffer), PSTR("%s/+"), MQTT_TOPIC_RELAY);
mqttSubscribe(buffer); mqttSubscribe(buffer);
} }
@ -441,7 +443,7 @@ void relaySetupMQTT() {
void relayInfluxDB(unsigned char id) { void relayInfluxDB(unsigned char id) {
if (id >= _relays.size()) return; if (id >= _relays.size()) return;
char buffer[10]; char buffer[10];
snprintf_P(buffer, strlen(buffer), PSTR("%s,id=%d"), MQTT_TOPIC_RELAY, id);
snprintf_P(buffer, sizeof(buffer), PSTR("%s,id=%d"), MQTT_TOPIC_RELAY, id);
influxDBSend(buffer, relayStatus(id) ? "1" : "0"); influxDBSend(buffer, relayStatus(id) ? "1" : "0");
} }
#endif #endif


+ 7
- 7
code/espurna/rfbridge.ino View File

@ -58,7 +58,7 @@ void _rfbLearn() {
#if WEB_SUPPORT #if WEB_SUPPORT
char buffer[100]; char buffer[100];
snprintf_P(buffer, strlen(buffer), PSTR("{\"action\": \"rfbLearn\", \"data\":{\"id\": %d, \"status\": %d}}"), _learnId, _learnStatus ? 1 : 0);
snprintf_P(buffer, sizeof(buffer), PSTR("{\"action\": \"rfbLearn\", \"data\":{\"id\": %d, \"status\": %d}}"), _learnId, _learnStatus ? 1 : 0);
wsSend(buffer); wsSend(buffer);
#endif #endif
@ -120,7 +120,7 @@ void _rfbDecode() {
// Websocket update // Websocket update
#if WEB_SUPPORT #if WEB_SUPPORT
char wsb[100]; char wsb[100];
snprintf_P(wsb, strlen(wsb), PSTR("{\"rfb\":[{\"id\": %d, \"status\": %d, \"data\": \"%s\"}]}"), _learnId, _learnStatus ? 1 : 0, buffer);
snprintf_P(wsb, sizeof(wsb), PSTR("{\"rfb\":[{\"id\": %d, \"status\": %d, \"data\": \"%s\"}]}"), _learnId, _learnStatus ? 1 : 0, buffer);
wsSend(wsb); wsSend(wsb);
#endif #endif
@ -216,7 +216,7 @@ void _rfbMqttCallback(unsigned int type, const char * topic, const char * payloa
if (type == MQTT_CONNECT_EVENT) { if (type == MQTT_CONNECT_EVENT) {
char buffer[strlen(MQTT_TOPIC_RFLEARN) + 3]; char buffer[strlen(MQTT_TOPIC_RFLEARN) + 3];
snprintf_P(buffer, strlen(buffer), PSTR("%s/+"), MQTT_TOPIC_RFLEARN);
snprintf_P(buffer, sizeof(buffer), PSTR("%s/+"), MQTT_TOPIC_RFLEARN);
mqttSubscribe(buffer); mqttSubscribe(buffer);
mqttSubscribe(MQTT_TOPIC_RFOUT); mqttSubscribe(MQTT_TOPIC_RFOUT);
} }
@ -257,13 +257,13 @@ void _rfbMqttCallback(unsigned int type, const char * topic, const char * payloa
void rfbStore(unsigned char id, bool status, const char * code) { void rfbStore(unsigned char id, bool status, const char * code) {
DEBUG_MSG_P(PSTR("[RFBRIDGE] Storing %d-%s => '%s'\n"), id, status ? "ON" : "OFF", code); DEBUG_MSG_P(PSTR("[RFBRIDGE] Storing %d-%s => '%s'\n"), id, status ? "ON" : "OFF", code);
char key[8] = {0}; char key[8] = {0};
snprintf_P(key, strlen(key), PSTR("rfb%d%s"), id, status ? "on" : "off");
snprintf_P(key, sizeof(key), PSTR("rfb%d%s"), id, status ? "on" : "off");
setSetting(key, code); setSetting(key, code);
} }
String rfbRetrieve(unsigned char id, bool status) { String rfbRetrieve(unsigned char id, bool status) {
char key[8] = {0}; char key[8] = {0};
snprintf_P(key, strlen(key), PSTR("rfb%d%s"), id, status ? "on" : "off");
snprintf_P(key, sizeof(key), PSTR("rfb%d%s"), id, status ? "on" : "off");
return getSetting(key); return getSetting(key);
} }
@ -288,13 +288,13 @@ void rfbLearn(unsigned char id, bool status) {
void rfbForget(unsigned char id, bool status) { void rfbForget(unsigned char id, bool status) {
char key[8] = {0}; char key[8] = {0};
snprintf_P(key, strlen(key), PSTR("rfb%d%s"), id, status ? "on" : "off");
snprintf_P(key, sizeof(key), PSTR("rfb%d%s"), id, status ? "on" : "off");
delSetting(key); delSetting(key);
// Websocket update // Websocket update
#if WEB_SUPPORT #if WEB_SUPPORT
char wsb[100]; char wsb[100];
snprintf_P(wsb, strlen(wsb), PSTR("{\"rfb\":[{\"id\": %d, \"status\": %d, \"data\": \"\"}]}"), id, status ? 1 : 0);
snprintf_P(wsb, sizeof(wsb), PSTR("{\"rfb\":[{\"id\": %d, \"status\": %d, \"data\": \"\"}]}"), id, status ? 1 : 0);
wsSend(wsb); wsSend(wsb);
#endif #endif


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

@ -383,7 +383,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
void _wsStart(uint32_t client_id) { void _wsStart(uint32_t client_id) {
char chipid[6]; char chipid[6];
snprintf_P(chipid, strlen(chipid), PSTR("%06X"), ESP.getChipId());
snprintf_P(chipid, sizeof(chipid), PSTR("%06X"), ESP.getChipId());
DynamicJsonBuffer jsonBuffer; DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject(); JsonObject& root = jsonBuffer.createObject();
@ -691,6 +691,7 @@ void wsSetup() {
_ws.onEvent(_wsEvent); _ws.onEvent(_wsEvent);
mqttRegister(_wsMQTTCallback); mqttRegister(_wsMQTTCallback);
_server->addHandler(&_ws); _server->addHandler(&_ws);
_server->on("/auth", HTTP_GET, _onAuth);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -764,7 +765,7 @@ ArRequestHandlerFunction _bindAPI(unsigned int apiID) {
// 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, strlen(buffer), PSTR("{ \"%s\": %s }"), api.key, p);
snprintf_P(buffer, sizeof(buffer), PSTR("{ \"%s\": %s }"), api.key, p);
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", p);
@ -837,7 +838,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, strlen(buffer), PSTR("/api/%s"), url);
snprintf_P(buffer, sizeof(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;
@ -913,7 +914,7 @@ void _onGetConfig(AsyncWebServerRequest *request) {
} }
char buffer[100]; char buffer[100];
snprintf_P(buffer, strlen(buffer), PSTR("attachment; filename=\"%s-backup.json\""), (char *) getSetting("hostname").c_str());
snprintf_P(buffer, sizeof(buffer), PSTR("attachment; filename=\"%s-backup.json\""), (char *) getSetting("hostname").c_str());
response->addHeader("Content-Disposition", buffer); response->addHeader("Content-Disposition", buffer);
response->setLength(); response->setLength();
request->send(response); request->send(response);
@ -988,7 +989,7 @@ void _onUpgradeData(AsyncWebServerRequest *request, String filename, size_t inde
void webSetup() { void webSetup() {
// Cache the Last-Modifier header value // Cache the Last-Modifier header value
snprintf_P(_last_modified, strlen(_last_modified), PSTR("%s %s GMT"), __DATE__, __TIME__);
snprintf_P(_last_modified, sizeof(_last_modified), PSTR("%s %s GMT"), __DATE__, __TIME__);
// Create server // Create server
_server = new AsyncWebServer(getSetting("webPort", WEB_PORT).toInt()); _server = new AsyncWebServer(getSetting("webPort", WEB_PORT).toInt());
@ -1007,7 +1008,6 @@ void webSetup() {
_server->on("/index.html", HTTP_GET, _onHome); _server->on("/index.html", HTTP_GET, _onHome);
#endif #endif
_server->on("/config", HTTP_GET, _onGetConfig); _server->on("/config", HTTP_GET, _onGetConfig);
_server->on("/auth", HTTP_GET, _onAuth);
_server->on("/upgrade", HTTP_POST, _onUpgrade, _onUpgradeData); _server->on("/upgrade", HTTP_POST, _onUpgrade, _onUpgradeData);
// Serve static files // Serve static files


Loading…
Cancel
Save