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
parent
9098670b47
commit
52c834bbba
|
@ -20,7 +20,6 @@ void Endpoint::onMessage(String topic, String payload) {
|
||||||
String devicePrefix = parent->DEV_TOPIC("");
|
String devicePrefix = parent->DEV_TOPIC("");
|
||||||
|
|
||||||
if(!topic.startsWith(devicePrefix)) {
|
if(!topic.startsWith(devicePrefix)) {
|
||||||
Serial.println("ignoring");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +28,6 @@ void Endpoint::onMessage(String topic, String payload) {
|
||||||
String property = topic.substring(propPos+1, topic.indexOf("/", propPos+1));
|
String property = topic.substring(propPos+1, topic.indexOf("/", propPos+1));
|
||||||
|
|
||||||
if(name.equals(endpoint)) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,8 @@ void SpejsNode::init() {
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.systemDebugOutput(false); // Debug output to serial
|
Serial.systemDebugOutput(false); // Debug output to serial
|
||||||
Serial.print("*** SpejsNode init, running on: ");
|
|
||||||
Serial.print(deviceID);
|
debugf("*** SpejsNode init, runnning on: %s, current rom: %d", deviceID.c_str(), currentSlot);
|
||||||
Serial.printf(", current rom: %d\r\n", currentSlot);
|
|
||||||
|
|
||||||
WifiAccessPoint.enable(false);
|
WifiAccessPoint.enable(false);
|
||||||
WifiStation.enable(true);
|
WifiStation.enable(true);
|
||||||
|
@ -45,9 +44,8 @@ void SpejsNode::loadJSON(std::vector<EndpointInitializer> initializers) {
|
||||||
|
|
||||||
DynamicJsonBuffer jsonBuffer;
|
DynamicJsonBuffer jsonBuffer;
|
||||||
if (fileExist(CONFIG_FILE)) {
|
if (fileExist(CONFIG_FILE)) {
|
||||||
Serial.println("Found config file");
|
|
||||||
int size = fileGetSize(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];
|
char* jsonString = new char[size + 1];
|
||||||
fileGetContent(CONFIG_FILE, jsonString, size + 1);
|
fileGetContent(CONFIG_FILE, jsonString, size + 1);
|
||||||
JsonObject& root = jsonBuffer.parseObject(jsonString);
|
JsonObject& root = jsonBuffer.parseObject(jsonString);
|
||||||
|
@ -62,7 +60,7 @@ void SpejsNode::loadJSON(std::vector<EndpointInitializer> initializers) {
|
||||||
for(auto init: initializers) {
|
for(auto init: initializers) {
|
||||||
Endpoint* ep = init(it.value);
|
Endpoint* ep = init(it.value);
|
||||||
if (ep != NULL) {
|
if (ep != NULL) {
|
||||||
Serial.printf("%s: got object\n", it.key);
|
debugf("%s: got object", it.key);
|
||||||
registerEndpoint(it.key, ep);
|
registerEndpoint(it.key, ep);
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
@ -70,11 +68,11 @@ void SpejsNode::loadJSON(std::vector<EndpointInitializer> initializers) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
Serial.printf("%s: nothing found\n", it.key);
|
debugf("%s: nothing found", it.key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Serial.println("No configuration");
|
debugf("No configuration");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,14 +80,14 @@ void SpejsNode::keepAliveHandler() {
|
||||||
static int failureCounter = 0;
|
static int failureCounter = 0;
|
||||||
if(!WifiStation.isConnected()) {
|
if(!WifiStation.isConnected()) {
|
||||||
statusLED.high();
|
statusLED.high();
|
||||||
Serial.println("keepalive: Network reconnect");
|
debugf("keepalive: Network reconnect");
|
||||||
if(failureCounter++ < 5)
|
if(failureCounter++ < 5)
|
||||||
WifiStation.connect();
|
WifiStation.connect();
|
||||||
else
|
else
|
||||||
System.restart();
|
System.restart();
|
||||||
} else if(mqtt.getConnectionState() != eTCS_Connected) {
|
} else if(mqtt.getConnectionState() != eTCS_Connected) {
|
||||||
statusLED.high();
|
statusLED.high();
|
||||||
Serial.println("keepalive: MQTT reconnect");
|
debugf("keepalive: MQTT reconnect");
|
||||||
if(failureCounter++ < 5)
|
if(failureCounter++ < 5)
|
||||||
onConnected();
|
onConnected();
|
||||||
else
|
else
|
||||||
|
@ -101,7 +99,7 @@ void SpejsNode::keepAliveHandler() {
|
||||||
uint8_t mode;
|
uint8_t mode;
|
||||||
if(rboot_get_last_boot_mode(&mode) && mode == MODE_TEMP_ROM) {
|
if(rboot_get_last_boot_mode(&mode) && mode == MODE_TEMP_ROM) {
|
||||||
rboot_set_current_rom(currentSlot);
|
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() {
|
void SpejsNode::onConnected() {
|
||||||
statusLED.idle();
|
statusLED.idle();
|
||||||
|
|
||||||
Serial.println("Connection successful");
|
debugf("Connection successful");
|
||||||
|
|
||||||
// MQTT initialization
|
// MQTT initialization
|
||||||
mqtt.setWill(DEV_TOPIC("$online"), "false", 1, true);
|
mqtt.setWill(DEV_TOPIC("$online"), "false", 1, true);
|
||||||
|
|
|
@ -16,7 +16,6 @@ void DHTEndpoint::sample() {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.print("Failed to read from DHT: ");
|
debugf("Failed to read from DHT: %d", sensor.getLastError());
|
||||||
Serial.print(sensor.getLastError());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ void ImplementationEndpoint::startOTA() {
|
||||||
#endif
|
#endif
|
||||||
String spiffsURL = OTA_URL + parent->deviceID + "/spiff_rom.bin";
|
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
|
// need a clean object, otherwise if run before and failed will not run again
|
||||||
if (otaUpdater) delete otaUpdater;
|
if (otaUpdater) delete otaUpdater;
|
||||||
|
@ -29,7 +29,7 @@ void ImplementationEndpoint::startOTA() {
|
||||||
|
|
||||||
slot = !parent->currentSlot;
|
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
|
// flash rom to position indicated in the rBoot config rom table
|
||||||
otaUpdater->addItem(bootconf.roms[slot], romURL);
|
otaUpdater->addItem(bootconf.roms[slot], romURL);
|
||||||
|
@ -66,7 +66,7 @@ void ImplementationEndpoint::otaUpdateCallback(rBootHttpUpdate& updater, bool re
|
||||||
slot = 0;
|
slot = 0;
|
||||||
|
|
||||||
// set to boot new rom and then reboot
|
// 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);
|
rboot_set_temp_rom(slot);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue