Site icon Renzo Mischianti

ESP32 with Lora E32 not receiving data

Hi Renzo, I have 2 esp32-c6 devboards and i am using the below code. I am facing 2 issues 1.)Whenever sender is trying to send data and making AUX High, i get Serial disconnected. 2.)Receiver Unit is not receiving the data. Sending Data
//Sender
#include "Arduino.h"
#define E32_TTL_1W
#include "LoRa_E32.h"

#define AUX 23
#define M0 10
#define M1 11

//HardwareSerial serial1(2);

//LoRa_E32 e32ttl1w(&serial1,RX,TX, 18, UART_BPS_RATE_9600,SERIAL_8N1);
LoRa_E32 e32ttl1w(&Serial1, AUX, M0, M1);
void printParameters(struct Configuration configuration);
void printModuleInformation(struct ModuleInformation moduleInformation);

// Variables globales
unsigned long interval = 15000;          // interval between sends
unsigned long lastSendTime = 0;        // last send time
byte msgCount = 0;            // count of outgoing messages
long randNumber;
void setup() {
  //Inicio comunicacion serie con monitor
  Serial.begin(9600);
  delay(500);

  Serial.println();

  e32ttl1w.begin();

  //Configuro el nodo LoRa
  nodeConfig();
}

void loop() {
  // Wait a few seconds between measurements.

  if (millis() - lastSendTime > interval) {
    // print a random number from 10 to 19
    randNumber = random(10, 20);
    String trama = String(randNumber);
    ResponseStatus rs = e32ttl1w.sendFixedMessage(0x0, 0x3, 0x4, trama);
    Serial.println("Sending " + trama);
    Serial.println(rs.getResponseDescription());
    lastSendTime = millis();            // timestamp the message
    msgCount++;
  }
  delay(100);
}

void nodeConfig(){

  ResponseStructContainer c;
  c = e32ttl1w.getConfiguration();
  Configuration configuration = *(Configuration*) c.data;

  configuration.ADDH        = 0x0;
  configuration.ADDL        = 0x1;
  configuration.CHAN        = 0x4;

  configuration.SPED.airDataRate           = AIR_DATA_RATE_010_24;
  configuration.SPED.uartBaudRate          = UART_BPS_9600;
  configuration.SPED.uartParity            = MODE_00_8N1;
  configuration.OPTION.fec                 = FEC_1_ON;
  configuration.OPTION.fixedTransmission   = FT_FIXED_TRANSMISSION;
  configuration.OPTION.ioDriveMode         = IO_D_MODE_PUSH_PULLS_PULL_UPS;
  configuration.OPTION.transmissionPower   = POWER_21;
  configuration.OPTION.wirelessWakeupTime  = WAKE_UP_1250;
  //printParameters(configuration);

// Set configuration changed and set to not hold the configuration
  ResponseStatus rs = e32ttl1w.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
  Serial.print("Config: ");
  Serial.println(rs.getResponseDescription());
}
Receiver Unit Code
//Receiver Code
#include "Arduino.h"
#define E32_TTL_1W
#include "LoRa_E32.h"
#define AUX 1
#define M0 10
#define M1 11

LoRa_E32 e32ttl1w(&Serial1, AUX, M0, M1);

void setup() {
//Inicio comunicacion serie con monitor
	Serial.begin(9600);
	delay(500);
// Startup all pins and UART
	e32ttl1w.begin();
//Configuro el nodo LoRa
	nodeConfig();
  //delay(4000);
  //fetchConfig();
}

void loop() {
	if (e32ttl1w.available() > 0) {
		Serial.println("———-");
		ResponseContainer rc = e32ttl1w.receiveMessage();
// If something goes wrong print error
		if (rc.status.code != 1) {
			rc.status.getResponseDescription();
		} else {
// Print the data received
			Serial.println(rc.data);
		}
	}
	delay(100);
}

void nodeConfig() {
	ResponseStructContainer c;
	c = e32ttl1w.getConfiguration();
	Configuration configuration = *(Configuration*) c.data;
	configuration.ADDH = 0x0;
	configuration.ADDL = 0x3;
	configuration.CHAN = 0x4;
	configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
	configuration.SPED.uartBaudRate = UART_BPS_9600;
	configuration.SPED.uartParity = MODE_00_8N1;
	configuration.OPTION.fec = FEC_1_ON;
	configuration.OPTION.fixedTransmission = FT_FIXED_TRANSMISSION;
	configuration.OPTION.ioDriveMode = IO_D_MODE_PUSH_PULLS_PULL_UPS;
	configuration.OPTION.transmissionPower = POWER_30;
	configuration.OPTION.wirelessWakeupTime = WAKE_UP_1250;
// Set configuration changed and set to not hold the configuration
  Serial.println("Updtaed config is ");
	ResponseStatus rs = e32ttl1w.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
	Serial.print("Config: ");
	Serial.println(rs.getResponseDescription());
}
Exit mobile version