feature-requests icon indicating copy to clipboard operation
feature-requests copied to clipboard

Adding LoRa WAN support

Open stich86 opened this issue 5 years ago • 83 comments

Describe the problem you have/What new integration you would like Add support for LoRa WAN protocol like RFM95

Please describe your use case for this integration and alternatives you've tried:

it would be nice to integrate ESP between their self for various automation (like a far remote sensor)

Additional context

this is one of the primary library used on Arduino https://github.com/sandeepmistry/arduino-LoRa

stich86 avatar Mar 20 '19 17:03 stich86

In the german computer magazine c't was a project that contains an ATtiny and LoRaWan.

Maybe this can be used as an starting point?! Here is the link to the source code: c't Briefkastensensor

There is even a schematic to attach the LoRaWan module to the ATtiny which can maybe reused for the ESP32.

My use case: I have a remote network to supervise (in a basement) where there is no cellular or wifi network available (massive construction, tons of steel in the walls). I need to monitor the hosts in the network and report the data regularly. Power consumption is an issue here since the monitoring needs to be battery powered to work as well during a power outage. So any ESP is a must, i can't use a raspberry pi with HomeAssistant. LoRaWan does work here, so the transfer of sensor data via LoRa would work, when ESPHome can talk to the LoRa-Modem and transfer some payload regularly.

mseefeldt avatar May 23 '19 06:05 mseefeldt

Hi there.

I have been trying to integrate Lora functionalities to Esphome on ESP32 TTGO OLED V1 boards.

I have had some success in sending messages. I am stuck on the receiver part.

Please find bellow my code. Please excuse the limitation of my skills in coding, I am no expert at all in this field.

Sender Side :

lora_sender.yaml file :

esphome:
  name: lora_sender
  platform: ESP32
  board: ttgo-lora32-v1
  includes:
    - lora_sender.h
  libraries:
    - "LoRa"
    - "SPI"

wifi:
  ssid: "myssid"
  password: "mypwd"
  fast_connect: on
  
  manual_ip:
    static_ip: 192.168.0.XX
    gateway: 192.168.0.XX
    subnet: 255.255.255.0

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: 'mypwd'

ota:
  password: 'mypwd'

spi:
  clk_pin: GPIO5
  mosi_pin: GPIO27
  miso_pin: GPIO19

text_sensor:
- platform: custom
  lambda: |-
    auto lora_text_sensor = new lora_sender();
    App.register_component(lora_text_sensor);
    return {lora_text_sensor};

  text_sensors:
    name: "Lora Text Sensor"

The custom sensor code is lora_sender.h

#include "esphome.h"
#include "LoRa.h"
#include "SPI.h"

using namespace esphome;

class lora_sender : public PollingComponent, public text_sensor::TextSensor {
 public:
  // constructor
  lora_sender() : PollingComponent(15000) {}
  
  void setup() override {
      Serial.begin(115200);
      Serial.println("LoRa Sender");
      LoRa.setPins(18, 14, 26);
      if (!LoRa.begin(868E6)) {
        Serial.println("Starting LoRa failed!");
        while (1);
        delay(1000);
      }
Serial.println("Sending data packet...");
  }

  void update() override {
    // This will be called every "update_interval" milliseconds.
    // Publish state
    publish_state("Hello World");
    LoRa.beginPacket();
    LoRa.print("Hello World");
    LoRa.endPacket(); 
  }
};

This is obviously a very simple test case, as it pushes a simple string out. But I believe it is simple enough to adapt it to other cases.

I have validated that the messages gets properly sent by scanning RF with SDR.

Now for the receiving part, I am stuck on the custom text sensor definition. I don't know how to create a sensor that listen continuously (with continuous polling).

Any help would be appreciated.

Lefuneste83 avatar May 28 '19 09:05 Lefuneste83

Now for the receiving part, I am stuck on the custom text sensor definition. I don't know how to create a sensor that listen continuously (with continuous polling).

For that you can override the loop() method.

OttoWinter avatar May 28 '19 09:05 OttoWinter

Thank you Otto. Sorry for asking but can you point me to some example code ? As I said I am really coming back to coding, as I find your project worth spending some time upon... But I am absolutely a newbie in this field.

Lefuneste83 avatar May 28 '19 09:05 Lefuneste83

For example components/gps/gps.h - It's basically the same thing as here just that the loop function is now part of the component.

OttoWinter avatar May 28 '19 09:05 OttoWinter

Thank you Otto I will have a look at this and let you know.

Lefuneste83 avatar May 28 '19 10:05 Lefuneste83

Thank you Otto I will have a look at this and let you know.

thank you for your codes, lefuneste82 and Otto winter's guide.

Can you share custom codes for the lora_receive.h

If Lora supports in ESPHOME , It will be more useful platform for the IOT things.

I wish I can integrate with Lora.

thank you for your trial Lefuneste83. : )

minsuke avatar Dec 13 '19 02:12 minsuke

I'm also looking forward to get lora supported in esphome. I ordered some SX1278 modules (Ra-02 Ai-Thinker with 433mhz) to make some tests.

My goal is to connect two different home assistant setup's/networks which are some kilometers apart. Idea is to have a esphome node on each side (in their own network/own home assistant instance) which are listening to some home assistant (binary)sensors and pushing a message via lora to the other esphome node when a (binary)sensor changes. So it should be possible to mirror states from one home assistant instance/network to another. Great! Isn't it? So much the theory...

rradar avatar Dec 25 '19 21:12 rradar

I think I found two very interesting libraries which could be useful for this:

https://github.com/sandeepmistry/arduino-LoRa

  • Support for LoRa Semtech SX1276/77/78/79

https://github.com/jgromes/RadioLib

Supported modules:

  • CC1101 FSK radio module
  • ESP8266 WiFi module
  • HC05 Bluetooth module
  • JDY08 BLE module
  • nRF24L01 2.4 GHz module
  • RF69 FSK/OOK radio module
  • RFM9x series LoRa modules (RFM95, RM96, RFM97, RFM98)
  • SX127x series LoRa modules (SX1272, SX1273, SX1276, SX1277, SX1278, SX1279)
  • SX126x series LoRa modules (SX1261, SX1262, SX1268)
  • SX1231 FSK/OOK radio module
  • XBee modules (S2B)

The second one is a bigger (not limited to lora) but very active project

rradar avatar Dec 29 '19 10:12 rradar

My goal is to connect two different home assistant setup's/networks which are some kilometers apart.

Have you looked at the duty cycle limits for the 433mhz band? You might come close to exceeding that with a somewhat smart smart house.

beikeland avatar Jan 09 '20 16:01 beikeland

Hey All, I wanted to share with you my custom code for a lora reciever. I'm using it at the moment as a gateway for two lora nodes, one for my power-meter in the basement, that is based on an arduino pro mini, and the second one as a mailbox sensor, that is based on an attiny84, similar to the one mentioned earlier from c't. I'm using the LoRa library for my RFM95 Lora modules and I included also some AES128 encryption with Crypto/CryptoLW library, the attiny84 limited the encryption to only AES128 due to RAM limits.

lora_gateway.yaml file:


esphome:
  name: lora_gateway
  platform: ESP32
  board: esp32dev
  includes:
    - lora_gateway.h
  libraries:
    - "LoRa"
    - "SPI"
    - "CryptoLW"
    - "Crypto"
    - "ArduinoJson-esphomelib"

wifi:
  ssid: "myssid"
  password: "mywlanpswd"
  fast_connect: on
  
  manual_ip:
    static_ip: 192.168.178.XXX
    gateway: 192.168.178.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Fallback Hotspot"
    password: "pswd"

captive_portal:

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:
  password: "apipswd"

ota:
  password: "otapswd"
  
# Enable SPI for LoRa
spi:
  clk_pin: GPIO18
  mosi_pin: GPIO23
  miso_pin: GPIO19
  

sensor:
  - platform: custom
    lambda: |-
      auto lora_sensor = new MyLoRaSensors();
      App.register_component(lora_sensor);
      return {lora_sensor->zaehler_sensor_id, 
              lora_sensor->zaehler_sensor_stand,
              lora_sensor->zaehler_sensor_power,
              lora_sensor->zaehler_sensor_elaps,
              lora_sensor->zaehler_sensor_msg,
              lora_sensor->zaehler_sensor_rssi,
              lora_sensor->zaehler_sensor_vbat,
              lora_sensor->mbox_sensor_post,
              lora_sensor->mbox_sensor_msg,
              lora_sensor->mbox_sensor_rssi,
              lora_sensor->mbox_sensor_vbat};
    sensors:
    - name: "Zählernummer"
      accuracy_decimals: 0
      icon: mdi:counter
    - name: "Zählerstand"
      unit_of_measurement: kWh
      accuracy_decimals: 4
      icon: mdi:counter
    - name: "Wirkleistung"
      unit_of_measurement: W
      accuracy_decimals: 0
      icon: mdi:gauge
    - name: "Zählersender: letzte Nachricht vor"
      unit_of_measurement: s
      accuracy_decimals: 0
      icon: mdi:timelapse
    - name: "Zählersender: Nachricht #"
      accuracy_decimals: 0
      icon: mdi:message-processing-outline
    - name: "Zählersender: Signalstärke"
      unit_of_measurement: dBm
      accuracy_decimals: 0
      icon: mdi:signal
    - name: "Zählersender: Batteriespannung"
      unit_of_measurement: V
      accuracy_decimals: 3
      icon: mdi:battery
    - name: "Briefkasten"
      accuracy_decimals: 0
      icon: mdi:email-box
    - name: "Briefkastensender: Nachricht #"
      accuracy_decimals: 0
      icon: mdi:message-processing-outline
    - name: "Briefkastensender: Signalstärke"
      unit_of_measurement: dBm
      accuracy_decimals: 0
      icon: mdi:signal
    - name: "Briefkastensender: Batteriespannung"
      unit_of_measurement: V
      accuracy_decimals: 3
      icon: mdi:battery

The custom reciever code lora_gateway.h:


#include "esphome.h"
#include "SPI.h"
#include "LoRa.h"
#include "Crypto.h"
#include "AES.h"
#include "CTR.h"
#include "string.h"
#include "ArduinoJson.h"

using namespace esphome;

#define csPin 5        // LoRa radio chip select
#define resetPin 21    // LoRa radio reset // -1 for not in use
#define dio0Pin 2      // change for your board; must be a hardware interrupt pin
#define freq 868700000 // LoRa used frequency 868 MHz
#define SF 7           // LoRa used spreadingFactor // ranges from 6-12,default 7 see API docs
#define bw 125E3       // LoRa signal bandwidth in Hz, defaults to 125E3
#define sw 0x12        // LoRa SyncWord ranges from 0-0xFF, default 0x12, see LoRa API docs		!!! MUST be equal on Lora sensor nodes and gateway

#define MAX_PLAINTEXT_SIZE 134
#define MAX_CIPHERTEXT_SIZE 134

byte key[16] = {0x01, 0x02, 0x0b, 0x5b, 0xc6, 0x6e, 0xa5, 0xa3, 0xfa, 0x1a, 0xf7, 0xf3, 0x8d, 0xc3, 0x7a, 0xbc}; // The very secret key !!! MUST be equal on Lora sensor nodes and gateway
byte iv[16] = {0xa7, 0x8a, 0x23, 0x2d, 0xed, 0x1c, 0x77, 0xd8, 0xfd, 0xab, 0x8b, 0x13, 0xc4, 0x8d, 0xb1, 0xf3};	//!!! MUST be equal on Lora sensor nodes and gateway
byte ciphertext[MAX_PLAINTEXT_SIZE] = {0};
byte plaintext[MAX_CIPHERTEXT_SIZE] = {0};
byte old_ciphertext[MAX_PLAINTEXT_SIZE] = {0};
String receive_buf = "";
String rssi = "";
String msg_Zaehler = "";
String msg_Briefkasten = "";
long Z_VBat = 0;   // 4066345
long Z_ID = 0;       // 12345678
long Z_Stand = 0; // 1130810033
int Z_Pow = 0;      // 1350
int Z_Elaps = 0;  // 32
long Z_msg = 0;     // 32452
int Z_RSSI = 0;    // -123
long B_VBat = 0; // 4066345
bool B_Post = 0; // 1
long B_msg = 0;   // 32452
int B_RSSI = 0;  // -123

CTR<AES128> ctr;

/*--------------------------------------------------------------------------------
                            LoRa Data Recieved
--------------------------------------------------------------------------------*/
void onReceive(int packetSize)
{
  // received a packet
  //ESP_LOGD("custom", "Received packet '");

  // read packet
  LoRa.readBytes(ciphertext, MAX_CIPHERTEXT_SIZE);
  //ESP_LOGD("custom", "%s", ciphertext);

  // print RSSI of packet
  rssi = "";
  rssi = String(LoRa.packetRssi());
  //ESP_LOGD("custom", "' with RSSI %s", rssi);
}

/*--------------------------------------------------------------------------------
                                  Decode Massage
--------------------------------------------------------------------------------*/
void decode_msg()
{
  ctr.clear();
  ctr.setKey(key, ctr.keySize());
  ctr.setIV(iv, ctr.ivSize());

  memset(plaintext, 0xBA, sizeof(plaintext));	// reset plaintext variable before next decryption

  ctr.decrypt(plaintext, ciphertext, sizeof(ciphertext));	// decrypt new massage

  receive_buf = (char*)plaintext;
  
  //ESP_LOGD("custom", (char*)ciphertext);
  //ESP_LOGD("custom", (char*)plaintext);
  //ESP_LOGD("custom", receive_buf.c_str());
}

/*--------------------------------------------------------------------------------
                           Json String parsing
--------------------------------------------------------------------------------*/
// {"Sensor":"Zaehler","VBat":4066345,"ID":12345678,"Stand":1130810033,"Pow":1350,"Elaps":32,"msg":32452,"RSSI":-123}
// {\"Sensor\":\"Zaehler\",\"VBat\":4066345,\"ID\":12345678,\"Stand\":1130810033,\"Pow\":1350,\"Elaps\":32,\"msg\":32452,\"RSSI\":-123}
void json_data_pars(String json)
{
  const size_t capacity = JSON_OBJECT_SIZE(8) + 60;
  DynamicJsonBuffer  jsonBuffer(capacity);

  JsonObject& doc = jsonBuffer.parseObject(json);

  String Sens = doc["Sensor"]; // "Zaehler"
  
  if (Sens == "Zaehler")
  {
    //msg_Zaehler = json;
	//ESP_LOGD("custom", "%s", msg_Zaehler);
    
    Z_VBat = doc["VBat"];   // 4066345
    Z_ID = doc["ID"];       // 12345678
    Z_Stand = doc["Stand"]; // 1130810033
    Z_Pow = doc["Pow"];      // 1350
    Z_Elaps = doc["Elaps"];  // 32
    Z_msg = doc["msg"];     // 32452
    Z_RSSI = doc["RSSI"];    // -123
	
    /*ESP_LOGD("custom", "%s", Sens.c_str());
    ESP_LOGD("custom", "%li", Z_VBat);
    ESP_LOGD("custom", "%li", Z_ID);
    ESP_LOGD("custom", "%li", Z_Stand);
    ESP_LOGD("custom", "%i", Z_Pow);
    ESP_LOGD("custom", "%i", Z_Elaps);
    ESP_LOGD("custom", "%li", Z_msg);
    ESP_LOGD("custom", "%i", Z_RSSI);*/
  }
  else if (Sens == "MBox")
  {
    //msg_Briefkasten = json;
	//ESP_LOGD("custom", "%s", msg_Briefkasten);
    
    B_VBat = doc["VBat"]; // 4066345
    B_Post = doc["Post"]; // 1
    B_msg = doc["msg"];   // 32452
    B_RSSI = doc["RSSI"];  // -123
	
	/*ESP_LOGD("custom", "%s", Sens.c_str());
    ESP_LOGD("custom", "%li", B_VBat);
    ESP_LOGD("custom", "%i", B_Post);
    ESP_LOGD("custom", "%li", B_msg);
    ESP_LOGD("custom", "%i", B_RSSI);*/
  }
}


class MyLoRaSensors : public PollingComponent {
 public:
  Sensor *zaehler_sensor_id = new Sensor();
  Sensor *zaehler_sensor_stand = new Sensor();
  Sensor *zaehler_sensor_power = new Sensor();
  Sensor *zaehler_sensor_elaps = new Sensor();
  Sensor *zaehler_sensor_msg = new Sensor();
  Sensor *zaehler_sensor_rssi = new Sensor();
  Sensor *zaehler_sensor_vbat = new Sensor();
  Sensor *mbox_sensor_post = new Sensor();
  Sensor *mbox_sensor_msg = new Sensor();
  Sensor *mbox_sensor_rssi = new Sensor();
  Sensor *mbox_sensor_vbat = new Sensor();
  
  MyLoRaSensors() : PollingComponent(4000) { }
  
  void setup() override {
    // This will be called by App.setup()
	
	LoRa.setPins(csPin, resetPin, dio0Pin); // set CS, reset, IRQ pin

	if (!LoRa.begin(freq)) // initialize radio at "freq" MHz
	{
		ESP_LOGD("custom", "LoRa init failed. Check your connections.");
		while (true); // if failed, do nothing
		//delay(1000);
	}
	//LoRa.setSpreadingFactor(SF);          // set spreadingFactor
	//LoRa.setSignalBandwidth(bw);          // set signal bandwidth
	LoRa.setSyncWord(sw);					// set SyncWord
	ESP_LOGD("custom", "LoRa init succeeded.");
	ESP_LOGD("custom", "Frequency %d Bandwidth %E SF %i SyncWord %x", freq, bw, SF, sw);
	ESP_LOGD("custom", "LoRa Connection ready...");

	// register the receive callback and put the radio into receive mode
	LoRa.onReceive(onReceive);
	LoRa.receive();
  }
  
  void update() override {
    // This will be called by App.loop()
	if (memcmp(old_ciphertext, ciphertext, MAX_CIPHERTEXT_SIZE) != 0)	// check if radio recieved new massage
	{
		decode_msg();
		receive_buf.replace("\"xxx\"", rssi);
		json_data_pars(receive_buf);
		
		zaehler_sensor_id->publish_state(Z_ID);
		zaehler_sensor_stand->publish_state(Z_Stand*0.0001);
		zaehler_sensor_power->publish_state(Z_Pow);
		zaehler_sensor_elaps->publish_state(Z_Elaps);
		zaehler_sensor_msg->publish_state(Z_msg);
		zaehler_sensor_rssi->publish_state(Z_RSSI);
		zaehler_sensor_vbat->publish_state(Z_VBat*0.000001);
		mbox_sensor_post->publish_state(B_Post);
		mbox_sensor_msg->publish_state(B_msg);
		mbox_sensor_rssi->publish_state(B_RSSI);
		mbox_sensor_vbat->publish_state(B_VBat*0.000001);
		
		for (uint8_t i = 0; i 

With this code I'm getting all the sensors publishing the values into HA.

Johni81 avatar Jan 10 '20 18:01 Johni81

@Johni81 do you mind sharing your code for the one of the senders? Im looking to do a mailbox sender with lora, and might take a whack at it with your code. Thanks!

BrewNinja avatar Jan 15 '20 19:01 BrewNinja

@BrewNinja here is my code for the mailbox sender.


#include <Arduino.h>
#include <ATTinyCore.h>
#include <SPI.h>
#include <LoRa.h>
#include <Crypto.h>
#include <AES.h>
#include <CTR.h>
#include <string.h>
#include <avr/sleep.h>
#include <avr/wdt.h>

// ATMEL ATTINY84 / ARDUINO
//
//                           +-\/-+
//                     VCC  1|    |14  GND
//             (D  0)  PB0  2|    |13  PA0  (D 10)        AREF
//             (D  1)  PB1  3|    |12  PA1  (D  9)
//             (D 11)  PB3  4|    |11  PA2  (D  8)
//  PWM  INT0  (D  2)  PB2  5|    |10  PA3  (D  7)
//  PWM        (D  3)  PA7  6|    |9   PA4  (D  6)
//  PWM        (D  4)  PA6  7|    |8   PA5  (D  5)        PWM
//                           +----+

// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
#define statusled 2    // LED for control
#define irled 1        // power for ir-led of proximity sensor (invisible)
#define irdiode 0      // power in for diode in proximity sensor
#define irsens PA0     //adc pin (connect to output of sensor)
#define csPin 7        // LoRa radio chip select
#define resetPin -1    // LoRa radio reset // -1 for not in use
#define dio0Pin 3      // change for your board; must be a hardware interrupt pin
#define freq 868700000 // LoRa used frequency 868 MHz
#define SF 7           // LoRa used spreadingFactor // ranges from 6-12,default 7 see API docs
#define bw 125E3       // LoRa signal bandwidth in Hz, defaults to 125E3
#define sw 0x12        // LoRa SyncWord ranges from 0-0xFF, default 0x12, see LoRa API docs

// define a threshold for your mailbox.
#define THRESHOLD 15

#define MAX_PLAINTEXT_SIZE 82
#define MAX_CIPHERTEXT_SIZE 82

byte key[16] = {0x01, 0x02, 0x0b, 0x5b, 0xc6, 0x6e, 0xa5, 0xa3, 0xfa, 0x1a, 0xf7, 0xf3, 0x8d, 0xc3, 0x7a, 0xbc}; // The very secret key
byte iv[16] = {0xa7, 0x8a, 0x23, 0x2d, 0xed, 0x1c, 0x77, 0xd8, 0xfd, 0xab, 0x8b, 0x13, 0xc4, 0x8d, 0xb1, 0xf3};
byte ciphertext[MAX_CIPHERTEXT_SIZE] = {0};
uint16_t msgCount = 0; // count of outgoing messages
long vbat = 0;
bool post = 0;
bool post_old = 0;
int sleepCycles = 1;

CTR<AESTiny128> ctr;

/*--------------------------------------------------------------------------------
                                    Setup
--------------------------------------------------------------------------------*/
void setup()
{
  Serial.begin(9600); // TX is AIN0, RX is AIN1
  pinMode(irled, OUTPUT);
  pinMode(irdiode, OUTPUT);
  pinMode(statusled, OUTPUT);

  LoRa.setPins(csPin, resetPin, dio0Pin); // set CS, reset, IRQ pin

  if (!LoRa.begin(freq))
  { // initialize radio at "freq" MHz
    //Serial.println("LoRa init fail");
    while (true)
      ; // if failed, do nothing
  }
  //LoRa.setSpreadingFactor(SF);          // set spreadingFactor
  //LoRa.setSignalBandwidth(bw);          // set signal bandwidth
  LoRa.setSyncWord(sw); // set SyncWord
  //Serial.println("LoRa init");

  //Serial.println("Connected");
}

/*--------------------------------------------------------------------------------
                          Überprüfung auf Briefkasteninhalt
--------------------------------------------------------------------------------*/
void checkLetter()
{
  digitalWrite(irled, HIGH);
  digitalWrite(irdiode, HIGH);
  unsigned int measure;
  for (int i = 0; i  THRESHOLD)
  {
    post = 1;
  }
  else
  {
    post = 0;
  }
}

/*--------------------------------------------------------------------------------
                          Batteriespannung ermitteln
--------------------------------------------------------------------------------*/
void getVbat()
{
  // Select ADC inputs
  // bit    76543210
  // REFS = 00       = Vcc used as Vref
  // MUX  =   100001 = Single ended, 1.1V (Internal Ref) as Vin
  ADMUX = _BV(MUX5) | _BV(MUX0); // oder	ADMUX = 0b00100001;
  /*
		After switching to internal voltage reference the ADC requires a settling time of 1ms before
		measurements are stable. Conversions starting before this may not be reliable. The ADC must
		be enabled during the settling time.
	*/
  delay(2);
  /*
		The first conversion after switching voltage source may be inaccurate, and the user is advised to discard this result.
	*/
  ADCSRA |= _BV(ADSC); // Start a conversion
  while (bit_is_set(ADCSRA, ADSC))
    ;   // Wait for 1st conversion to be ready...
        //..and ignore the result
  uint8_t low = ADCL;
  uint8_t high = ADCH;
  uint16_t vbat = (high 

Johni81 avatar Jan 15 '20 20:01 Johni81

Appreciate it! Thank you!

BrewNinja avatar Jan 15 '20 20:01 BrewNinja

I wonder if the title should be changed to "Add LoRa support". Because as far as I understand is it all about LoRa here and not about LoRa WAN (yet).

Maybe the LoRa support could be added to the already existing remote_receiver and remote_transmitter components of esphome?

rradar avatar Jan 19 '20 15:01 rradar

@Johni81 thank you very much for your sketch.

I was able to get a wemos d1 mini with a Ai-Thinker RA-02 433 Lora Module with SX1278 up and running as a receiver with your code. Little modifications for my 433Mhz module in lora_gateway.h are:

#define csPin 15       // LoRa radio chip select
#define resetPin 16    // LoRa radio reset // -1 for not in use
#define dio0Pin 5      // change for your board; must be a hardware interrupt pin
#define freq 433000000 // LoRa used frequency 433 MHz
#define SF 7           // LoRa used spreadingFactor // ranges from 6-12,default 7 see API docs
#define bw 125E3       // LoRa signal bandwidth in Hz, defaults to 125E3
#define sw 0x12        // LoRa SyncWord ranges from 0-0xFF, default 0x12, see LoRa API docs		!!! MUST be equal on Lora sensor nodes and gateway

and my spi pins on the wemos d1 mini are:

spi:
  clk_pin: D5
  mosi_pin: D7
  miso_pin: D6

My wiring:

   ESP8266      -  RA-02
	Gpio15/D8   - NSS
	Gpio13/D7   - MOSI
	Gpio12/D6   - MISO
	Gpio14/D5   - SCK
	Gpio05/D1   - DIO0
	Gpio16/D0   - RST
	VCC         - 3.3V
	GND         - GND

Now I wonder what's needed to get another pair of this (esp&ra-02) acting as a sender. My idea is to forward (binary)sensor data the esphome node is knowing (from local or home assistant) anyways.

Could this be possible? :thinking:

rradar avatar Jan 31 '20 12:01 rradar

unstale this bot :smiling_imp:

rradar avatar Apr 05 '20 11:04 rradar

Any Chance this will get properly implemented in Esphome ?

JonathanTreffler avatar Jun 24 '20 12:06 JonathanTreffler

Any Chance this will get properly implemented in Esphome ?

@TessyPowder I guess the best would to support RadioLib but I could imaging that it is a bunch of work to integrate into esphome

rradar avatar Jun 29 '20 12:06 rradar

+1 desire for an official LORA integration with ESPHOME!

philletourneau avatar Jul 11 '20 15:07 philletourneau

+1 desire for an official LORA integration with ESPHOME!

acelauwc avatar Sep 05 '20 06:09 acelauwc

+1 desire for an official LORA integration with ESPHOME!

maxparrela avatar Oct 12 '20 20:10 maxparrela

+1 desire for an official LORA integration with ESPHOME!

cristianm avatar Oct 24 '20 12:10 cristianm

+1 :-)

pauldogg avatar Nov 02 '20 03:11 pauldogg

+1 Also if some esphome developer needs a LORA device I'll chip in !

thekoma avatar Nov 10 '20 17:11 thekoma

Hi. I really like to have LORA for my home automation system. It makes my WIFI issues disappear in a second. Please add the support. Thank you in advance!

AquaMCU avatar Nov 15 '20 14:11 AquaMCU

I have researched LORA a little bit. I think for starters, it would be nice to be able to initialize a LORA module as a sender and receiver. It would be nice to have something like LORA.send (STRING) and some kind of event when the receiving end gets a message.

That way you could set up a very simple LORA connection between two devices.

Do you think this is possible?

AquaMCU avatar Nov 17 '20 12:11 AquaMCU

@AquaMCU no, because this is a feature request.

gretel avatar Nov 17 '20 21:11 gretel

I know. So where would you go and post a feature request like this? How can the community fund this development? I think there are some guys interested in this. Do you want to do some kind of bug bounty or a kick starter?

Oliver

P.s. I already donated 50$ for this to Otto and I would add another 50 to some kind of bug bounty.

AquaMCU avatar Nov 18 '20 06:11 AquaMCU

Best bet would be to drop into discord and possibly reddit and see if anyone is interested. As mentioned, radiolib looks like a promising way to integrate, but it would still take someone's time to actually add it. I think this is a no-brainer for adding functionality, but the issue is finding someone who is interested in actually doing the adding.

BrewNinja avatar Nov 18 '20 13:11 BrewNinja