Preciso mandar uma string com informação de nrf24l01 para nrf24l01 ate chega em um para q posso manda para o banco de dados. Os código q fiz,tive como base o a biblioteca rf24.
Estou em dúvida em relação ao endereço pipe como atribuir e como manipular o openWritePipe ou openReadPipe. O código segue abaixa:
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
RF24 radio(9,10);
int inf[1];
int msg[1];
const uint64_t pipe = 0xE8E8F0F0E1LL;
String theMessage = "";
bool confirmar(String enviar){
if(enviar.length()==20){
return true;
}else{
return false;
}
}
void EnviarConfirmacao(bool confirmacao){
radio.stopListening();
if(confirmacao==true){
inf[0]=1;
radio.write( inf, 1);
}else{
inf[0]=0;
radio.write( inf, 1);
}
radio.startListening();
}
void setup(void){
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}
void loop(void){
if (radio.available()){
radio.read(msg, 1);
char theChar = msg[0];
if (msg[0] != -1){
theMessage.concat(theChar);
}
else {
Serial.println(theMessage);
if(confirmar(theMessage)){
Serial.println("Informação completa");
EnviarConfirmacao(confirmar(theMessage));
}
theMessage= "";
}
}
}
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
int inf[1];
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
String theMessage = "";
void EnviarDado(String enviar){
radio.stopListening();
int messageSize = enviar.length();
for (int i = 0; i < messageSize; i++) {
int charToSend[1];
charToSend[0] = enviar.charAt(i);
radio.write(charToSend,1);
}
//send the 'terminate string' value...
msg[0] = -1;
radio.write(msg,1);
radio.startListening();
}
bool confirmar(String enviar){
int x=0;
if(enviar.length()==20){
return true;
}else{
return false;
}
}
void EnviarConfirmacao(bool confirmacao){
radio.stopListening();
if(confirmacao==true){
inf[0]=1;
radio.write( inf, 1);
}else{
inf[0]=0;
radio.write( inf, 1);
}
radio.startListening();
}
void setup(void){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
radio.startListening();
}
int hora;
String theMessage = "22;22;22/22/22;22:22";
void loop(void){
if(radio.available()){
Enviardado(theMessage);
radio.read(inf, sizeof(inf));
if(inf[0]==1){
Serial.println("Confirmação recebida");
}else{
Serial.println("Informação incompleta");
}
}
Tags:
Bem-vindo a
Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)
© 2024 Criado por Marcelo Rodrigues. Ativado por