From db170b551164be99a76e98b9b31aecf57dde2b07 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Sat, 8 Feb 2025 21:23:45 -0500 Subject: [PATCH] ur dad support --- .../Feather9x_TX_RX_serial.ino | 54 +++++++++++++------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/Feather9x_TX_RX_serial/Feather9x_TX_RX_serial.ino b/Feather9x_TX_RX_serial/Feather9x_TX_RX_serial.ino index 8eec1b7..b7f5296 100644 --- a/Feather9x_TX_RX_serial/Feather9x_TX_RX_serial.ino +++ b/Feather9x_TX_RX_serial/Feather9x_TX_RX_serial.ino @@ -12,6 +12,15 @@ // Singleton instance of the radio driver RH_RF95 rf95(RFM95_CS, RFM95_INT); +int16_t packetnum = 0; +int16_t max_message_with_packet_num = RH_RF95_MAX_MESSAGE_LEN - 7; +int incomingByte = 0; + +// Serial imput +const byte numChars = RH_RF95_MAX_MESSAGE_LEN; +char receivedChars[numChars]; +char name[30]; + void setup() { pinMode(LED_BUILTIN, OUTPUT); pinMode(RFM95_RST, OUTPUT); @@ -48,18 +57,29 @@ void setup() { // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then // you can set transmitter powers from 5 to 23 dBm: rf95.setTxPower(23, false); + + Serial.println("Please enter your name: "); + int ndx = 0; + while (Serial.available() == 0) {} + while (Serial.available() > 0) { + // read the incoming byte: + incomingByte = Serial.read(); + // say what you got: + name[ndx] = incomingByte; + ndx++; + } + char send_name[RH_RF95_MAX_MESSAGE_LEN] = ""; + strcat(send_name, name); + strcat(send_name, " has joined the chat!"); + + Serial.print("Welcome "); + Serial.println(name); + rf95.send((uint8_t *)send_name, RH_RF95_MAX_MESSAGE_LEN); } -int16_t packetnum = 0; -int16_t max_message_with_packet_num = RH_RF95_MAX_MESSAGE_LEN - 7; -int incomingByte = 0; - -// Serial imput -const byte numChars = RH_RF95_MAX_MESSAGE_LEN; -char receivedChars[numChars]; - void loop() { memset(receivedChars, '\0', sizeof(receivedChars)); + int dataReceived = 0; int ndx = 0; @@ -75,16 +95,17 @@ void loop() { if (dataReceived) { dataReceived = 0; - Serial.print("Trying to send: "); - Serial.print(receivedChars); + Serial.print(name); + Serial.print(": "); + Serial.println(receivedChars); + + char actual_message[RH_RF95_MAX_MESSAGE_LEN]; + strcat(actual_message, name); + strcat(actual_message, ": "); + strcat(actual_message, receivedChars); // Transmit code - // Serial.println("Transmitting..."); // Send a message to rf95_server - - // Serial.print("Sending "); Serial.println(receivedChars); - - // Serial.println("Sending..."); delay(10); - rf95.send((uint8_t *)receivedChars, RH_RF95_MAX_MESSAGE_LEN); + rf95.send((uint8_t *)actual_message, RH_RF95_MAX_MESSAGE_LEN); // Serial.println("Waiting for packet to complete..."); delay(10); rf95.waitPacketSent(); @@ -98,7 +119,6 @@ void loop() { if (rf95.recv(buf, &len)) { digitalWrite(LED_BUILTIN, HIGH); // RH_RF95::printBuffer("Received: ", buf, len); - Serial.print("Got: "); Serial.println((char*)buf); // Serial.print("RSSI: "); // Serial.println(rf95.lastRssi(), DEC);