fix strcpy vs strcat issue
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user