diff --git a/Feather9x_TX_RX_serial/Feather9x_TX_RX_serial.ino b/Feather9x_TX_RX_serial/Feather9x_TX_RX_serial.ino index 84309fb..6664264 100644 --- a/Feather9x_TX_RX_serial/Feather9x_TX_RX_serial.ino +++ b/Feather9x_TX_RX_serial/Feather9x_TX_RX_serial.ino @@ -56,22 +56,38 @@ int incomingByte = 0; // Serial imput const byte numChars = RH_RF95_MAX_MESSAGE_LEN; +char receivedChars[numChars]; void loop() { - // Transmit code - delay(1000); // Wait 1 second between transmits, could also 'sleep' here! - 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"; - itoa(packetnum++, radiopacket+max_message_with_packet_num, 10); - Serial.print("Sending "); Serial.println(radiopacket); - - // Serial.println("Sending..."); delay(10); - rf95.send((uint8_t *)radiopacket, RH_RF95_MAX_MESSAGE_LEN); + strcpy(receivedChars, ""); + int dataReceived = 0; - // Serial.println("Waiting for packet to complete..."); delay(10); - rf95.waitPacketSent(); + 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 + 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); + + // Serial.println("Waiting for packet to complete..."); delay(10); + rf95.waitPacketSent(); + } // Receiver code if (rf95.available()) { // Should be a message for us now @@ -82,26 +98,9 @@ void loop() { digitalWrite(LED_BUILTIN, HIGH); // RH_RF95::printBuffer("Received: ", buf, len); Serial.print("Got: "); - // Serial.println((char*)buf); + Serial.println((char*)buf); // Serial.print("RSSI: "); // 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); - } }