i'm trying to send String from an Arduino(Uno) using the Serial. to an another Arduino(Uno). using nRF24l01+. and I'm using the library RF24.h the String is sended correctly but I have some problems with the acknowledgement.
This is my Rx code.
#include<SPI.h> #include<nRF24L01.h> #include<RF24.h> const uint64_t pipe[1]= {0xF0F0F0F0E1LL}; RF24 radio(9,10); char buf[32]= ""; char false_buf[32]= "MKJK212U1H7"; void setup() { Serial.begin(115200); radio.begin(); radio.setChannel(0x35); radio.setAutoAck(true); radio.enableAckPayload(); radio.enableDynamicPayloads(); radio.openReadingPipe(1,pipe[0]); radio.startListening(); radio.setRetries(1,15); radio.writeAckPayload( 1, false_buf, sizeof(false_buf) ); } void loop() { int OkMsg; while(!radio.available()){}; if ( radio.available() > 0) { radio.read(&buf,sizeof(buf) ); Serial.println(buf); radio.writeAckPayload( 1, buf, sizeof(false_buf) ); while(!radio.available()){}; if ( radio.available() > 0) { radio.read(&OkMsg,sizeof(OkMsg) ); Serial.println(OkMsg); if(OkMsg == 1){Serial.println("OkMsg's true!");} else {Serial.println("OkMsg's false!");} }} } and this is my Tx code
#include <SPI.h> #include <RF24.h> #include <nRF24L01.h> RF24 radio(9, 10); // CE, CSN const uint64_t pipe[1]= {0xF0F0F0F0E1LL}; char CharToSend[32]= "" ; char Ack[32]= "" ; String inputString = ""; String Allconfiguration = ""; boolean stringComplete = false; char inChar; boolean isConnected = false; int OkMsg = 0; void setup() { SPI.begin(); Serial.begin(115200); RadioSetupTransmiter(); } void loop() { if(stringComplete) { if(Allconfiguration.startsWith("\n")){Allconfiguration.remove(0,1);} Allconfiguration.remove(Allconfiguration.length()); inputString = ""; Serial.print("Allconfiguration : "); Serial.println(Allconfiguration); int counter = 0; for(int i=0; i<Allconfiguration.length(); i++) { if((Allconfiguration[i] == '\n')&&(i!=Allconfiguration.length())) { int pre_counter = counter; counter = i+1; inputString = Allconfiguration.substring(pre_counter, counter); if(inputString[0]!='$'){inputString.toCharArray(CharToSend,32);} if(radio.write(&CharToSend, sizeof(CharToSend))) {CheckData(); Serial.print("inputString : "); Serial.print(CharToSend);} } if(i == Allconfiguration.length()){ const char EndChar[2] = "$"; } inputString = ""; } Allconfiguration = ""; stringComplete = false; } } void serialEvent() { while (Serial.available()) { char inChar = (char)Serial.read(); Allconfiguration +=inChar; if (inChar == '$'){stringComplete = true; } } } void RadioSetupTransmiter(){ radio.begin(); radio.setChannel(0x35); delay(100); radio.setAutoAck( true ) ; radio.enableAckPayload(); radio.enableDynamicPayloads(); // radio.printDetails(); radio.stopListening(); radio.openWritingPipe(pipe[0]); radio.setRetries(1, 15); } void CheckData(){ int OkMsg = 0; while (!radio.isAckPayloadAvailable()){}; if(radio.isAckPayloadAvailable()) { radio.read(&Ack,sizeof(Ack)); //Serial.println(Ack); if(strcmp(CharToSend,Ack) == 0){ OkMsg = 1 ; Serial.println("AckRecived"); radio.write(&OkMsg,sizeof(OkMsg));} } }