Replies: 15 comments 50 replies
-
I don't now why PR3309 is linked to that Lora discussion but it's not related at all I understand your use case, using Tasmota as a bridge/gateway from Lora to MQTT just like already supported for Bluetooth or Zigbee makes sense when using far remote sensors Unfortunately no-one has ever proposed to work on that feature. How is the connection between the Lora chip and the ESP32 ? |
Beta Was this translation helpful? Give feedback.
-
I have quite some experience with using RF95W chips for LoRa and LoraWAN (LoraGw, STM32L0LoraTx, STM32L0TTN, ...). I think, LoraWAN with Tasmota makes no sense. Sensordata goes through special and relatively expensive gateways (at least compared to rf or zigbee bridges) to a cloud (here TTN) where you can already query the data with http, mqtt and more. Sensors are usually "out there" with no or low power and often no wlan - not an ESP/Tasmota domain. Pure LoRa would be a better match, but also not perfect: the LoRa chip communicates via SPI. |
Beta Was this translation helpful? Give feedback.
-
There is a well maintained solution for such a gateway https://github.com/1technophile/OpenMQTTGateway/releases |
Beta Was this translation helpful? Give feedback.
-
// Tasmota LoRa driver
// easyhan.pt
#define LORA_VERSION "2024.02.19.2347"
#ifdef USE_LORA_V1
#warning **** LORA_V1 Driver is included... ****
#define XDRV_101 101
// This variable will be set to true after initialization
bool initSuccess = false;
char *payload = nullptr;
size_t payload_size = 512;
char *topic = nullptr;
size_t topic_size = 50;
// LoRa
#include <LoRa.h>
// esp8266
#define LORA_SCK 14
#define LORA_MISO 12
#define LORA_MOSI 13
#define LORA_SS 15
#define LORA_RST -1
#define LORA_DI0 5
// ### CHA_CHA_POLY ###
#include "../../easyhan_secrets_cha.h"
#include "ChaChaPolyHelper.h"
byte iv[CHA_CHA_POLY_IV_SIZE];
// ### CHA_CHA_POLY EOF ###
// **********************
void LoRaInit() {
//
payload = (char *)calloc(payload_size, sizeof(char));
topic = (char *)calloc(topic_size, sizeof(char));
if (!payload || !topic) {
AddLog(LOG_LEVEL_INFO, PSTR("LORA: out of memory"));
return;
}
AddLog(LOG_LEVEL_INFO, PSTR("LORA: Init..."));
SPI.begin();
LoRa.setPins(LORA_SS, LORA_RST, LORA_DI0);
LoRa.setSyncWord(0x12);
if (!LoRa.begin(868E6)) {
while (true)
;
}
AddLog(LOG_LEVEL_INFO, PSTR("LORA: SCK %d"), LORA_SCK);
AddLog(LOG_LEVEL_INFO, PSTR("LORA: MISO %d"),
LORA_MISO);
AddLog(LOG_LEVEL_INFO, PSTR("LORA: MOSI %d"),
LORA_MOSI);
AddLog(LOG_LEVEL_INFO, PSTR("LORA: SS %d"), LORA_SS);
AddLog(LOG_LEVEL_INFO, PSTR("LORA: RST %d"), LORA_RST);
AddLog(LOG_LEVEL_INFO, PSTR("LORA: DI0 %d"), LORA_DI0);
LoRa.receive();
// Set initSuccess at the very end of the init process
// Init is successful
initSuccess = true;
} // end LoRaInit
void LoRaWork(void) {
//
int packetSize = LoRa.parsePacket();
if (packetSize) {
AddLog(LOG_LEVEL_INFO,
PSTR("LORA: Packet received !"));
byte rxArray[packetSize];
for (uint8_t i = 0; i < packetSize; i++) {
rxArray[i] = (char)LoRa.read();
}
bool noVerify = false;
uint8_t polySize =
CHA_CHA_POLY_TAG_SIZE + CHA_CHA_POLY_IV_SIZE;
if (packetSize > polySize & packetSize < 250) {
// ### if packet size is Cha Cha ###
byte tag[CHA_CHA_POLY_TAG_SIZE];
byte plainText[sizeof(rxArray) - polySize];
byte cipherText[sizeof(plainText)];
// copy arrays
memcpy(cipherText, rxArray, sizeof(cipherText));
memcpy(tag, &rxArray[sizeof(cipherText)],
sizeof(tag));
memcpy(iv,
&rxArray[sizeof(cipherText) + sizeof(tag)],
sizeof(iv));
// clear array
for (uint8_t i = 0; i < sizeof(plainText); i++) {
plainText[i] = 0xff;
}
// decrypt message from cipherText to plainText
// output is valid only if result is true
bool verify = ChaChaPolyCipher.decrypt(
key, iv, auth, cipherText, plainText, tag);
if (verify) {
// hex to json
// LORAdata["byte0"] = plainText[0];
// LORAdata["byte1"] = plainText[1];
uint32_t up = plainText[2] << 24 |
plainText[3] << 16 |
plainText[4] << 8 | plainText[5];
AddLog(LOG_LEVEL_INFO,
PSTR("LORA: Packet valid ! Up: %d"), up);
snprintf_P(topic, topic_size,
PSTR("home/lora/eb1"));
snprintf_P(payload, payload_size,
PSTR("{\"id\":\"eb1\",\"up\":%d}"),
up);
// retain = true
MqttPublishPayload(topic, payload,
strlen(payload), false);
} // eof if verify
else {
noVerify = true;
} // eof else if verify
} // eof if packet size is cha cha true
else {
noVerify = true;
}
if (noVerify) {
//
AddLog(LOG_LEVEL_INFO,
PSTR("LORA: Packet invalid !"));
} // if noVerify
} // end if packetSize
} // end LoRaWork
void LoRaJson(bool json) {
if (json) {
//
} else {
WSContentSend_PD("{s}LoRa Gateway {m} {e}");
WSContentSend_PD("{s}Build: " LORA_VERSION
" {m} {e}");
WSContentSend_PD("{s}<br>{m} {e}");
float tmpHeap = ESP.getFreeHeap() / 1000.0;
WSContentSend_PD("{s}Free Heap{m} %1_f kB{e}",
&tmpHeap);
} // eof !json
} // HanJson
/********************************************\
* Interface
\********************************************/
bool Xdrv101(uint32_t function) {
bool result = false;
if (FUNC_INIT == function) {
LoRaInit();
} else if (initSuccess) {
switch (function) {
case FUNC_LOOP:
LoRaWork();
break;
case FUNC_JSON_APPEND:
LoRaJson(true);
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR:
LoRaJson(false);
break;
#endif // USE_WEBSERVER
}
}
return result;
}
#warning **** LORA_V1 End! ****
#endif // USE_LORA_V1 |
Beta Was this translation helpful? Give feedback.
-
Great news! |
Beta Was this translation helpful? Give feedback.
-
What are you people wanting to achieve with lora/lorawan on tasmota? The current implementation supports lora to be used like serialbridge AND allows any command initiated on a lora node to be executed on a selected lora receiver like the OP envisionend. Implementing lorawan as a node won't happen as there are better options AND tasmota on esp8266/esp32 is too power hungry. My current project is mimicking a lorawan gateway and app server on Tasmota allowing to use standard cheap lorawan nodes to receive and act upon without the need for cloud solutions. I'm able to decode the join message from a lorawan node but still fail to send a valid join accept message to the node (lorawan is NOT just lora with overhead; it needs frequency hops and all kinds of security keys to work). Do not expect a (small codesize) solution soon. |
Beta Was this translation helpful? Give feedback.
-
Hi folks, As per others and your very good concern "what is achieveable with lora on tasmota" permit some few lines:
I believe that the most valuable here is the connectivity range and we could completely ignore the idea of "energy budgets". If you agree as principle on a Class C node implementation I am willing to contribute it to the Tasmota project, for a LoraWAN compliance. Thanks. |
Beta Was this translation helpful? Give feedback.
-
I agree that adding LoRaWan capability to tasmota would be and interesting feature (i'm using tasmota & LoRaWan due to a simple AT command driver developed in berry and RAK sip modules). I add my notes to the topic: Maybe that the implementation could be "mixed" native and berry leaving in berry the flexibility to select what payload to send and how to decode the incoming control messages implementing not only simple straightforward messages suc as "power1 1" but complete custom command that activate scenarios. @cbalint13 I'm not a skilled programmer in berry but if you are able we can start to implement payload encoding in berry. I'm available for simple development and for structured testing. Another, simpler, payload encoder: https://github.com/thesolarnomad/lora-serialization |
Beta Was this translation helpful? Give feedback.
-
Yep, payload size (in LoRaWAN ascenssion) now can be a concern, i agree with you totaly.
As last mention, I also like very much @arendst current work on his lora serial-bridge idea, that would be a super nice decentralized approach not needing any kind of gateway/cloud, but this Class C LoraWAN would be a completley separate alternative (which might share only the backend drivers for the SX127X SPI HW modules) giving the Tasmota a LoraWAN compliance to act as a node within it. @FulvioSpelta , Thanks a lot for the inputs, I was't aware (yet) on this super-light weight PS (Later Edit): My initial data-payload approach was a basic |
Beta Was this translation helpful? Give feedback.
-
Thank you for your responses. It's valued very much. As earlier mentionend I'm trying to receive and act upon standard low-cost LoraWan End-nodes without the need for a cloud connection. I managed to receive valid data from both a Dragino LDS02 and a MerryIoT DW10. The join process works well and occasional reception of data at a fixed frequency works too. See code snippet below:
I very much want to move the message decode, as done above, from C to Berry simply because it allows future device decoding without LoRaWan (= Tasmota) code recompilation (as berry is interpreted at runtime). Notice the word "occasional" above. The issue here is that on EU868 devices they use frequency and DataRate (DR) hopping to lower the blocking of LoRanWan frequency bands. I'm currently struglling to get MAC control of end-node functional. Using MAC command At the moment I'm not working on Tasmota being a LoRaWan end-node because I do not see battery powered Tasmota having a long life-time. I agree with @cbalint13 that AC powered Tasmota LoRaWan end-nodes might be possible and if someone feels the need to write a driver I'm willing to add it to the current LoRaWan support. |
Beta Was this translation helpful? Give feedback.
-
Has anyone looked at the Reyax RYLR998 for connecting to remote sensors? It uses a very simple serial AT command set for control. It is a transceiver so it can send and receive. It is a simple peer-to-peer device with one-to-many and many-to-one capability. I personally think LoraWan is way too complicated for what I have in mind. Since Tasmota does such a great job integrating with Home Assistant, I think being able to use Tasmota as a gateway to the local network and Home Assistant would really be great for remote sensors. I just got two RYLR8988 modules to test using Wemos D1 Mini Pros as a transmitter and receiver and was able to get about .5 mile reception without paying much attention to line-of-sight. My use case is: one or more remote DIY sensors based on ESP32xx using the RYLR988 to communicate with a home based network running many other Tasmota based devices and Home Assistant. If a native Tasmota driver is not on the horizon, how would you approach handling the serial input data with Berry? |
Beta Was this translation helpful? Give feedback.
-
@arendst What about the limitation I mentioned previously, about not being able to use LoRa and a SD card at the same time, when they have separate busses? It would make sense to be able to use SPI bus 2, at least for one of the features. |
Beta Was this translation helpful? Give feedback.
-
In addition find documentation here https://tasmota.github.io/docs/LoRa-and-LoRaWan-Bridge/ |
Beta Was this translation helpful? Give feedback.
-
With my security hat on, I came to the observation that having the Also noticed that the handling of commands not matching the topic is not "very clean":
Maybe that feature is "too open", especially when always enabled. A safer way of handling commands could be that this is delegated to Berry code (not sure how many are using ESP8266-based devices for LoRa), and better security could be done using the cryptographic features available there. |
Beta Was this translation helpful? Give feedback.
-
Hello! Facing some troubles with LoRa.. I compiled the firmware (tasmota32) in PlatformIO with support for the sx1276 and sx1262 drivers, and specific pins for LoRa appeared in the configuration menu. Configured all necessary pins but when I enter LoraConfig in the console, I get the response {"Command":"Unknown"}. Is it possible to compile tasmota w lora support for esp32-c3? For example module HT-CT62 based on esp32-c3 and sx1262 is very interesting for building nodes. |
Beta Was this translation helpful? Give feedback.
-
Hello
I've followed the discussion here and in 2018 @gemu2015 added initial support for Lora with PR3309
What I don't get, is the current status of Lora/LoraWAN in Tasmota.
My progect would be to have two LORA32 (such as TTGO) relaying informations between them via MQTT.
(Remote BLE sensors -> Tasmota reading BLE -> LoRa -> Tasmota Relaying BLE sensors to MQTT Broker)
Of course mine is just an idea, but from what I've read, this should be a reasonable approach, since the remote location is too far away (800+ meters) from my home with no clear LoS and so Wifi is not an option.
Of course if I'm on a completely wrong path/anyone has better ideas on how to handle such a scenario, any suggestion is very welcome.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions