From f9867c1844c94b833b8f95a57d8f6ab43d5efebf Mon Sep 17 00:00:00 2001 From: ducoterra Date: Sat, 8 Feb 2025 21:39:00 -0500 Subject: [PATCH] fix strcpy vs strcat issue --- Feather9x_TX_RX_serial/Feather9x_TX_RX_serial.ino | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Feather9x_TX_RX_serial/Feather9x_TX_RX_serial.ino b/Feather9x_TX_RX_serial/Feather9x_TX_RX_serial.ino index b7f5296..46fa218 100644 --- a/Feather9x_TX_RX_serial/Feather9x_TX_RX_serial.ino +++ b/Feather9x_TX_RX_serial/Feather9x_TX_RX_serial.ino @@ -19,7 +19,7 @@ int incomingByte = 0; // Serial imput const byte numChars = RH_RF95_MAX_MESSAGE_LEN; char receivedChars[numChars]; -char name[30]; +char chatName[30]; void setup() { pinMode(LED_BUILTIN, OUTPUT); @@ -65,15 +65,15 @@ void setup() { // read the incoming byte: incomingByte = Serial.read(); // say what you got: - name[ndx] = incomingByte; + chatName[ndx] = incomingByte; ndx++; } char send_name[RH_RF95_MAX_MESSAGE_LEN] = ""; - strcat(send_name, name); + strcpy(send_name, chatName); strcat(send_name, " has joined the chat!"); Serial.print("Welcome "); - Serial.println(name); + Serial.println(chatName); rf95.send((uint8_t *)send_name, RH_RF95_MAX_MESSAGE_LEN); } @@ -95,12 +95,12 @@ void loop() { if (dataReceived) { dataReceived = 0; - Serial.print(name); + Serial.print(chatName); Serial.print(": "); Serial.println(receivedChars); char actual_message[RH_RF95_MAX_MESSAGE_LEN]; - strcat(actual_message, name); + strcpy(actual_message, chatName); strcat(actual_message, ": "); strcat(actual_message, receivedChars); @@ -122,6 +122,7 @@ void loop() { Serial.println((char*)buf); // Serial.print("RSSI: "); // Serial.println(rf95.lastRssi(), DEC); + digitalWrite(LED_BUILTIN, LOW); } } }