Renzo Mischianti
Published © CC BY-NC-SA

LoRa E32 Device for Arduino, ESP32 or ESP8266: Library

My project is a library for E32 LoRa (Long Range) device very cheap and long range (from 3Km to 8Km), to simplify usage and conf.

BeginnerFull instructions provided1 hour25,827
LoRa E32 Device for Arduino, ESP32 or ESP8266: Library

Things used in this project

Story

Read more

Schematics

Arduino E32 schematics

Code

Code snippet #2

Plain text
#include "LoRa_E32.h"

LoRa_E32 e32ttl100(2, 3); // RX, TX
// LoRa_E32 e32ttl100(2, 3, 5, 6, 7); // RX, TX

Code snippet #4

Plain text
#include <SoftwareSerial.h>
#include "LoRa_E32.h"

SoftwareSerial mySerial(2, 3); // RX, TX
LoRa_E32 e32ttl100(&amp;mySerial);
// LoRa_E32 e32ttl100(&amp;mySerial, 5, 7, 6);

Code snippet #8

Plain text
		ResponseStructContainer getConfiguration();
		ResponseStatus setConfiguration(Configuration configuration, PROGRAM_COMMAND saveType = WRITE_CFG_PWR_DWN_LOSE);

		ResponseStructContainer getModuleInformation();
        void printParameters(struct Configuration configuration);
        ResponseStatus resetModule();

Code snippet #10

Plain text
  SUCCESS = 1,
  ERR_UNKNOWN,
  ERR_NOT_SUPPORT,
  ERR_NOT_IMPLEMENT,
  ERR_NOT_INITIAL,
  ERR_INVALID_PARAM,
  ERR_DATA_SIZE_NOT_MATCH,
  ERR_BUF_TOO_SMALL,
  ERR_TIMEOUT,
  ERR_HARDWARE,
  ERR_HEAD_NOT_RECOGNIZED

Code snippet #11

Plain text
		ResponseContainer rs = e32ttl.receiveMessage();
		String message = rs.data;

		Serial.println(rs.status.getResponseDescription());
		Serial.println(message);

Code snippet #12

Plain text
	ResponseStructContainer c;
	c = e32ttl100.getConfiguration();
	// It's important get configuration pointer before all other operation
	Configuration configuration = *(Configuration*) c.data;
	Serial.println(c.status.getResponseDescription());
	Serial.println(c.status.code);

Code snippet #14

Plain text
	ResponseStructContainer c;
	c = e32ttl100.getConfiguration();
	// It's important get configuration pointer before all other operation
	Configuration configuration = *(Configuration*) c.data;
	Serial.println(c.status.getResponseDescription());
	Serial.println(c.status.code);
        Serial.println(configuration.SPED.getUARTBaudRate());

Code snippet #15

Plain text
	configuration.ADDL = 0x0; // First part of address
	configuration.ADDH = 0x1; // Second part of address
	configuration.CHAN = 0x19;// Channel

	configuration.OPTION.fec = FEC_0_OFF; // Forward error correction switch
	configuration.OPTION.fixedTransmission = FT_TRANSPARENT_TRANSMISSION; // Transmission mode
	configuration.OPTION.ioDriveMode = IO_D_MODE_PUSH_PULLS_PULL_UPS; // Pull-up management
	configuration.OPTION.transmissionPower = POWER_17; // dBm transmission power 
	configuration.OPTION.wirelessWakeupTime = WAKE_UP_1250; // Wait time for wake up

	configuration.SPED.airDataRate = AIR_DATA_RATE_011_48; // Air data rate
	configuration.SPED.uartBaudRate = UART_BPS_115200; // Communication baud rate
	configuration.SPED.uartParity = MODE_00_8N1; // Parity bit

Code snippet #16

Plain text
	Serial.print(F("Chan : "));  Serial.print(configuration.CHAN, DEC); Serial.print(" -> "); Serial.println(configuration.getChannelDescription());
	Serial.println(F(" "));
	Serial.print(F("SpeedParityBit     : "));  Serial.print(configuration.SPED.uartParity, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getUARTParityDescription());
	Serial.print(F("SpeedUARTDatte  : "));  Serial.print(configuration.SPED.uartBaudRate, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getUARTBaudRate());
	Serial.print(F("SpeedAirDataRate   : "));  Serial.print(configuration.SPED.airDataRate, BIN);Serial.print(" -> "); Serial.println(configuration.SPED.getAirDataRate());

	Serial.print(F("OptionTrans        : "));  Serial.print(configuration.OPTION.fixedTransmission, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getFixedTransmissionDescription());
	Serial.print(F("OptionPullup       : "));  Serial.print(configuration.OPTION.ioDriveMode, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getIODroveModeDescription());
	Serial.print(F("OptionWakeup       : "));  Serial.print(configuration.OPTION.wirelessWakeupTime, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getWirelessWakeUPTimeDescription());
	Serial.print(F("OptionFEC          : "));  Serial.print(configuration.OPTION.fec, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getFECDescription());
	Serial.print(F("OptionPower        : "));  Serial.print(configuration.OPTION.transmissionPower, BIN);Serial.print(" -> "); Serial.println(configuration.OPTION.getTransmissionPowerDescription());

Code snippet #18

Plain text
	ResponseStructContainer c;
	c = e32ttl100.getConfiguration();
	// It's important get configuration pointer before all other operation
	Configuration configuration = *(Configuration*) c.data;
	Serial.println(c.status.getResponseDescription());
	Serial.println(c.status.code);

	printParameters(configuration);
	configuration.ADDL = 0x0;
	configuration.ADDH = 0x1;
	configuration.CHAN = 0x19;

	configuration.OPTION.fec = FEC_0_OFF;
	configuration.OPTION.fixedTransmission = FT_TRANSPARENT_TRANSMISSION;
	configuration.OPTION.ioDriveMode = IO_D_MODE_PUSH_PULLS_PULL_UPS;
	configuration.OPTION.transmissionPower = POWER_17;
	configuration.OPTION.wirelessWakeupTime = WAKE_UP_1250;

	configuration.SPED.airDataRate = AIR_DATA_RATE_011_48;
	configuration.SPED.uartBaudRate = UART_BPS_115200;
	configuration.SPED.uartParity = MODE_00_8N1;

	// Set configuration changed and set to not hold the configuration
	ResponseStatus rs = e32ttl100.setConfiguration(configuration, WRITE_CFG_PWR_DWN_LOSE);
	Serial.println(rs.getResponseDescription());
	Serial.println(rs.code);
	printParameters(configuration);

Code snippet #23

Plain text
// One of 
#define FREQUENCY_433 
#define FREQUENCY_170
#define FREQUENCY_470
#define FREQUENCY_868
#define FREQUENCY_915

Code snippet #27

Plain text
       if (e32ttl.available()  > 1){
		ResponseContainer rs = e32ttl.receiveMessage();
		String message = rs.data; // First ever get the data
		Serial.println(rs.status.getResponseDescription());
		Serial.println(message);
	}

Code snippet #29

Plain text
	struct Messaggione {
		char type[5];
		char message[8];
		bool mitico;
	};
        struct Messaggione messaggione = {"TEMP", "Peple", true};
        ResponseStatus rs = e32ttl.sendMessage(&amp;messaggione, sizeof(Messaggione));
	Serial.println(rs.getResponseDescription());

Code snippet #30

Plain text
		ResponseStructContainer rsc = e32ttl.receiveMessage(sizeof(Messaggione));
		struct Messaggione messaggione = *(Messaggione*) rsc.data;
		Serial.println(messaggione.message);
		Serial.println(messaggione.mitico);

Code snippet #32

Plain text
		struct Messaggione { // Partial strucutre without type
			char message[8];
			bool mitico;
		};

		char type[5]; // first part of structure
		ResponseContainer rs = e32ttl.receiveInitialMessage(sizeof(type));
                // Put string in a char array (not needed)
		memcpy ( type, rs.data.c_str(), sizeof(type) );

		Serial.println("READ TYPE: ");
		Serial.println(rs.status.getResponseDescription());
		Serial.println(type);

                // Read the rest of structure
		ResponseStructContainer rsc = e32ttl.receiveMessage(sizeof(Messaggione));
		struct Messaggione messaggione = *(Messaggione*) rsc.data;

Code snippet #38

Plain text
        ResponseStructContainer c;
	c = e32ttl100.getConfiguration();
	// It's important get configuration pointer before all other operation
	Configuration configuration = *(Configuration*) c.data;
	Serial.println(c.status.getResponseDescription());
	Serial.println(c.status.code);

	printParameters(configuration);
	configuration.ADDL = BROADCAST_ADDRESS;
	configuration.ADDH = BROADCAST_ADDRESS;

	// Set configuration changed and set to not hold the configuration
	ResponseStatus rs = e32ttl100.setConfiguration(configuration, WRITE_CFG_PWR_DWN_LOSE);
	Serial.println(rs.getResponseDescription());
	Serial.println(rs.code);
	printParameters(configuration);

Github

https://github.com/xreef/LoRa_E32_Series_Library

Credits

Renzo Mischianti

Renzo Mischianti

35 projects • 45 followers
Software developer but I love electronics, wood, nature, and everything else as well. Now blogger? on www.mischianti.org

Comments