[LORA] Improvements, change frequency, webUI, Oled support, add boards (#1742)
* [LORA] Capability to change LORA frequency and Add OLED Merge of the 2 environments for TTGO V1 * Merge messages keys with upper level json * Id as a sub topic * Add display and state measures * Add frequency configuration through WebUI * Add parameters * Add auto discovery * Add node example for ttgo lora32 v1 * Add environments and fix scope * Support for sync word as a byte * Fix TX Power setting * Add LoRa gateway description * Add onlyknown filter
This commit is contained in:
1 parent
3d20995b3a
commit
246423a8a8
18 files changed
+990
-121
No files matched your search
@@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
@@ -0,0 +1,59 @@
|
||||
# OpenMQTTGateway LoRa Node Example
|
||||
This repository contains an example of a LoRa node program designed for the ESP32 platform. The program reads the internal temperature of the ESP32, packages the data into a JSON format, and sends it over LoRa.
|
||||
|
||||
## Features:
|
||||
* Uses an SX12XX LoRa module.
|
||||
* Displays packet sending status and temperature data on an SSD1306 OLED display.
|
||||
* Sends the ESP32's MAC address as the node ID.
|
||||
* Sends temperature data in Celsius.
|
||||
|
||||
## Hardware Requirements:
|
||||
* ESP32 development board.
|
||||
* SX12XX LoRa module.
|
||||
* SSD1306 OLED display.
|
||||
|
||||
## Pin Configuration:
|
||||
* SCK - GPIO5
|
||||
* MISO - GPIO19
|
||||
* MOSI - GPIO27
|
||||
* SS - GPIO18
|
||||
* RST - GPIO14
|
||||
* DI0 - GPIO26
|
||||
|
||||
## Setup:
|
||||
### Hardware Setup:
|
||||
|
||||
Connect the SX1278 LoRa module and the SSD1306 OLED display to the ESP32 according to the pin configuration.
|
||||
Ensure that the OLED display is powered correctly.
|
||||
|
||||
### Software Setup:
|
||||
|
||||
* Clone this repository.
|
||||
* Open the provided node program with PlatformIO
|
||||
* Upload the program to your ESP32.
|
||||
|
||||
## Usage:
|
||||
Power on the ESP32.
|
||||
The OLED display will show the status of the packet being sent and the current temperature reading.
|
||||
The built-in LED on the ESP32 will blink once every time a packet is sent.
|
||||
Monitor the serial output (at 115200 baud rate) to see the JSON formatted data being sent.
|
||||
|
||||
## Data Format:
|
||||
The data is sent in the following JSON format:
|
||||
|
||||
```json
|
||||
{
|
||||
"model": "ESP32TEMP",
|
||||
"id": "ESP32_MAC_ADDRESS",
|
||||
"tempc": "TEMPERATURE_IN_CELSIUS"
|
||||
}
|
||||
```
|
||||
|
||||
## Troubleshooting:
|
||||
LoRa Initialization Failed: Ensure that the SX1278 LoRa module is connected correctly and powered on.
|
||||
OLED Display Not Working: Check the connections and ensure that the display is powered correctly.
|
||||
No Temperature Data: Ensure that the ESP32's internal temperature sensor is functional.
|
||||
Contributing:
|
||||
Feel free to contribute to this example by opening issues or submitting pull requests. Any feedback or improvements are welcome!
|
||||
|
||||
I hope this README helps users understand and use your program! Adjustments can be made as necessary to fit any additional details or changes.
|
||||
@@ -0,0 +1,36 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:ttgo-lora32-v1]
|
||||
platform = espressif32
|
||||
board = ttgo-lora32-v1
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
https://github.com/sandeepmistry/arduino-LoRa.git#f4a1d27
|
||||
https://github.com/ThingPulse/esp8266-oled-ssd1306.git#f96fd6a
|
||||
monitor_speed = 115200
|
||||
|
||||
[env:ttgo-lora32-v21]
|
||||
platform = espressif32
|
||||
board = ttgo-lora32-v21
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
https://github.com/sandeepmistry/arduino-LoRa.git#f4a1d27
|
||||
https://github.com/ThingPulse/esp8266-oled-ssd1306.git#f96fd6a
|
||||
monitor_speed = 115200
|
||||
|
||||
[env:heltec-wifi-lora-32] ; Heltec ESP32 Board with SSD1306 display
|
||||
platform = ${com.esp32_platform}
|
||||
board = heltec_wifi_lora_32
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
https://github.com/sandeepmistry/arduino-LoRa.git#f4a1d27
|
||||
https://github.com/ThingPulse/esp8266-oled-ssd1306.git#f96fd6a
|
||||
monitor_speed = 115200
|
||||
@@ -0,0 +1,104 @@
|
||||
#include <LoRa.h>
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
#include <Wire.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SSD1306.h"
|
||||
#include "rom/ets_sys.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "soc/sens_reg.h"
|
||||
|
||||
#define SCK 5 // GPIO5 -- SX1278's SCK
|
||||
#define MISO 19 // GPIO19 -- SX1278's MISnO
|
||||
#define MOSI 27 // GPIO27 -- SX1278's MOSI
|
||||
#define SS 18 // GPIO18 -- SX1278's CS
|
||||
#define RST 14 // GPIO14 -- SX1278's RESET
|
||||
#define DI0 26 // GPIO26 -- SX1278's IRQ(Interrupt Request)
|
||||
#define BAND 915E6
|
||||
|
||||
unsigned int counter = 0;
|
||||
|
||||
SSD1306 display(0x3c, 4, 15);
|
||||
String rssi = "RSSI --";
|
||||
String packSize = "--";
|
||||
String packet;
|
||||
|
||||
float intTemperatureRead() {
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 3,
|
||||
SENS_FORCE_XPD_SAR_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_CLK_DIV, 10,
|
||||
SENS_TSENS_CLK_DIV_S);
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_POWER_UP);
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_DUMP_OUT);
|
||||
SET_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_POWER_UP_FORCE);
|
||||
SET_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_POWER_UP);
|
||||
ets_delay_us(100);
|
||||
SET_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_DUMP_OUT);
|
||||
ets_delay_us(5);
|
||||
float temp_f = (float)GET_PERI_REG_BITS2(SENS_SAR_SLAVE_ADDR3_REG,
|
||||
SENS_TSENS_OUT, SENS_TSENS_OUT_S);
|
||||
float temp_c = (temp_f - 32) / 1.8;
|
||||
return temp_c;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(16, OUTPUT);
|
||||
pinMode(2, OUTPUT);
|
||||
|
||||
digitalWrite(16, LOW); // set GPIO16 low to reset OLED
|
||||
delay(50);
|
||||
digitalWrite(16, HIGH); // while OLED is running, must set GPIO16 in high
|
||||
|
||||
Serial.begin(115200);
|
||||
while (!Serial)
|
||||
;
|
||||
Serial.println();
|
||||
Serial.println("LoRa Sender Test");
|
||||
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
LoRa.setPins(SS, RST, DI0);
|
||||
if (!LoRa.begin(BAND)) {
|
||||
Serial.println("Starting LoRa failed!");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
Serial.println("init ok");
|
||||
display.init();
|
||||
display.flipScreenVertically();
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
|
||||
delay(1500);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
display.clear();
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
|
||||
display.drawString(0, 0, "Sending packet: ");
|
||||
display.drawString(90, 0, String(counter));
|
||||
|
||||
String NodeId = WiFi.macAddress();
|
||||
float temp = intTemperatureRead();
|
||||
// send packet
|
||||
LoRa.beginPacket();
|
||||
// Build json string to send
|
||||
String msg = "{\"model\":\"ESP32TEMP\",\"id\":\"" + NodeId + "\",\"tempc\":" + String(temp) + "}";
|
||||
// Send json string
|
||||
LoRa.print(msg);
|
||||
LoRa.endPacket();
|
||||
|
||||
Serial.println(String(msg));
|
||||
|
||||
display.drawString(0, 15, String(NodeId));
|
||||
display.drawString(0, 30, "tempc: " + String(temp) + " C");
|
||||
display.display();
|
||||
|
||||
counter++;
|
||||
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
|
||||
delay(1000); // wait for a second
|
||||
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
|
||||
delay(60000); // wait for 60 seconds
|
||||
}
|
||||
Reference in new issue
Block a user