Use debugf instead of Serial for logging

This helps with Serial-oriented applications by not polluting default
serial port. This can still be reenabled with Serial.systemDebugOutput.
master
informatic 2017-10-06 23:37:03 +02:00
parent 9098670b47
commit 52c834bbba
4 changed files with 15 additions and 19 deletions

View File

@ -20,7 +20,6 @@ void Endpoint::onMessage(String topic, String payload) {
String devicePrefix = parent->DEV_TOPIC("");
if(!topic.startsWith(devicePrefix)) {
Serial.println("ignoring");
return;
}
@ -29,6 +28,6 @@ void Endpoint::onMessage(String topic, String payload) {
String property = topic.substring(propPos+1, topic.indexOf("/", propPos+1));
if(name.equals(endpoint)) {
Serial.printf("%s - %s response: %d\n", endpoint.c_str(), property.c_str(), onValue(property, payload).status);
debugf("%s - %s response: %d\n", endpoint.c_str(), property.c_str(), onValue(property, payload).status);
}
}

View File

@ -16,9 +16,8 @@ void SpejsNode::init() {
Serial.begin(115200);
Serial.systemDebugOutput(false); // Debug output to serial
Serial.print("*** SpejsNode init, running on: ");
Serial.print(deviceID);
Serial.printf(", current rom: %d\r\n", currentSlot);
debugf("*** SpejsNode init, runnning on: %s, current rom: %d", deviceID.c_str(), currentSlot);
WifiAccessPoint.enable(false);
WifiStation.enable(true);
@ -45,9 +44,8 @@ void SpejsNode::loadJSON(std::vector<EndpointInitializer> initializers) {
DynamicJsonBuffer jsonBuffer;
if (fileExist(CONFIG_FILE)) {
Serial.println("Found config file");
int size = fileGetSize(CONFIG_FILE);
Serial.printf("%d bytes\n", size);
debugf("Found config file, %d bytes", size);
char* jsonString = new char[size + 1];
fileGetContent(CONFIG_FILE, jsonString, size + 1);
JsonObject& root = jsonBuffer.parseObject(jsonString);
@ -62,7 +60,7 @@ void SpejsNode::loadJSON(std::vector<EndpointInitializer> initializers) {
for(auto init: initializers) {
Endpoint* ep = init(it.value);
if (ep != NULL) {
Serial.printf("%s: got object\n", it.key);
debugf("%s: got object", it.key);
registerEndpoint(it.key, ep);
found = true;
break;
@ -70,11 +68,11 @@ void SpejsNode::loadJSON(std::vector<EndpointInitializer> initializers) {
}
if (!found) {
Serial.printf("%s: nothing found\n", it.key);
debugf("%s: nothing found", it.key);
}
}
} else {
Serial.println("No configuration");
debugf("No configuration");
}
}
@ -82,14 +80,14 @@ void SpejsNode::keepAliveHandler() {
static int failureCounter = 0;
if(!WifiStation.isConnected()) {
statusLED.high();
Serial.println("keepalive: Network reconnect");
debugf("keepalive: Network reconnect");
if(failureCounter++ < 5)
WifiStation.connect();
else
System.restart();
} else if(mqtt.getConnectionState() != eTCS_Connected) {
statusLED.high();
Serial.println("keepalive: MQTT reconnect");
debugf("keepalive: MQTT reconnect");
if(failureCounter++ < 5)
onConnected();
else
@ -101,7 +99,7 @@ void SpejsNode::keepAliveHandler() {
uint8_t mode;
if(rboot_get_last_boot_mode(&mode) && mode == MODE_TEMP_ROM) {
rboot_set_current_rom(currentSlot);
Serial.println("Successfuly connected, accepting temp rom");
debugf("Successfuly connected, accepting temp rom");
}
}
}
@ -128,7 +126,7 @@ void SpejsNode::gotIP(IPAddress ip, IPAddress netmask, IPAddress gateway) {
void SpejsNode::onConnected() {
statusLED.idle();
Serial.println("Connection successful");
debugf("Connection successful");
// MQTT initialization
mqtt.setWill(DEV_TOPIC("$online"), "false", 1, true);

View File

@ -16,7 +16,6 @@ void DHTEndpoint::sample() {
}
else
{
Serial.print("Failed to read from DHT: ");
Serial.print(sensor.getLastError());
debugf("Failed to read from DHT: %d", sensor.getLastError());
}
}

View File

@ -19,7 +19,7 @@ void ImplementationEndpoint::startOTA() {
#endif
String spiffsURL = OTA_URL + parent->deviceID + "/spiff_rom.bin";
Serial.println("Updating...");
debugf("Updating...");
// need a clean object, otherwise if run before and failed will not run again
if (otaUpdater) delete otaUpdater;
@ -29,7 +29,7 @@ void ImplementationEndpoint::startOTA() {
slot = !parent->currentSlot;
Serial.printf("Updating to rom %d.\r\n", slot);
debugf("Updating to rom %d.", slot);
// flash rom to position indicated in the rBoot config rom table
otaUpdater->addItem(bootconf.roms[slot], romURL);
@ -66,7 +66,7 @@ void ImplementationEndpoint::otaUpdateCallback(rBootHttpUpdate& updater, bool re
slot = 0;
// set to boot new rom and then reboot
Serial.printf("Firmware updated, rebooting to rom %d...\r\n", slot);
debugf("Firmware updated, rebooting to rom %d...", slot);
rboot_set_temp_rom(slot);