fix strcpy vs strcat issue
This commit is contained in:
@@ -19,7 +19,7 @@ int incomingByte = 0;
|
|||||||
// Serial imput
|
// Serial imput
|
||||||
const byte numChars = RH_RF95_MAX_MESSAGE_LEN;
|
const byte numChars = RH_RF95_MAX_MESSAGE_LEN;
|
||||||
char receivedChars[numChars];
|
char receivedChars[numChars];
|
||||||
char name[30];
|
char chatName[30];
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
@@ -65,15 +65,15 @@ void setup() {
|
|||||||
// read the incoming byte:
|
// read the incoming byte:
|
||||||
incomingByte = Serial.read();
|
incomingByte = Serial.read();
|
||||||
// say what you got:
|
// say what you got:
|
||||||
name[ndx] = incomingByte;
|
chatName[ndx] = incomingByte;
|
||||||
ndx++;
|
ndx++;
|
||||||
}
|
}
|
||||||
char send_name[RH_RF95_MAX_MESSAGE_LEN] = "";
|
char send_name[RH_RF95_MAX_MESSAGE_LEN] = "";
|
||||||
strcat(send_name, name);
|
strcpy(send_name, chatName);
|
||||||
strcat(send_name, " has joined the chat!");
|
strcat(send_name, " has joined the chat!");
|
||||||
|
|
||||||
Serial.print("Welcome ");
|
Serial.print("Welcome ");
|
||||||
Serial.println(name);
|
Serial.println(chatName);
|
||||||
rf95.send((uint8_t *)send_name, RH_RF95_MAX_MESSAGE_LEN);
|
rf95.send((uint8_t *)send_name, RH_RF95_MAX_MESSAGE_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,12 +95,12 @@ void loop() {
|
|||||||
|
|
||||||
if (dataReceived) {
|
if (dataReceived) {
|
||||||
dataReceived = 0;
|
dataReceived = 0;
|
||||||
Serial.print(name);
|
Serial.print(chatName);
|
||||||
Serial.print(": ");
|
Serial.print(": ");
|
||||||
Serial.println(receivedChars);
|
Serial.println(receivedChars);
|
||||||
|
|
||||||
char actual_message[RH_RF95_MAX_MESSAGE_LEN];
|
char actual_message[RH_RF95_MAX_MESSAGE_LEN];
|
||||||
strcat(actual_message, name);
|
strcpy(actual_message, chatName);
|
||||||
strcat(actual_message, ": ");
|
strcat(actual_message, ": ");
|
||||||
strcat(actual_message, receivedChars);
|
strcat(actual_message, receivedChars);
|
||||||
|
|
||||||
@@ -122,6 +122,7 @@ void loop() {
|
|||||||
Serial.println((char*)buf);
|
Serial.println((char*)buf);
|
||||||
// Serial.print("RSSI: ");
|
// Serial.print("RSSI: ");
|
||||||
// Serial.println(rf95.lastRssi(), DEC);
|
// Serial.println(rf95.lastRssi(), DEC);
|
||||||
|
digitalWrite(LED_BUILTIN, LOW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user