serial transmission working!

This commit is contained in:
2025-02-08 20:47:35 -05:00
parent 36acf609a2
commit 0218469e70

View File

@@ -56,22 +56,38 @@ 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];
void loop() { void loop() {
strcpy(receivedChars, "");
int dataReceived = 0;
while (Serial.available() > 0) {
dataReceived = 1;
static byte ndx = 0;
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
receivedChars[ndx] = incomingByte;
ndx++;
}
if (dataReceived) {
dataReceived = 0;
Serial.print("I received: ");
Serial.println(receivedChars);
// Transmit code // Transmit code
delay(1000); // Wait 1 second between transmits, could also 'sleep' here!
Serial.println("Transmitting..."); // Send a message to rf95_server Serial.println("Transmitting..."); // Send a message to rf95_server
char radiopacket[RH_RF95_MAX_MESSAGE_LEN] = " You can't read thisf dsa fdsa fdsa fdsa fdsa fdsa fdsa fdsa fdsa fdsf"; Serial.print("Sending "); Serial.println(receivedChars);
itoa(packetnum++, radiopacket+max_message_with_packet_num, 10);
Serial.print("Sending "); Serial.println(radiopacket);
// Serial.println("Sending..."); delay(10); // Serial.println("Sending..."); delay(10);
rf95.send((uint8_t *)radiopacket, RH_RF95_MAX_MESSAGE_LEN); rf95.send((uint8_t *)receivedChars, RH_RF95_MAX_MESSAGE_LEN);
// Serial.println("Waiting for packet to complete..."); delay(10); // Serial.println("Waiting for packet to complete..."); delay(10);
rf95.waitPacketSent(); rf95.waitPacketSent();
}
// Receiver code // Receiver code
if (rf95.available()) { if (rf95.available()) {
// Should be a message for us now // Should be a message for us now
@@ -82,26 +98,9 @@ void loop() {
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, HIGH);
// RH_RF95::printBuffer("Received: ", buf, len); // RH_RF95::printBuffer("Received: ", buf, len);
Serial.print("Got: "); Serial.print("Got: ");
// Serial.println((char*)buf); Serial.println((char*)buf);
// Serial.print("RSSI: "); // Serial.print("RSSI: ");
// Serial.println(rf95.lastRssi(), DEC); // Serial.println(rf95.lastRssi(), DEC);
} }
} }
char receivedChars[numChars];
int dataReceived = 0;
while (Serial.available() > 0) {
dataReceived = 1;
static byte ndx = 0;
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
receivedChars[ndx] = incomingByte;
ndx++;
}
if (dataReceived) {
dataReceived = 0;
Serial.print("I received: ");
Serial.println(receivedChars);
}
} }