Browse Source

Moving debug strings to PROGMEM. ~1.5KBytes of heap memory freed

fastled
Xose Pérez 7 years ago
parent
commit
8c54488fa1
17 changed files with 125 additions and 123 deletions
  1. +3
    -3
      code/espurna/button.ino
  2. +3
    -3
      code/espurna/dht.ino
  3. +2
    -2
      code/espurna/ds18b20.ino
  4. +2
    -2
      code/espurna/emon.ino
  5. +22
    -21
      code/espurna/espurna.ino
  6. +1
    -1
      code/espurna/fauxmo.ino
  7. +3
    -3
      code/espurna/i2c.ino
  8. +3
    -3
      code/espurna/led.ino
  9. +25
    -24
      code/espurna/mqtt.ino
  10. +13
    -13
      code/espurna/nofuss.ino
  11. +3
    -3
      code/espurna/ntp.ino
  12. +9
    -9
      code/espurna/ota.ino
  13. +2
    -2
      code/espurna/pow.ino
  14. +5
    -5
      code/espurna/relay.ino
  15. +8
    -8
      code/espurna/rf.ino
  16. +3
    -3
      code/espurna/settings.ino
  17. +18
    -18
      code/espurna/web.ino

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

@ -66,7 +66,7 @@ uint8_t mapEvent(uint8_t event, uint8_t count, uint16_t length) {
void buttonEvent(unsigned int id, unsigned char event) {
DEBUG_MSG("[BUTTON] Pressed #%d, event: %d\n", id, event);
DEBUG_MSG_P(PSTR("[BUTTON] Pressed #%d, event: %d\n"), id, event);
if (event == 0) return;
#ifdef MQTT_TOPIC_BUTTON
@ -84,7 +84,7 @@ void buttonEvent(unsigned int id, unsigned char event) {
if (action == BUTTON_MODE_RESET) ESP.restart();
if (action == BUTTON_MODE_PULSE) relayPulseToggle();
if (action == BUTTON_MODE_FACTORY) {
DEBUG_MSG("\n\nFACTORY RESET\n\n");
DEBUG_MSG_P(PSTR("\n\nFACTORY RESET\n\n"));
settingsFactoryReset();
ESP.restart();
}
@ -129,7 +129,7 @@ void buttonSetup() {
#endif
DEBUG_MSG("[BUTTON] Number of buttons: %d\n", _buttons.size());
DEBUG_MSG_P(PSTR("[BUTTON] Number of buttons: %d\n"), _buttons.size());
}


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

@ -54,7 +54,7 @@ void dhtLoop() {
// Check if readings are valid
if (isnan(h) || isnan(t)) {
DEBUG_MSG("[DHT] Error reading sensor\n");
DEBUG_MSG_P(PSTR("[DHT] Error reading sensor\n"));
} else {
@ -66,8 +66,8 @@ void dhtLoop() {
dtostrf(t, 4, 1, temperature);
itoa((unsigned int) h, humidity, 10);
DEBUG_MSG("[DHT] Temperature: %s%s\n", temperature, (tmpUnits == TMP_CELSIUS) ? "ºC" : "ºF");
DEBUG_MSG("[DHT] Humidity: %s\n", humidity);
DEBUG_MSG_P(PSTR("[DHT] Temperature: %s%s\n"), temperature, (tmpUnits == TMP_CELSIUS) ? "ºC" : "ºF");
DEBUG_MSG_P(PSTR("[DHT] Humidity: %s\n"), humidity);
// Send MQTT messages
mqttSend(getSetting("dhtTmpTopic", DHT_TEMPERATURE_TOPIC).c_str(), temperature);


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

@ -73,7 +73,7 @@ void dsLoop() {
// Check if readings are valid
if (isnan(t)) {
DEBUG_MSG("[DS18B20] Error reading sensor\n");
DEBUG_MSG_P(PSTR("[DS18B20] Error reading sensor\n"));
} else {
@ -87,7 +87,7 @@ void dsLoop() {
dtostrf(t, 5, 1, _dsTemperatureStr);
DEBUG_MSG("[DS18B20] Temperature: %s%s\n",
DEBUG_MSG_P(PSTR("[DS18B20] Temperature: %s%s\n"),
getDSTemperatureStr(),
(_dsIsConnected ? ((tmpUnits == TMP_CELSIUS) ? "ºC" : "ºF") : ""));


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

@ -142,8 +142,8 @@ void powerMonitorLoop() {
char current[6];
dtostrf(_current, 5, 2, current);
DEBUG_MSG("[ENERGY] Current: %sA\n", current);
DEBUG_MSG("[ENERGY] Power: %dW\n", int(_current * mainsVoltage));
DEBUG_MSG_P(PSTR("[ENERGY] Current: %sA\n"), current);
DEBUG_MSG_P(PSTR("[ENERGY] Power: %dW\n"), int(_current * mainsVoltage));
// Update websocket clients
char text[64];


+ 22
- 21
code/espurna/espurna.ino View File

@ -40,13 +40,14 @@ void heartbeat() {
if (millis() < last_uptime) ++uptime_overflows;
last_uptime = millis();
unsigned long uptime_seconds = uptime_overflows * (UPTIME_OVERFLOW / 1000) + (last_uptime / 1000);
unsigned int free_heap = ESP.getFreeHeap();
DEBUG_MSG("[MAIN] Time: %s\n", (char *) NTP.getTimeDateString().c_str());
DEBUG_MSG_P(PSTR("[MAIN] Time: %s\n"), (char *) NTP.getTimeDateString().c_str());
if (!mqttConnected()) {
DEBUG_MSG("[MAIN] Uptime: %ld seconds\n", uptime_seconds);
DEBUG_MSG("[MAIN] Free heap: %d bytes\n", ESP.getFreeHeap());
DEBUG_MSG_P(PSTR("[MAIN] Uptime: %ld seconds\n"), uptime_seconds);
DEBUG_MSG_P(PSTR("[MAIN] Free heap: %d bytes\n"), free_heap);
#if ENABLE_ADC_VCC
DEBUG_MSG("[MAIN] Power: %d mV\n", ESP.getVcc());
DEBUG_MSG_P(PSTR("[MAIN] Power: %d mV\n"), ESP.getVcc());
#endif
}
@ -72,7 +73,7 @@ void heartbeat() {
mqttSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str());
#endif
#if (MQTT_REPORT_FREEHEAP)
mqttSend(MQTT_TOPIC_FREEHEAP, String(ESP.getFreeHeap()).c_str());
mqttSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str());
#endif
#if (MQTT_REPORT_RELAY)
relayMQTT();
@ -113,29 +114,29 @@ void hardwareLoop() {
void welcome() {
DEBUG_MSG("%s %s\n", (char *) APP_NAME, (char *) APP_VERSION);
DEBUG_MSG("%s\n%s\n\n", (char *) APP_AUTHOR, (char *) APP_WEBSITE);
DEBUG_MSG("ChipID: %06X\n", ESP.getChipId());
DEBUG_MSG("CPU frequency: %d MHz\n", ESP.getCpuFreqMHz());
DEBUG_MSG("Last reset reason: %s\n", (char *) ESP.getResetReason().c_str());
DEBUG_MSG("Memory size: %d bytes\n", ESP.getFlashChipSize());
DEBUG_MSG("Free heap: %d bytes\n", ESP.getFreeHeap());
DEBUG_MSG("Firmware size: %d bytes\n", ESP.getSketchSize());
DEBUG_MSG("Free firmware space: %d bytes\n", ESP.getFreeSketchSpace());
DEBUG_MSG_P(PSTR("%s %s\n"), (char *) APP_NAME, (char *) APP_VERSION);
DEBUG_MSG_P(PSTR("%s\n%s\n\n"), (char *) APP_AUTHOR, (char *) APP_WEBSITE);
DEBUG_MSG_P(PSTR("ChipID: %06X\n"), ESP.getChipId());
DEBUG_MSG_P(PSTR("CPU frequency: %d MHz\n"), ESP.getCpuFreqMHz());
DEBUG_MSG_P(PSTR("Last reset reason: %s\n"), (char *) ESP.getResetReason().c_str());
DEBUG_MSG_P(PSTR("Memory size: %d bytes\n"), ESP.getFlashChipSize());
DEBUG_MSG_P(PSTR("Free heap: %d bytes\n"), ESP.getFreeHeap());
DEBUG_MSG_P(PSTR("Firmware size: %d bytes\n"), ESP.getSketchSize());
DEBUG_MSG_P(PSTR("Free firmware space: %d bytes\n"), ESP.getFreeSketchSpace());
#if not EMBEDDED_WEB
FSInfo fs_info;
if (SPIFFS.info(fs_info)) {
DEBUG_MSG("File system total size: %d bytes\n", fs_info.totalBytes);
DEBUG_MSG(" used size : %d bytes\n", fs_info.usedBytes);
DEBUG_MSG(" block size: %d bytes\n", fs_info.blockSize);
DEBUG_MSG(" page size : %d bytes\n", fs_info.pageSize);
DEBUG_MSG(" max files : %d\n", fs_info.maxOpenFiles);
DEBUG_MSG(" max length: %d\n", fs_info.maxPathLength);
DEBUG_MSG_P(PSTR("File system total size: %d bytes\n"), fs_info.totalBytes);
DEBUG_MSG_P(PSTR(" used size : %d bytes\n"), fs_info.usedBytes);
DEBUG_MSG_P(PSTR(" block size: %d bytes\n"), fs_info.blockSize);
DEBUG_MSG_P(PSTR(" page size : %d bytes\n"), fs_info.pageSize);
DEBUG_MSG_P(PSTR(" max files : %d\n"), fs_info.maxOpenFiles);
DEBUG_MSG_P(PSTR(" max length: %d\n"), fs_info.maxPathLength);
}
#endif
DEBUG_MSG("\n\n");
DEBUG_MSG_P(PSTR("\n\n"));
}


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

@ -32,7 +32,7 @@ void fauxmoSetup() {
}
}
fauxmo.onMessage([relays](unsigned char device_id, const char * name, bool state) {
DEBUG_MSG("[FAUXMO] %s state: %s\n", name, state ? "ON" : "OFF");
DEBUG_MSG_P(PSTR("[FAUXMO] %s state: %s\n"), name, state ? "ON" : "OFF");
relayStatus(device_id, state);
});
}


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

@ -24,14 +24,14 @@ void i2cScan() {
response = brzo_i2c_end_transaction();
if (response == 0) {
DEBUG_MSG("[I2C] Device found at address 0x%02X\n", address);
DEBUG_MSG_P(PSTR("[I2C] Device found at address 0x%02X\n"), address);
nDevices++;
} else if (response != 32) {
//DEBUG_MSG("[I2C] Unknown error at address 0x%02X\n", address);
//DEBUG_MSG_P(PSTR("[I2C] Unknown error at address 0x%02X\n"), address);
}
}
if (nDevices == 0) DEBUG_MSG("[I2C] No devices found");
if (nDevices == 0) DEBUG_MSG_P(PSTR("[I2C] No devices found"));
}


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

@ -77,7 +77,7 @@ void ledMQTTCallback(unsigned int type, const char * topic, const char * payload
// Get led ID
unsigned int ledID = t.substring(strlen(MQTT_TOPIC_LED)+1).toInt();
if (ledID >= ledCount()) {
DEBUG_MSG("[LED] Wrong ledID (%d)\n", ledID);
DEBUG_MSG_P(PSTR("[LED] Wrong ledID (%d)\n"), ledID);
return;
}
@ -132,8 +132,8 @@ void ledSetup() {
mqttRegister(ledMQTTCallback);
DEBUG_MSG("[LED] Number of leds: %d\n", _leds.size());
DEBUG_MSG("[LED] Led auto indicator is %s\n", ledAuto ? "ON" : "OFF" );
DEBUG_MSG_P(PSTR("[LED] Number of leds: %d\n"), _leds.size());
DEBUG_MSG_P(PSTR("[LED] Led auto indicator is %s\n"), ledAuto ? "ON" : "OFF" );
}


+ 25
- 24
code/espurna/mqtt.ino View File

@ -21,8 +21,8 @@ bool _mqttConnected = false;
String mqttTopic;
bool _mqttForward;
char * _mqtt_pass = 0;
char * _mqtt_user = 0;
char *_mqttUser = 0;
char *_mqttPass = 0;
std::vector<void (*)(unsigned int, const char *, const char *)> _mqtt_callbacks;
#if MQTT_SKIP_RETAINED
unsigned long mqttConnectedAt = 0;
@ -67,7 +67,7 @@ String mqttSubtopic(char * topic) {
void mqttSendRaw(const char * topic, const char * message) {
if (mqtt.connected()) {
DEBUG_MSG("[MQTT] Sending %s => %s\n", topic, message);
DEBUG_MSG_P(PSTR("[MQTT] Sending %s => %s\n"), topic, message);
#if MQTT_USE_ASYNC
mqtt.publish(topic, MQTT_QOS, MQTT_RETAIN, message);
#else
@ -90,7 +90,7 @@ void mqttSend(const char * topic, unsigned int index, const char * message) {
void mqttSubscribeRaw(const char * topic) {
if (mqtt.connected() && (strlen(topic) > 0)) {
DEBUG_MSG("[MQTT] Subscribing to %s\n", topic);
DEBUG_MSG_P(PSTR("[MQTT] Subscribing to %s\n"), topic);
mqtt.subscribe(topic, MQTT_QOS);
}
}
@ -111,7 +111,7 @@ void mqttRegister(void (*callback)(unsigned int, const char *, const char *)) {
void _mqttOnConnect() {
DEBUG_MSG("[MQTT] Connected!\n");
DEBUG_MSG_P(PSTR("[MQTT] Connected!\n"));
#if MQTT_SKIP_RETAINED
mqttConnectedAt = millis();
@ -135,7 +135,7 @@ void _mqttOnConnect() {
void _mqttOnDisconnect() {
DEBUG_MSG("[MQTT] Disconnected!\n");
DEBUG_MSG_P(PSTR("[MQTT] Disconnected!\n"));
// Send disconnect event to subscribers
for (unsigned char i = 0; i < _mqtt_callbacks.size(); i++) {
@ -149,14 +149,14 @@ void _mqttOnMessage(char* topic, char* payload, unsigned int len) {
char message[len + 1];
strlcpy(message, (char *) payload, len + 1);
DEBUG_MSG("[MQTT] Received %s => %s", topic, message);
DEBUG_MSG_P(PSTR("[MQTT] Received %s => %s"), topic, message);
#if MQTT_SKIP_RETAINED
if (millis() - mqttConnectedAt < MQTT_SKIP_TIME) {
DEBUG_MSG(" - SKIPPED\n");
DEBUG_MSG_P(PSTR(" - SKIPPED\n"));
return;
}
#endif
DEBUG_MSG("\n");
DEBUG_MSG_P(PSTR("\n"));
// Check system topics
String t = mqttSubtopic((char *) topic);
@ -185,7 +185,7 @@ void mqttConnect() {
static unsigned long last_try = millis();
if (millis() - last_try < MQTT_TRY_INTERVAL) {
if (++tries > MQTT_MAX_TRIES) {
DEBUG_MSG("[MQTT] MQTT_MAX_TRIES met, disconnecting from WiFi\n");
DEBUG_MSG_P(PSTR("[MQTT] MQTT_MAX_TRIES met, disconnecting from WiFi\n"));
wifiDisconnect();
tries = 0;
return;
@ -198,34 +198,37 @@ void mqttConnect() {
mqtt.disconnect();
if (_mqttUser) free(_mqttUser);
if (_mqttPass) free(_mqttPass);
char * host = strdup(getSetting("mqttServer", MQTT_SERVER).c_str());
unsigned int port = getSetting("mqttPort", MQTT_PORT).toInt();
char * user = strdup(getSetting("mqttUser").c_str());
char * pass = strdup(getSetting("mqttPassword").c_str());
_mqttUser = strdup(getSetting("mqttUser").c_str());
_mqttPass = strdup(getSetting("mqttPassword").c_str());
DEBUG_MSG("[MQTT] Connecting to broker at %s:%d", host, port);
DEBUG_MSG_P(PSTR("[MQTT] Connecting to broker at %s:%d"), host, port);
mqtt.setServer(host, port);
#if MQTT_USE_ASYNC
mqtt.setKeepAlive(MQTT_KEEPALIVE).setCleanSession(false);
mqtt.setWill((mqttTopic + MQTT_TOPIC_STATUS).c_str(), MQTT_QOS, MQTT_RETAIN, "0");
if ((strlen(user) > 0) && (strlen(pass) > 0)) {
DEBUG_MSG(" as user '%s'.", user);
mqtt.setCredentials(user, pass);
if ((strlen(_mqttUser) > 0) && (strlen(_mqttPass) > 0)) {
DEBUG_MSG_P(PSTR(" as user '%s'."), _mqttUser);
mqtt.setCredentials(_mqttUser, _mqttPass);
}
DEBUG_MSG("\n");
DEBUG_MSG_P(PSTR("\n"));
mqtt.connect();
#else
bool response;
if ((strlen(user) > 0) && (strlen(pass) > 0)) {
DEBUG_MSG(" as user '%s'\n", user);
response = mqtt.connect(getIdentifier().c_str(), user, pass, (mqttTopic + MQTT_TOPIC_STATUS).c_str(), MQTT_QOS, MQTT_RETAIN, "0");
if ((strlen(_mqttUser) > 0) && (strlen(_mqttPass) > 0)) {
DEBUG_MSG_P(PSTR(" as user '%s'\n"), _mqttUser);
response = mqtt.connect(getIdentifier().c_str(), _mqttUser, _mqttPass, (mqttTopic + MQTT_TOPIC_STATUS).c_str(), MQTT_QOS, MQTT_RETAIN, "0");
} else {
DEBUG_MSG("\n");
DEBUG_MSG_P(PSTR("\n"));
response = mqtt.connect(getIdentifier().c_str(), (mqttTopic + MQTT_TOPIC_STATUS).c_str(), MQTT_QOS, MQTT_RETAIN, "0");
}
@ -233,14 +236,12 @@ void mqttConnect() {
_mqttOnConnect();
_mqttConnected = true;
} else {
DEBUG_MSG("[MQTT] Connection failed\n");
DEBUG_MSG_P(PSTR("[MQTT] Connection failed\n"));
}
#endif
free(host);
free(user);
free(pass);
String mqttSetter = getSetting("mqttSetter", MQTT_USE_SETTER);
String mqttGetter = getSetting("mqttGetter", MQTT_USE_GETTER);


+ 13
- 13
code/espurna/nofuss.ino View File

@ -23,46 +23,46 @@ NoFUSSClient.setVersion(APP_VERSION);
NoFUSSClient.onMessage([](nofuss_t code) {
if (code == NOFUSS_START) {
DEBUG_MSG("[NoFUSS] Start\n");
DEBUG_MSG_P(PSTR("[NoFUSS] Start\n"));
}
if (code == NOFUSS_UPTODATE) {
DEBUG_MSG("[NoFUSS] Already in the last version\n");
DEBUG_MSG_P(PSTR("[NoFUSS] Already in the last version\n"));
}
if (code == NOFUSS_PARSE_ERROR) {
DEBUG_MSG("[NoFUSS] Error parsing server response\n");
DEBUG_MSG_P(PSTR("[NoFUSS] Error parsing server response\n"));
}
if (code == NOFUSS_UPDATING) {
DEBUG_MSG("[NoFUSS] Updating");
DEBUG_MSG(" New version: %s\n", (char *) NoFUSSClient.getNewVersion().c_str());
DEBUG_MSG(" Firmware: %s\n", (char *) NoFUSSClient.getNewFirmware().c_str());
DEBUG_MSG(" File System: %s", (char *) NoFUSSClient.getNewFileSystem().c_str());
DEBUG_MSG_P(PSTR("[NoFUSS] Updating");
DEBUG_MSG_P(PSTR(" New version: %s\n"), (char *) NoFUSSClient.getNewVersion().c_str());
DEBUG_MSG_P(PSTR(" Firmware: %s\n"), (char *) NoFUSSClient.getNewFirmware().c_str());
DEBUG_MSG_P(PSTR(" File System: %s"), (char *) NoFUSSClient.getNewFileSystem().c_str());
}
if (code == NOFUSS_FILESYSTEM_UPDATE_ERROR) {
DEBUG_MSG("[NoFUSS] File System Update Error: %s\n", (char *) NoFUSSClient.getErrorString().c_str());
DEBUG_MSG_P(PSTR("[NoFUSS] File System Update Error: %s\n"), (char *) NoFUSSClient.getErrorString().c_str());
}
if (code == NOFUSS_FILESYSTEM_UPDATED) {
DEBUG_MSG("[NoFUSS] File System Updated\n");
DEBUG_MSG_P(PSTR("[NoFUSS] File System Updated\n"));
}
if (code == NOFUSS_FIRMWARE_UPDATE_ERROR) {
DEBUG_MSG("[NoFUSS] Firmware Update Error: %s\n", (char *) NoFUSSClient.getErrorString().c_str());
DEBUG_MSG_P(PSTR("[NoFUSS] Firmware Update Error: %s\n"), (char *) NoFUSSClient.getErrorString().c_str());
}
if (code == NOFUSS_FIRMWARE_UPDATED) {
DEBUG_MSG("[NoFUSS] Firmware Updated\n");
DEBUG_MSG_P(PSTR("[NoFUSS] Firmware Updated\n"));
}
if (code == NOFUSS_RESET) {
DEBUG_MSG("[NoFUSS] Resetting board\n");
DEBUG_MSG_P(PSTR("[NoFUSS] Resetting board\n"));
}
if (code == NOFUSS_END) {
DEBUG_MSG("[NoFUSS] End\n");
DEBUG_MSG_P(PSTR("[NoFUSS] End\n"));
}
});


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

@ -24,12 +24,12 @@ void ntpSetup() {
NTP.onNTPSyncEvent([](NTPSyncEvent_t error) {
if (error) {
if (error == noResponse) {
DEBUG_MSG("[NTP] Error: NTP server not reachable\n");
DEBUG_MSG_P(PSTR("[NTP] Error: NTP server not reachable\n"));
} else if (error == invalidAddress) {
DEBUG_MSG("[NTP] Error: Invalid NTP server address\n");
DEBUG_MSG_P(PSTR("[NTP] Error: Invalid NTP server address\n"));
}
} else {
DEBUG_MSG("[NTP] Time: %s\n", (char *) NTP.getTimeDateString(NTP.getLastNTPSync()).c_str());
DEBUG_MSG_P(PSTR("[NTP] Time: %s\n"), (char *) NTP.getTimeDateString(NTP.getLastNTPSync()).c_str());
}
});


+ 9
- 9
code/espurna/ota.ino View File

@ -23,28 +23,28 @@ void otaSetup() {
otaConfigure();
ArduinoOTA.onStart([]() {
DEBUG_MSG("[OTA] Start\n");
DEBUG_MSG_P(PSTR("[OTA] Start\n"));
wsSend("{\"message\": \"OTA update started\"}");
});
ArduinoOTA.onEnd([]() {
DEBUG_MSG("\n[OTA] End\n");
DEBUG_MSG_P(PSTR("\n[OTA] End\n"));
wsSend("{\"action\": \"reload\"}");
delay(100);
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
DEBUG_MSG("[OTA] Progress: %u%%\r", (progress / (total / 100)));
DEBUG_MSG_P(PSTR("[OTA] Progress: %u%%\r"), (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
#if DEBUG_PORT
DEBUG_MSG("\n[OTA] Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) DEBUG_MSG("Auth Failed\n");
else if (error == OTA_BEGIN_ERROR) DEBUG_MSG("Begin Failed\n");
else if (error == OTA_CONNECT_ERROR) DEBUG_MSG("Connect Failed\n");
else if (error == OTA_RECEIVE_ERROR) DEBUG_MSG("Receive Failed\n");
else if (error == OTA_END_ERROR) DEBUG_MSG("End Failed\n");
DEBUG_MSG_P(PSTR("\n[OTA] Error[%u]: "), error);
if (error == OTA_AUTH_ERROR) DEBUG_MSG_P(PSTR("Auth Failed\n"));
else if (error == OTA_BEGIN_ERROR) DEBUG_MSG_P(PSTR("Begin Failed\n"));
else if (error == OTA_CONNECT_ERROR) DEBUG_MSG_P(PSTR("Connect Failed\n"));
else if (error == OTA_RECEIVE_ERROR) DEBUG_MSG_P(PSTR("Receive Failed\n"));
else if (error == OTA_END_ERROR) DEBUG_MSG_P(PSTR("End Failed\n"));
#endif
});


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

@ -38,13 +38,13 @@ void powEnable(bool status) {
attachInterrupt(POW_CF1_PIN, hlw8012_cf1_interrupt, CHANGE);
attachInterrupt(POW_CF_PIN, hlw8012_cf_interrupt, CHANGE);
#endif
DEBUG_MSG("[POW] Enabled\n");
DEBUG_MSG_P(PSTR("[POW] Enabled\n"));
} else {
#if POW_USE_INTERRUPTS == 1
detachInterrupt(POW_CF1_PIN);
detachInterrupt(POW_CF_PIN);
#endif
DEBUG_MSG("[POW] Disabled\n");
DEBUG_MSG_P(PSTR("[POW] Disabled\n"));
}
}


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

@ -153,7 +153,7 @@ bool relayStatus(unsigned char id, bool status, bool report) {
if (relayStatus(id) != status) {
DEBUG_MSG("[RELAY] %d => %s\n", id, status ? "ON" : "OFF");
DEBUG_MSG_P(PSTR("[RELAY] %d => %s\n"), id, status ? "ON" : "OFF");
changed = true;
relayProviderStatus(id, status);
@ -345,7 +345,7 @@ void relayDomoticzSetup() {
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject((char *) payload);
if (!root.success()) {
DEBUG_MSG("[DOMOTICZ] Error parsing data\n");
DEBUG_MSG_P(PSTR("[DOMOTICZ] Error parsing data\n"));
return;
}
@ -354,7 +354,7 @@ void relayDomoticzSetup() {
int relayID = relayFromIdx(idx);
if (relayID >= 0) {
unsigned long value = root["nvalue"];
DEBUG_MSG("[DOMOTICZ] Received value %d for IDX %d\n", value, idx);
DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %d for IDX %d\n"), value, idx);
relayStatus(relayID, value == 1);
}
@ -414,7 +414,7 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo
// Get relay ID
unsigned int relayID = t.substring(strlen(MQTT_TOPIC_RELAY)+1).toInt();
if (relayID >= relayCount()) {
DEBUG_MSG("[RELAY] Wrong relayID (%d)\n", relayID);
DEBUG_MSG_P(PSTR("[RELAY] Wrong relayID (%d)\n"), relayID);
return;
}
@ -482,6 +482,6 @@ void relaySetup() {
relayDomoticzSetup();
#endif
DEBUG_MSG("[RELAY] Number of relays: %d\n", _relays.size());
DEBUG_MSG_P(PSTR("[RELAY] Number of relays: %d\n"), _relays.size());
}

+ 8
- 8
code/espurna/rf.ino View File

@ -21,7 +21,7 @@ unsigned long rfCodeOFF = 0;
void rfLoop() {
return;
if (rfCode == 0) return;
DEBUG_MSG("[RF] Received code: %lu\n", rfCode);
DEBUG_MSG_P(PSTR("[RF] Received code: %lu\n"), rfCode);
if (rfCode == rfCodeON) relayStatus(0, true);
if (rfCode == rfCodeOFF) relayStatus(0, false);
rfCode = 0;
@ -51,8 +51,8 @@ void rfBuildCodes() {
rfCodeOFF = code + 2;
rfCodeON = code + 6;
DEBUG_MSG("[RF] Code ON : %lu\n", rfCodeON);
DEBUG_MSG("[RF] Code OFF: %lu\n", rfCodeOFF);
DEBUG_MSG_P(PSTR("[RF] Code ON : %lu\n"), rfCodeON);
DEBUG_MSG_P(PSTR("[RF] Code OFF: %lu\n"), rfCodeOFF);
}
@ -66,26 +66,26 @@ void rfSetup() {
rfBuildCodes();
RemoteReceiver::init(RF_PIN, 3, rfCallback);
RemoteReceiver::disable();
DEBUG_MSG("[RF] Disabled\n");
DEBUG_MSG_P(PSTR("[RF] Disabled\n"));
static WiFiEventHandler e1 = WiFi.onStationModeDisconnected([](const WiFiEventStationModeDisconnected& event) {
RemoteReceiver::disable();
DEBUG_MSG("[RF] Disabled\n");
DEBUG_MSG_P(PSTR("[RF] Disabled\n"));
});
static WiFiEventHandler e2 = WiFi.onSoftAPModeStationDisconnected([](const WiFiEventSoftAPModeStationDisconnected& event) {
RemoteReceiver::disable();
DEBUG_MSG("[RF] Disabled\n");
DEBUG_MSG_P(PSTR("[RF] Disabled\n"));
});
static WiFiEventHandler e3 = WiFi.onStationModeConnected([](const WiFiEventStationModeConnected& event) {
RemoteReceiver::enable();
DEBUG_MSG("[RF] Enabled\n");
DEBUG_MSG_P(PSTR("[RF] Enabled\n"));
});
static WiFiEventHandler e4 = WiFi.onSoftAPModeStationConnected([](const WiFiEventSoftAPModeStationConnected& event) {
RemoteReceiver::enable();
DEBUG_MSG("[RF] Enabled\n");
DEBUG_MSG_P(PSTR("[RF] Enabled\n"));
});
}


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

@ -163,8 +163,8 @@ void settingsSetup() {
e->response(Embedis::OK);
});
DEBUG_MSG("[SETTINGS] EEPROM size: %d bytes\n", SPI_FLASH_SEC_SIZE);
DEBUG_MSG("[SETTINGS] Settings size: %d bytes\n", settingsSize());
DEBUG_MSG_P(PSTR("[SETTINGS] EEPROM size: %d bytes\n"), SPI_FLASH_SEC_SIZE);
DEBUG_MSG_P(PSTR("[SETTINGS] Settings size: %d bytes\n"), settingsSize());
}
@ -191,7 +191,7 @@ bool delSetting(const String& key) {
}
void saveSettings() {
DEBUG_MSG("[SETTINGS] Saving\n");
DEBUG_MSG_P(PSTR("[SETTINGS] Saving\n"));
#if not AUTO_SAVE
EEPROM.commit();
#endif


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

@ -45,13 +45,13 @@ char _last_modified[50];
bool wsSend(const char * payload) {
if (ws.count() > 0) {
DEBUG_MSG("[WEBSOCKET] Broadcasting '%s'\n", payload);
DEBUG_MSG_P(PSTR("[WEBSOCKET] Broadcasting '%s'\n"), payload);
ws.textAll(payload);
}
}
bool wsSend(uint32_t client_id, const char * payload) {
DEBUG_MSG("[WEBSOCKET] Sending '%s' to #%ld\n", payload, client_id);
DEBUG_MSG_P(PSTR("[WEBSOCKET] Sending '%s' to #%ld\n"), payload, client_id);
ws.text(client_id, payload);
}
@ -73,7 +73,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject((char *) payload);
if (!root.success()) {
DEBUG_MSG("[WEBSOCKET] Error parsing data\n");
DEBUG_MSG_P(PSTR("[WEBSOCKET] Error parsing data\n"));
ws.text(client_id, "{\"message\": \"Error parsing data!\"}");
return;
}
@ -83,7 +83,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
String action = root["action"];
DEBUG_MSG("[WEBSOCKET] Requested action: %s\n", action.c_str());
DEBUG_MSG_P(PSTR("[WEBSOCKET] Requested action: %s\n"), action.c_str());
if (action.equals("reset")) {
ESP.restart();
@ -123,7 +123,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
if (action.equals("relay") && root.containsKey("data")) {
JsonObject& data = root["data"];
if (data.containsKey("status")) {
bool state = (strcmp(data["status"], "1") == 0);
@ -152,7 +152,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
if (root.containsKey("config") && root["config"].is<JsonArray&>()) {
JsonArray& config = root["config"];
DEBUG_MSG("[WEBSOCKET] Parsing configuration data\n");
DEBUG_MSG_P(PSTR("[WEBSOCKET] Parsing configuration data\n"));
unsigned char webMode = WEB_MODE_NORMAL;
@ -274,7 +274,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
}
if (value != getSetting(key)) {
//DEBUG_MSG("[WEBSOCKET] Storing %s = %s\n", key.c_str(), value.c_str());
//DEBUG_MSG_P(PSTR("[WEBSOCKET] Storing %s = %s\n", key.c_str(), value.c_str()));
setSetting(key, value);
save = changed = true;
if (key.startsWith("mqtt")) changedMQTT = true;
@ -533,7 +533,7 @@ bool _wsAuth(AsyncWebSocketClient * client) {
}
if (index == WS_BUFFER_SIZE) {
DEBUG_MSG("[WEBSOCKET] Validation check failed\n");
DEBUG_MSG_P(PSTR("[WEBSOCKET] Validation check failed\n"));
ws.text(client->id(), "{\"message\": \"Session expired, please reload page...\"}");
return false;
}
@ -553,14 +553,14 @@ void _wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTy
if (type == WS_EVT_CONNECT) {
IPAddress ip = client->remoteIP();
DEBUG_MSG("[WEBSOCKET] #%u connected, ip: %d.%d.%d.%d, url: %s\n", client->id(), ip[0], ip[1], ip[2], ip[3], server->url());
DEBUG_MSG_P(PSTR("[WEBSOCKET] #%u connected, ip: %d.%d.%d.%d, url: %s\n"), client->id(), ip[0], ip[1], ip[2], ip[3], server->url());
_wsStart(client->id());
} else if(type == WS_EVT_DISCONNECT) {
DEBUG_MSG("[WEBSOCKET] #%u disconnected\n", client->id());
DEBUG_MSG_P(PSTR("[WEBSOCKET] #%u disconnected\n"), client->id());
} else if(type == WS_EVT_ERROR) {
DEBUG_MSG("[WEBSOCKET] #%u error(%u): %s\n", client->id(), *((uint16_t*)arg), (char*)data);
DEBUG_MSG_P(PSTR("[WEBSOCKET] #%u error(%u): %s\n"), client->id(), *((uint16_t*)arg), (char*)data);
} else if(type == WS_EVT_PONG) {
DEBUG_MSG("[WEBSOCKET] #%u pong(%u): %s\n", client->id(), len, len ? (char*) data : "");
DEBUG_MSG_P(PSTR("[WEBSOCKET] #%u pong(%u): %s\n"), client->id(), len, len ? (char*) data : "");
} else if(type == WS_EVT_DATA) {
AwsFrameInfo * info = (AwsFrameInfo*)arg;
@ -588,7 +588,7 @@ void _wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTy
// -----------------------------------------------------------------------------
void webLogRequest(AsyncWebServerRequest *request) {
DEBUG_MSG("[WEBSERVER] Request: %s %s\n", request->methodToString(), request->url().c_str());
DEBUG_MSG_P(PSTR("[WEBSERVER] Request: %s %s\n"), request->methodToString(), request->url().c_str());
}
bool _authenticate(AsyncWebServerRequest *request) {
@ -601,20 +601,20 @@ bool _authenticate(AsyncWebServerRequest *request) {
bool _authAPI(AsyncWebServerRequest *request) {
if (getSetting("apiEnabled").toInt() == 0) {
DEBUG_MSG("[WEBSERVER] HTTP API is not enabled\n");
DEBUG_MSG_P(PSTR("[WEBSERVER] HTTP API is not enabled\n"));
request->send(403);
return false;
}
if (!request->hasParam("apikey", (request->method() == HTTP_PUT))) {
DEBUG_MSG("[WEBSERVER] Missing apikey parameter\n");
DEBUG_MSG_P(PSTR("[WEBSERVER] Missing apikey parameter\n"));
request->send(403);
return false;
}
AsyncWebParameter* p = request->getParam("apikey", (request->method() == HTTP_PUT));
if (!p->value().equals(getSetting("apiKey"))) {
DEBUG_MSG("[WEBSERVER] Wrong apikey parameter\n");
DEBUG_MSG_P(PSTR("[WEBSERVER] Wrong apikey parameter\n"));
request->send(403);
return false;
}
@ -725,7 +725,7 @@ void _onRPC(AsyncWebServerRequest *request) {
AsyncWebParameter* p = request->getParam("action");
String action = p->value();
DEBUG_MSG("[RPC] Action: %s\n", action.c_str());
DEBUG_MSG_P(PSTR("[RPC] Action: %s\n"), action.c_str());
if (action.equals("reset")) {
response = 200;
@ -853,6 +853,6 @@ void webSetup() {
// Run server
_server->begin();
DEBUG_MSG("[WEBSERVER] Webserver running on port %d\n", getSetting("webPort", WEBSERVER_PORT).toInt());
DEBUG_MSG_P(PSTR("[WEBSERVER] Webserver running on port %d\n"), getSetting("webPort", WEBSERVER_PORT).toInt());
}

Loading…
Cancel
Save