This repository contains a Long Range (LoRa) local server implementation using a Raspberry Pi Zero 2 W and ESP32 microcontrollers.
The whole project consists of an Astro project, which handles everything through the Sever-Side Rendering implementation. This helps to enable API endpoints and monitoring of the GPIO board.
- Raspberry Pi Zero 2 W (recommended to use Raspberry Pi OS Lite with headless install)
- ESP32 microcontroller as data monitoring endpoints
You can review the script /client_ESP32/RFM69HCW_Tx.cpp
for an example of how to set up the ESP32 microcontroller.
RFM69HCW Pin | RPi Zero 2 W Pin | Note |
---|---|---|
3v3 | 1 (3v3) | |
GND | 9 (GND) | Can use any GND pin |
DIO0 | 18 (GPIO24) | Interrupt Pin |
MOSI | 19 (GPIO10) | |
MISO | 21 (GPIO09) | |
SCK (CLK) | 23 (GPIO11) | |
NSS (CS) | 24 (GPIO08 CS0) | |
RESET | 29 (GPIO05) | Reset Pin |
RFM69HCW Pin | ESP32 Pin |
---|---|
3v3 | 3v3 |
GND | GND |
DIO0 | D2 |
MOSI | D23 |
MISO | D19 |
SCK (CLK) | D18 |
NSS (CS) | D5 |
- Node.js v22.13.0
- Astro v5.8.0
- MariaDB v3.4.2
- mysql2 v3.14.1
- onoff v6.0.3
- plotly v3.0.1
- spi-device v3.1.2
Package rfm69radio is used, but it had to be modified; you can find the modified source files inside /src/lib/rfm69radio
.
IMPORTANT: GPIO Pin Configuration
The
onoff
library (used byrfm69radio
) requires GPIO pins to be addressed by their kernel line number, not their BCM or board number (see Use raspberry pi 4 GPIO with node js).In this project's configuration:
interruptPin: 536
corresponds to GPIO24 (Board Pin 18).resetPin: 517
corresponds to GPIO05 (Board Pin 29).If you change the wiring, you must find the new kernel line numbers.
RFM69.initialize({
interruptPin: 536, // GPIO24
resetPin: 517, // GPIO05
address: 1,
networkID: 100
}).then(() => {
RFM69.registerPacketReceivedCallback(packetLog);
return true;
});
Lines 4 - 5: Update function export and transfer speed
- module.exports = Object.freeze({
+ export const reg = Object.freeze({
- TRANSFER_SPEED: 40000,
+ TRANSFER_SPEED: 500000,
// the rest of the object body remains unchanged
)};
Lines 1061 - 1063: Add default export
+ export default {
+ reg,
+ };
Line 4: Change to use ES6 import
- const reg = require('./registers');
+ import _reg from './registers.js';
+ const reg = _reg.reg;
Line 10: Update function export
- module.exports.getConfig = function(freqBand, networkID) {
+ export function getConfig(freqBand, networkID) {
// function body remains unchanged
};
Lines 68 - 71: Add default export
+export default {
+ getConfig,
+};
Lines 4 - 9: Change to use ES6 import
- const rfm69 = function() {
- const spi = require('spi-device');
- const Gpio = require('onoff').Gpio;
- const config = require('./config');
- const reg = require('./registers');
+ import spi from 'spi-device';
+ import {Gpio} from 'onoff';
+ import config from './config.js';
+ import _reg from './registers.js';
+ const reg = _reg.reg;
+ export function rfm69() {
// the rest of the function body remains unchanged
};
For the current implementation of using ESP32 microcontrollers to monitor a temperature sensor LM35 and a RGB color sensor module TCS34725
You can use the sample code /client_ESP32/RFM69HCW_Tx.cpp
to set up the ESP32 microcontroller.
First, make sure to install MariaDB and set your username and password. Please make sure to take note of the credentials!
sudo apt install mariadb-server
sudo mysql_secure_installation
Use your credentials to access MariaDB
sudo mariadb -h localhost -u $USERNAME_HERE -p
Grant access to your user through password or make a new user for read access, in this example, we opt for the first option
ALTER USER $YOUR_USERNAME@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD($YOUR_PASSWORD);
Afterwards, create the database and table to log all incoming data. Feel free to change the database name and table name according to your needs
The example table is for logging the incoming data from the LM35 and the TCS34725
CREATE DATABASE $DATABASE_NAME;
USE $DATABASE_NAME;
CREATE TABLE $TABLE_NAME (
id int NOT NULL auto_increment,
id_dispositivo int NOT NULL,
fecha date NOT NULL,
hora time NOT NULL,
temperatura float(6,3) NOT NULL,
rojo int NOT NULL,
verde int NOT NULL,
azul int NOT NULL,
PRIMARY KEY (id)
) AUTO_INCREMENT=1;
The following example uses the recommended method for installing the latest Node.js version as of this writing. Make sure to consult any new version available
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo bash -
sudo apt-get install -y nodejs
sudo apt-get install git
Now you can clone the repository and install the required dependencies
git clone https://github.com/Ramstric/ESP32-RP3A0-LoRa-Server.git
cd ESP32-RP3A0-LoRa-Server
npm install
Lastly, add the MariaDB credentials to environment variables.
Your .env
should look like:
SQL_HOST=localhost
SQL_USER=
SQL_PASSWORD=
DATABASE_NAME=
TABLE_NAME=
Add your credentials and both the database and table names. If needed, you can also change the hostname.
Now you can start the server with:
npm run dev
This will launch the Astro server and begin monitoring device data in the background to receive every incoming packet.