jgromes / RadioLib

Universal wireless communication library for embedded devices
https://jgromes.github.io/RadioLib/
MIT License
1.49k stars 377 forks source link

RADIOLIB_ERR_TX_TIMEOUT #443

Closed alemori closed 2 years ago

alemori commented 2 years ago

The problem I have is that the transmitter gives me a time out error, but still the transmission is done.

Sketch that is causing the module fail Emisor

/*
   RadioLib SX127x Transmit Example

   This example transmits packets using SX1278 LoRa radio module.
   Each packet contains up to 256 bytes of data, in the form of:
    - Arduino String
    - null-terminated char array (C-string)
    - arbitrary binary data (byte array)

   Other modules from SX127x/RFM9x family can also be used.

   For default module settings, see the wiki page
   https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem

   For full API reference, see the GitHub Pages
   https://jgromes.github.io/RadioLib/
*/

// include the library
#include <RadioLib.h>

// SX1278 has the following connections:
// NSS pin:   10
// DIO0 pin:  2
// RESET pin: 9
// DIO1 pin:  3
SX1278 radio = new Module(10, 2, 9, 3);

// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;

void setup() {
  Serial.begin(9600);

 // carrier frequency:           434.0 MHz
  // bandwidth:                   125.0 kHz
  // spreading factor:            9
  // coding rate:                 6
  // sync word:                   0x14
  // output power:                10 dBm
  // preamble length:             8 symbols
  // amplifier gain:              0 (maximum gain)
  int state = radio.begin(434.0, 125.0, 9, 6, 0x12, 10, 8, 0);

  // initialize SX1278 with default settings
  Serial.print(F("[SX1278] Initializing ... "));
//   state = radio.begin();
  if (state == RADIOLIB_ERR_NONE) {
    Serial.println(F("success!"));
  } else {
    Serial.print(F("failed, code "));
    Serial.println(state);
    while (true);
  }

  // some modules have an external RF switch
  // controlled via two pins (RX enable, TX enable)
  // to enable automatic control of the switch,
  // call the following method
  // RX enable:   4
  // TX enable:   5
  /*
    radio.setRfSwitchPins(4, 5);
  */
}

void loop() {
  Serial.print("[SX1278] Transmitting packet ... ");

  // you can transmit C-string or Arduino string up to
  // 256 characters long
  // NOTE: transmit() is a blocking method!
  //       See example SX127x_Transmit_Interrupt for details
  //       on non-blocking transmission method.
  int state = radio.transmit("yy World!");
  Serial.println(" success!");
  // you can also transmit byte array up to 256 bytes long
  /*
    byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
    int state = radio.transmit(byteArr, 8);
  */
Serial.println(state);
  if (state == RADIOLIB_ERR_NONE) {
    // the packet was successfully transmitted
    Serial.println(" success!");

    // print measured data rate
    Serial.print(F("[SX1278] Datarate:\t"));
    Serial.print(radio.getDataRate());
    Serial.println(" bps"); }
 if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
    // the supplied packet was longer than 256 bytes
    Serial.println("too long!");}

 if (state == RADIOLIB_ERR_TX_TIMEOUT) {
    // timeout occurred while transmitting packet
    Serial.println("timeout!");}

  // wait for a second before transmitting again
  delay(1000);
}

Receive

   /*
   LoRaLib Receive Example

   This example listens for LoRa transmissions and tries to
   receive them. To successfully receive data, the following
   settings have to be the same on both transmitter 
   and receiver:
    - carrier frequency
    - bandwidth
    - spreading factor
    - coding rate
    - sync word
    - preamble length

   For more detailed information, see the LoRaLib Wiki
   https://github.com/jgromes/LoRaLib/wiki
*/

#include <ESP8266WiFi.h>
//#include "index.h"
//#include "index2.h"
//#include "index21.h"
#include "index3.h"
//#include "index4.h"
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

// include the library

#include <RadioLib.h>

// SX1278 has the following connections:
// NSS pin:   10
// DIO0 pin:  2
// RESET pin: 9
// DIO1 pin:  3
SX1278 radio = new Module(15, 5, 16, 4);

ESP8266WebServer server(80);

int state;
String Calibra1;
String str;
const char ssid[] = "Campo ";    //Definimos la SSDI de nuestro servidor WiFi -nombre de red- 
const char password[] = "12345678";       //Definimos la contraseña de nuestro servidor 
IPAddress ip(192, 168, 4, 1); // IP que asigno al AP
IPAddress netmask(255, 255, 255, 0);

String s3 = MAIN_page3; //Read HTML contents

void Calibracion(){

 WiFi.reconnect();

 server.send(200, "text/html", s3); //Send web page

}

void Calibra(){

 Calibra1 = str; 
 server.send(200, "text/html", Calibra1); //Send web page

}

void setup() {
  Serial.begin(9600);

  // carrier frequency:           434.0 MHz
  // bandwidth:                   430.0 kHz
  // spreading factor:            9
  // coding rate:                 6
  // sync word:                   0x14
  // output power:                10 dBm
  // preamble length:             8 symbols
  // amplifier gain:              0 (maximum gain)
  state = radio.begin(434.0, 125.0, 9, 6, 0x12, 10, 8, 0);

  // initialize SX1278 with default settings
  Serial.print(F("[SX1278] Initializing ... "));

  if (state == RADIOLIB_ERR_NONE) {
    Serial.println(F("success!"));
  } else {
    Serial.print(F("failed, code "));
    Serial.println(state);
    while (true);
  }

WiFi.persistent(false);
 // Esto habilita la salida del debug para el wifi
 //Serial.setDebugOutput(true)
 // ===============================
 //Si quiero hacer un restar del esp puedo utilizar 
 // ESP.restart();
 //ESP.getChipId() devuelve el ID del chip ESP8266 como un entero de 32 bits.
 int xxx=ESP.getChipId(); 
 //while (!xxx==16658883){return;}

 Serial.println(ESP.getChipId());
 // ESP.getFlashChipId() devuelve la ID del chip flash como un entero de 32 bits.
 // ESP.getVcc()se puede usar para medir el voltaje de suministro. ESP necesita reconfigurar el ADC al inicio para que esta característica esté disponible. Agregue la siguiente línea al principio de su boceto para usar getVcc:
 WiFi.setAutoConnect (true);
  WiFi.setAutoReconnect (true);
  WiFi.mode(WIFI_AP);
  WiFi.softAPConfig( IPAddress ( 192 , 168 , 4 , 1 ), IPAddress ( 192 , 168 , 4 , 1 ), IPAddress ( 255 , 255 , 255 , 0 ));
  //WiFi.mode(WIFI_AP_STA);
  //WiFi.mode(WIFI_AP);
  WiFi.softAP(ssid, password,4);            //Red con clave, en el canal 1 y visible
  //WiFi.softAP(ssid, password,3,1);      //Red con clave, en el canal 3 y visible 
  //WiFi.softAP(ssid);                    //Red abierta

  delay(500);
  Serial.print("Direccion IP Access Point - por defecto: ");      //Imprime la dirección IP
  Serial.println(WiFi.softAPIP()); 
  Serial.print("Direccion MAC Access Point: ");                   //Imprime la dirección MAC
  Serial.println(WiFi.softAPmacAddress()); 

  //IPAddress local_ip(192, 168, 1, 1);                           //Modifica la dirección IP 
  //IPAddress gateway(192, 168, 1, 1);   
  //IPAddress subnet(255, 255, 255, 0);
  //WiFi.softAPConfig(local_ip, gateway, subnet);
  //Serial.println();
  //Serial.print("Access Point - Nueva direccion IP: ");
  //Serial.println(WiFi.softAPIP());
   server.begin();                         //inicializamos el servidor

   Serial.println(ESP.getChipId());

server.on("/Calibracion", Calibracion);
server.on("/Calibra", Calibra);

}

void loop() {
  Serial.print(F("[SX1278] Waiting for incoming transmission ... "));

  // you can receive data as an Arduino String
  // NOTE: receive() is a blocking method!
  //       See example ReceiveInterrupt for details
  //       on non-blocking reception method.
  String str;
  int state = radio.receive(str);

  // you can also receive data as byte array
  /*
    byte byteArr[8];
    int state = radio.receive(byteArr, 8);
  */

  if (state == RADIOLIB_ERR_NONE) {
    // packet was successfully received
    Serial.println(F("success!"));

    // print the data of the packet
    Serial.print(F("[SX1278] Data:\t\t\t"));
    Serial.println(str);

    // print the RSSI (Received Signal Strength Indicator)
    // of the last received packet
    Serial.print(F("[SX1278] RSSI:\t\t\t"));
    Serial.print(radio.getRSSI());
    Serial.println(F(" dBm"));

    // print the SNR (Signal-to-Noise Ratio)
    // of the last received packet
    Serial.print(F("[SX1278] SNR:\t\t\t"));
    Serial.print(radio.getSNR());
    Serial.println(F(" dB"));

    // print frequency error
    // of the last received packet
    Serial.print(F("[SX1278] Frequency error:\t"));
    Serial.print(radio.getFrequencyError());
    Serial.println(F(" Hz"));

  } else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
    // timeout occurred while waiting for a packet
    Serial.println(F("timeout!"));

  } else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
    // packet was received, but is malformed
    Serial.println(F("CRC error!"));

  } else {
    // some other error occurred
    Serial.print(F("failed, code "));
    Serial.println(state);

  }
}

Hardware setup

The emitter is an arduino nano with a loara ra-02 a-thinker module the connections are: Lora - nano. 15-10 14-11 13-12 12-13 4-9 5-2 6-3 The receiver is a wemos d1 mini and lora ra-02 a-thinker. the connections are: lora wemos 15-d8 14-d7 13-d6 12-d5 4-d0 5-d1 6-d2

Wiring diagram, schematic, pictures etc.

Debug mode output

SX1278] Initializing ... success!
[SX1278] Transmitting packet ... R  1   89  
R   1   89  
W   1   89  
R   1   89  
R   1   89  
R   1D  74  
R   1E  90  
R   20  0   
R   21  8   
R   1   89  
R   1   89  
W   1   89  
R   1   89  
R   1   89  
R   40  0   
W   40  40  
R   40  40  
R   1   89  
W   12  FF  
R   22  1   
W   22  9   
R   22  9   
R   E   80  
W   E   0   
R   E   0   
R   D   0   
W   D   0   
R   D   0   
W   0   79  79  20  57  6F  72  6C  64  21  
R   1   89  
R   1   89  
W   1   8B  
R   1   8B  
R   1   89  
W   12  FF  
 success!
-5
timeout!

Additional info (please complete):

jgromes commented 2 years ago

still the transmission is done.

How have you verified that? By reception of the packet?

Apparent Tx timeout can be caused by bad connection on the DIO0 pin.

alemori commented 2 years ago

Hello, I made a change of micro, because all roads said that the problem was physical, and luckily the error disappeared. Thank you very much for your prompt response.