https://github.com/jayu/nodemcu-lora-sx1276-lua
NodeMCU lua library for LoRa SX1276/SX1278 radio communication modules
https://github.com/jayu/nodemcu-lora-sx1276-lua
esp32 esp8266 lora lorawan lua lua-library lua-script nodemcu nodemcu-esp8266 nodemcu-lora nodemcu-lua sx1276 sx1278
Last synced: 3 months ago
JSON representation
NodeMCU lua library for LoRa SX1276/SX1278 radio communication modules
- Host: GitHub
- URL: https://github.com/jayu/nodemcu-lora-sx1276-lua
- Owner: jayu
- Created: 2022-04-04T20:40:10.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-04-04T21:16:47.000Z (about 3 years ago)
- Last Synced: 2025-03-18T05:12:27.288Z (3 months ago)
- Topics: esp32, esp8266, lora, lorawan, lua, lua-library, lua-script, nodemcu, nodemcu-esp8266, nodemcu-lora, nodemcu-lua, sx1276, sx1278
- Language: Lua
- Homepage:
- Size: 8.79 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NodeMCU LoRa module library
NodeMCU lua library for LoRa SX1276/SX1278 radio communication modules
The library is a based on the library from https://github.com/JaapBraam/LoRaWanGateway
The improvements:
- fixed a bug with incorrect operations on message buffers which result in sending garbage instead of actual message
- enhanced power management to support 20dBm mode
- implementation was inspired by https://github.com/sandeepmistry/arduino-LoRa/blob/master/src/LoRa.cppI'm not an expert in implementing such libraries and I don't understand most of these registers operations, but I made it work for me somehow 😃
Most of the credits goes to authors of the mentioned libraries who had to study SX1276 manual a lot 🧐
## Usage
### API
```lua
local radioLib = require('sx1276.lua')local nssPin = 0
local dio0Pin = 1
local dio1Pin = 2local frequency = 433.000 * 1000000 -- Frequency in Hz
local spreadingFactor = "SF7" -- "SF7" - "SF12"
local bandWidth = "BW125" -- I think only this one is supported
local errorCorrection = "4/5" -- I believe these are supported: "4/5", "4/6", "4/7", "4/8"local radioInterface = radioLib(
nssPin,
dio0Pin,
dio1Pin,
frequency,
spreadingFactor,
bandWidth,
errorCorrection
)-- Receiving
local function handleMessage(pkt)
print("RX!")
print("Data: ", pkt.data)
print("RSSI: ", pkt.rssi)
for k, v in pairs(pkt) do
print(k, v)
end
endradioInterface.rxpk = handleMessage
-- Transmitting
local pkt = {
freq = frequency,
codr = errorCorrection,
datr = spreadingFactor .. bandWidth,
data = "Here goes your message",
powe = 17 -- values 0..20
}radio.txpk(pkt)
```
### Connections
_Stolen from https://github.com/JaapBraam/LoRaWanGateway/blob/master/README.md#hardware_
ESP PINSX1276 PIN
D1 (GPIO5)DIO0
D2 (GPIO4)DIO1
D5 (GPIO14)SCK
D6 (GPIO12)MISO
D7 (GPIO13)MOSI
D0 (GPIO16)NSS
GNDGND
3.3VVCC## TODO (a.k.a. roadmap)
The library needs a lot of refactoring, feel free to open a PR!
- [ ] refactor global variables with register numbers into object with all registers
- [ ] refactor all register magic numbers to variables with register numbers
- [ ] remove code responsible for handling multiple spreading factors
- [ ] make the API more friendly
- [ ] implement support for low power mode - right now NodeMCU has to be ON all the time to handle incoming messages, but there is a way to use interrupts from SX1276 to wake up NodeMCU