serial transmission working!
This commit is contained in:
@@ -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() {
|
||||||
// Transmit code
|
strcpy(receivedChars, "");
|
||||||
delay(1000); // Wait 1 second between transmits, could also 'sleep' here!
|
int dataReceived = 0;
|
||||||
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);
|
|
||||||
|
|
||||||
// Serial.println("Waiting for packet to complete..."); delay(10);
|
while (Serial.available() > 0) {
|
||||||
rf95.waitPacketSent();
|
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
|
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user