working version

This commit is contained in:
cally22
2023-07-08 22:43:44 +02:00
parent dc5f14256e
commit c55b7fc4ed
5 changed files with 160 additions and 32 deletions
+55 -7
View File
@@ -8,12 +8,45 @@ void RadioController::setup(int cepin, int cspin) {
Serial.println("Error initializing radio");
} else {
Serial.println("Succesfully initializing radio");
radio.openWritingPipe(writePipe);
radio.openReadingPipe(1, readPipe);
radio.setPALevel(RF24_PA_MAX);
radio.disableDynamicPayloads();
radio.setAutoAck(false);
radio.setRetries(5, 15);
// radio.openWritingPipe(writePipe);
// radio.openReadingPipe(1, readPipe);
// radio.setPALevel(RF24_PA_MAX);
// radio.disableDynamicPayloads();
// radio.setAutoAck(false);
// radio.setRetries(5, 15);
// radio.setDataRate( RF24_250KBPS );
// radio.openReadingPipe(1, readPipe);
// radio.enableAckPayload();
// radio.startListening();
uint8_t address[][6] = { "1Node", "2Node" };
// Set the PA Level low to try preventing power supply related problems
// because these examples are likely run with nodes in close proximity to
// each other.
radio.setPALevel(RF24_PA_LOW); // RF24_PA_MAX is default.
// to use ACK payloads, we need to enable dynamic payload lengths (for all nodes)
radio.enableDynamicPayloads(); // ACK payloads are dynamically sized
// Acknowledgement packets have no payloads by default. We need to enable
// this feature for all nodes (TX & RX) to use ACK payloads.
radio.enableAckPayload();
// set the TX address of the RX node into the TX pipe
radio.openWritingPipe(address[1]); // always uses pipe 0
// set the RX address of the TX node into a RX pipe
radio.openReadingPipe(1, address[0]); // using pipe 1
// load the payload for the first received transmission on pipe 0
// radio.writeAckPayload(1, &payload, sizeof(payload));
radio.startListening(); // put radio in RX mode
}
}
@@ -30,7 +63,6 @@ void RadioController::send(String msg) {
}
String RadioController::receive() {
radio.startListening();
String msg = "";
if (radio.available()) {
@@ -41,3 +73,19 @@ String RadioController::receive() {
return msg;
}
String RadioController::receiveAck(String textToSend) {
String msg = "";
if (radio.available()) {
char receivedText[32] = "";
uint8_t bytes = radio.getDynamicPayloadSize(); // get the size of the payload
radio.read(&receivedText, bytes); // read only the first 'bytes' from the payload
msg = String(receivedText);
char ack[8];
textToSend.substring(0, 8).toCharArray(ack, sizeof(ack));
radio.writeAckPayload(1, &ack, sizeof(ack));
}
return msg;
}