diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index 1f68c6f2a0..ca31522b35 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -461,10 +461,10 @@ const char *MyMesh::getLogDateTime() { void MyMesh::logRxRaw(float snr, float rssi, const uint8_t raw[], int len) { #if MESH_PACKET_LOGGING - Serial.print(getLogDateTime()); - Serial.print(" RAW: "); - mesh::Utils::printHex(Serial, raw, len); - Serial.println(); + MESH_CONSOLE_SERIAL.print(getLogDateTime()); + MESH_CONSOLE_SERIAL.print(" RAW: "); + mesh::Utils::printHex(MESH_CONSOLE_SERIAL, raw, len); + MESH_CONSOLE_SERIAL.println(); #endif } @@ -1043,7 +1043,7 @@ void MyMesh::dumpLogFile() { while (f.available()) { int c = f.read(); if (c < 0) break; - Serial.print((char)c); + MESH_CONSOLE_SERIAL.print((char)c); } f.close(); } @@ -1232,14 +1232,14 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply } } } else if (sender_timestamp == 0 && strcmp(command, "get acl") == 0) { - Serial.println("ACL:"); + MESH_CONSOLE_SERIAL.println("ACL:"); for (int i = 0; i < acl.getNumClients(); i++) { auto c = acl.getClientByIdx(i); if (c->permissions == 0) continue; // skip deleted (or guest) entries - Serial.printf("%02X ", c->permissions); - mesh::Utils::printHex(Serial, c->id.pub_key, PUB_KEY_SIZE); - Serial.printf("\n"); + MESH_CONSOLE_SERIAL.printf("%02X ", c->permissions); + mesh::Utils::printHex(MESH_CONSOLE_SERIAL, c->id.pub_key, PUB_KEY_SIZE); + MESH_CONSOLE_SERIAL.printf("\n"); } reply[0] = 0; } else if (memcmp(command, "discover.neighbors", 18) == 0) { diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 297337ab5c..d6ddf9c713 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -29,7 +29,7 @@ static unsigned long userBtnDownAt = 0; #endif void setup() { - Serial.begin(115200); + MESH_CONSOLE_SERIAL.begin(115200); delay(1000); board.begin(); @@ -86,8 +86,8 @@ void setup() { store.save("_main", the_mesh.self_id); } - Serial.print("Repeater ID: "); - mesh::Utils::printHex(Serial, the_mesh.self_id.pub_key, PUB_KEY_SIZE); Serial.println(); + MESH_CONSOLE_SERIAL.print("Repeater ID: "); + mesh::Utils::printHex(MESH_CONSOLE_SERIAL, the_mesh.self_id.pub_key, PUB_KEY_SIZE); MESH_CONSOLE_SERIAL.println(); command[0] = 0; @@ -109,12 +109,12 @@ void setup() { void loop() { int len = strlen(command); - while (Serial.available() && len < sizeof(command)-1) { - char c = Serial.read(); + while (MESH_CONSOLE_SERIAL.available() && len < sizeof(command)-1) { + char c = MESH_CONSOLE_SERIAL.read(); if (c != '\n') { command[len++] = c; command[len] = 0; - Serial.print(c); + MESH_CONSOLE_SERIAL.print(c); } if (c == '\r') break; } @@ -123,12 +123,12 @@ void loop() { } if (len > 0 && command[len - 1] == '\r') { // received complete line - Serial.print('\n'); + MESH_CONSOLE_SERIAL.print('\n'); command[len - 1] = 0; // replace newline with C string null terminator char reply[160]; the_mesh.handleCommand(0, command, reply); // NOTE: there is no sender_timestamp via serial! if (reply[0]) { - Serial.print(" -> "); Serial.println(reply); + MESH_CONSOLE_SERIAL.print(" -> "); MESH_CONSOLE_SERIAL.println(reply); } command[0] = 0; // reset command buffer @@ -141,7 +141,7 @@ void loop() { if (userBtnDownAt == 0) { userBtnDownAt = millis(); } else if ((unsigned long)(millis() - userBtnDownAt) >= USER_BTN_HOLD_OFF_MILLIS) { - Serial.println("Powering off..."); + MESH_CONSOLE_SERIAL.println("Powering off..."); board.powerOff(); // does not return } } else { diff --git a/src/MeshCore.h b/src/MeshCore.h index b4c57faf32..c424481a95 100644 --- a/src/MeshCore.h +++ b/src/MeshCore.h @@ -21,17 +21,21 @@ #define MAX_PATH_SIZE 64 #define MAX_TRANS_UNIT 255 +#ifndef MESH_CONSOLE_SERIAL + #define MESH_CONSOLE_SERIAL Serial +#endif + #if MESH_DEBUG && ARDUINO #include - #define MESH_DEBUG_PRINT(F, ...) Serial.printf("DEBUG: " F, ##__VA_ARGS__) - #define MESH_DEBUG_PRINTLN(F, ...) Serial.printf("DEBUG: " F "\n", ##__VA_ARGS__) + #define MESH_DEBUG_PRINT(F, ...) MESH_CONSOLE_SERIAL.printf("DEBUG: " F, ##__VA_ARGS__) + #define MESH_DEBUG_PRINTLN(F, ...) MESH_CONSOLE_SERIAL.printf("DEBUG: " F "\n", ##__VA_ARGS__) #else #define MESH_DEBUG_PRINT(...) {} #define MESH_DEBUG_PRINTLN(...) {} #endif #if BRIDGE_DEBUG && ARDUINO -#define BRIDGE_DEBUG_PRINTLN(F, ...) Serial.printf("%s BRIDGE: " F, getLogDateTime(), ##__VA_ARGS__) +#define BRIDGE_DEBUG_PRINTLN(F, ...) MESH_CONSOLE_SERIAL.printf("%s BRIDGE: " F, getLogDateTime(), ##__VA_ARGS__) #else #define BRIDGE_DEBUG_PRINTLN(...) {} #endif diff --git a/variants/rak3401/platformio.ini b/variants/rak3401/platformio.ini index 20a8a548b9..4675a9eebb 100644 --- a/variants/rak3401/platformio.ini +++ b/variants/rak3401/platformio.ini @@ -36,6 +36,8 @@ build_flags = -D MAX_NEIGHBOURS=50 ;-D MESH_PACKET_LOGGING=1 ;-D MESH_DEBUG=1 + ;-D MESH_CONSOLE_SERIAL=Serial1 + ;-UENV_INCLUDE_GPS ; GPS is on Serial1, enabling this line disables it build_src_filter = ${rak3401.build_src_filter} + +<../examples/simple_repeater>