Envio de ficheiros entre nRF24L01

Boas pessoal,

Já alguém encontrou algum exemplo para envio de ficheiros entre nRF24L01? Já pesquisei e aparece pouca coisa.
O ficheiro a enviar seria do tipo *.WAV . Nas minhas pesquisas encontrei uma coisa semelhante para ethernet. Deverá ser adaptável com alguma ajuda :slight_smile:

// Wave format file transfer demo for Arduino Mega over Ethernet
// Author: Bruno Senzio-Savino Barzellato
// V 1.0
// Notes: Transfer function can be optimized for filename and buffer size input
// December 1, 2016

// So far no data for this, decided to upload it for people that might consider this
// useful :)

//Using SdFat library
#include <SdFat.h>
SdFat sd;

#include <SPI.h>
#include <Ethernet2.h>

// SD chip select pin
const uint8_t chipSelect = 53; //Connect SD Card to pins 50, 51, 52 and 53 

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x10,0xCA,0x90 };

IPAddress server(10, 10, 6, 93); //SERVER IP ADDRESS

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(10,10,4,15); //ARDUINO IP ADDRESS

// Initialize the Ethernet client library
// with the IP address and port of the server
EthernetClient client;
int localport =19126;
// print stream
ArduinoOutStream cout(Serial);

//------------------------------------------------------------------------------
// store error strings in flash memory
#define error(s) sd.errorHalt_P(PSTR(s))
//------------------------------------------------------------------------------
void ftransfer() {

  char rbuffer[1024]; //Chunk can be increased to bigger sizes, be careful about memory!!
  char c;
  int n;
  // open test file
  SdFile rdfile("test.wav", O_READ); // <--- Name of file to be transfered

  //Obtain file size
  uint32_t fsize;
  fsize = rdfile.fileSize() - rdfile.curPosition();
  
  Serial.println(fsize);
  // check for open error
  if (!rdfile.isOpen()) error("File could not be opened, check configuration...");

    // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("Connecting to server for transfer...");
 Serial.println(Ethernet.localIP());
  // if you get a connection, report back via serial:
  if (client.connect(server, localport)) {
    Serial.println("Connected");

  while ((n = rdfile.fgets(rbuffer, sizeof(rbuffer))) > 0) {
       client.write(rbuffer, sizeof(rbuffer)-1);
  }
    
    client.stop();
  }
  else {
    // No response from server reply
    Serial.println("No server available");
  }

}
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
void setup(void) {

  //Allow communications for SD Card ant Ethernet Shield
  pinMode(10, OUTPUT);                       
  digitalWrite(10, HIGH);                    
  
  Serial.begin(9600);
  while (!Serial) {}  // Wait for Leonardo

  cout << pstr("Type any character to start\n");
  while (Serial.read() <= 0) {}
  delay(400);  // catch Due reset problem
  
  // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  if (!sd.begin(chipSelect, SPI_FULL_SPEED)) sd.initErrorHalt();
  
  ftransfer();
  
  cout << pstr("\nDone\n");
}

void loop(void) {}

Acho que tens bastante para fazer de forma a conseguires enviar um ficheiro... O nRF24L01 não funciona como um interface Ethernet.

Já tens dois arduinos a falar de forma consistente através dos nRF? Eu começaria por aí. Eu tive um sistema com eles a funcionar em casa e arranquei os poucos cabelos que tenho para os fazer funcionar.

Olá @Bubulindo.

Aquilo é um bocado diferente, de facto, do ethernet. Um colega sugeriu o uso de WEBSockets hoje. Ainda tenho de ir estudar um bocado para ver se serve (não conheço a técnica). Outro colega sugeriu que tentasse "desmembrar" o ficheiro e enviar grupos de 32 Bytes, sem ACK (parece-me mais próximo da realidade, mas ainda sem certezas).

Tenho 2 setups distintos, um com dois nanos e nRF24L01 e enviam mensagens simples entre si (observáveis na serial port) e outro com arduino due a fazer o mesmo.
Além desses dois, tenho dois walkie talkies com o Nano, baseados na RF24Audio do TMRH20.

A ideia é fazer algo do tipo, enviar uma mensagem de voz, gravada préviamente num SDCard, em diferido. É isso que ando a estudar. Vou analisar a possibilidade de usar a lib RF24Ethernet, para ver se consigo lá chegar. De qualquer das formas, continuo a pesquisar a ver se consigo analisar mais exemplos, porque o meu nível de programação é razoável, mas não é lá muito bom :slight_smile:
Todavia, obrigado pelas dicas. I'll keep you posted.

A ideia do teu colega acerca dos grupos de 32 bytes parece-me melhor... mas tem cuidado com várias tramas perdidas e o efeito que isso terá na mensagem.

Umas das possibilidades é o uso de Ack. A outra é se no fim do envio sizeofmsg for igual nos dois intervenientes, pode-se considerar que em em principio a msg passou correctamente.

Sim. O Ack vai atrasar a comunicação... enquanto que 32 bits numa mensagem de centenas ou milhares deles não faz diferença alguma (que é o conceito usado em Multicast com Ethernet).