* new target: RAK_4631_Repeater
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
#include <Arduino.h> // needed for PlatformIO
|
#include <Arduino.h> // needed for PlatformIO
|
||||||
#include <Mesh.h>
|
#include <Mesh.h>
|
||||||
#include <SPIFFS.h>
|
|
||||||
|
#if defined(NRF52_PLATFORM)
|
||||||
|
#include <InternalFileSystem.h>
|
||||||
|
#elif defined(ESP32)
|
||||||
|
#include <SPIFFS.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define RADIOLIB_STATIC_ONLY 1
|
#define RADIOLIB_STATIC_ONLY 1
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
@@ -54,6 +59,10 @@
|
|||||||
#include <helpers/ESP32Board.h>
|
#include <helpers/ESP32Board.h>
|
||||||
#include <helpers/CustomSX1262Wrapper.h>
|
#include <helpers/CustomSX1262Wrapper.h>
|
||||||
static ESP32Board board;
|
static ESP32Board board;
|
||||||
|
#elif defined(RAK_4631)
|
||||||
|
#include <helpers/RAK4631Board.h>
|
||||||
|
#include <helpers/CustomSX1262Wrapper.h>
|
||||||
|
static RAK4631Board board;
|
||||||
#else
|
#else
|
||||||
#error "need to provide a 'board' object"
|
#error "need to provide a 'board' object"
|
||||||
#endif
|
#endif
|
||||||
@@ -351,7 +360,9 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(P_LORA_SCLK)
|
#if defined(NRF52_PLATFORM)
|
||||||
|
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
|
||||||
|
#elif defined(P_LORA_SCLK)
|
||||||
SPIClass spi;
|
SPIClass spi;
|
||||||
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi);
|
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi);
|
||||||
#else
|
#else
|
||||||
@@ -379,12 +390,13 @@ void setup() {
|
|||||||
float tcxo = 1.6f;
|
float tcxo = 1.6f;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(P_LORA_SCLK)
|
#if defined(NRF52_PLATFORM)
|
||||||
|
SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI);
|
||||||
|
SPI.begin();
|
||||||
|
#elif defined(P_LORA_SCLK)
|
||||||
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
|
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
|
||||||
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo);
|
|
||||||
#else
|
|
||||||
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo);
|
|
||||||
#endif
|
#endif
|
||||||
|
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo);
|
||||||
if (status != RADIOLIB_ERR_NONE) {
|
if (status != RADIOLIB_ERR_NONE) {
|
||||||
delay(5000);
|
delay(5000);
|
||||||
Serial.print("ERROR: radio init failed: ");
|
Serial.print("ERROR: radio init failed: ");
|
||||||
@@ -402,8 +414,15 @@ void setup() {
|
|||||||
radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH);
|
radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(NRF52_PLATFORM)
|
||||||
|
InternalFS.begin();
|
||||||
|
IdentityStore store(InternalFS, "/identity");
|
||||||
|
#elif defined(ESP32)
|
||||||
SPIFFS.begin(true);
|
SPIFFS.begin(true);
|
||||||
IdentityStore store(SPIFFS, "/identity");
|
IdentityStore store(SPIFFS, "/identity");
|
||||||
|
#else
|
||||||
|
#error "need to define filesystem"
|
||||||
|
#endif
|
||||||
if (!store.load("_main", the_mesh.self_id)) {
|
if (!store.load("_main", the_mesh.self_id)) {
|
||||||
the_mesh.self_id = mesh::LocalIdentity(the_mesh.getRNG()); // create new random identity
|
the_mesh.self_id = mesh::LocalIdentity(the_mesh.getRNG()); // create new random identity
|
||||||
store.save("_main", the_mesh.self_id);
|
store.save("_main", the_mesh.self_id);
|
||||||
|
|||||||
@@ -175,3 +175,40 @@ build_flags =
|
|||||||
-D ADMIN_PASSWORD="\"password\""
|
-D ADMIN_PASSWORD="\"password\""
|
||||||
; -D MESH_PACKET_LOGGING=1
|
; -D MESH_PACKET_LOGGING=1
|
||||||
; -D MESH_DEBUG=1
|
; -D MESH_DEBUG=1
|
||||||
|
|
||||||
|
; ----------------- NRF52 ---------------------
|
||||||
|
[nrf52_base]
|
||||||
|
extends = arduino_base
|
||||||
|
platform = nordicnrf52
|
||||||
|
build_flags = ${arduino_base.build_flags}
|
||||||
|
-D NRF52_PLATFORM
|
||||||
|
|
||||||
|
[nrf52840_base]
|
||||||
|
extends = nrf52_base
|
||||||
|
build_flags = ${nrf52_base.build_flags}
|
||||||
|
lib_deps =
|
||||||
|
${nrf52_base.lib_deps}
|
||||||
|
rweather/Crypto @ ^0.4.0
|
||||||
|
https://github.com/adafruit/Adafruit_nRF52_Arduino
|
||||||
|
|
||||||
|
[rak4631]
|
||||||
|
extends = nrf52840_base
|
||||||
|
board = wiscore_rak4631
|
||||||
|
board_check = true
|
||||||
|
build_flags = ${nrf52840_base.build_flags}
|
||||||
|
-D RAK_4631
|
||||||
|
|
||||||
|
[env:RAK_4631_Repeater]
|
||||||
|
extends = rak4631
|
||||||
|
build_src_filter = ${rak4631.build_src_filter} +<../examples/simple_repeater/main.cpp>
|
||||||
|
build_flags =
|
||||||
|
${rak4631.build_flags}
|
||||||
|
-D RADIO_CLASS=CustomSX1262
|
||||||
|
-D WRAPPER_CLASS=CustomSX1262Wrapper
|
||||||
|
-D LORA_TX_POWER=22
|
||||||
|
-D ADVERT_NAME="\"RAK4631 Repeater\""
|
||||||
|
-D ADVERT_LAT=-37.0
|
||||||
|
-D ADVERT_LON=145.0
|
||||||
|
-D ADMIN_PASSWORD="\"password\""
|
||||||
|
; -D MESH_PACKET_LOGGING=1
|
||||||
|
; -D MESH_DEBUG=1
|
||||||
|
|||||||
@@ -17,7 +17,13 @@ bool IdentityStore::load(const char *name, mesh::LocalIdentity& id) {
|
|||||||
bool IdentityStore::save(const char *name, const mesh::LocalIdentity& id) {
|
bool IdentityStore::save(const char *name, const mesh::LocalIdentity& id) {
|
||||||
char filename[40];
|
char filename[40];
|
||||||
sprintf(filename, "%s/%s.id", _dir, name);
|
sprintf(filename, "%s/%s.id", _dir, name);
|
||||||
|
|
||||||
|
#if defined(NRF52_PLATFORM)
|
||||||
|
File file = _fs->open(filename, FILE_O_WRITE);
|
||||||
|
if (file) { file.seek(0); file.truncate(); }
|
||||||
|
#else
|
||||||
File file = _fs->open(filename, "w", true);
|
File file = _fs->open(filename, "w", true);
|
||||||
|
#endif
|
||||||
if (file) {
|
if (file) {
|
||||||
id.writeTo(file);
|
id.writeTo(file);
|
||||||
file.close();
|
file.close();
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <FS.h>
|
#if defined(ESP32)
|
||||||
|
#include <FS.h>
|
||||||
|
#define FILESYSTEM fs::FS
|
||||||
|
#elif defined(NRF52_PLATFORM)
|
||||||
|
#include <Adafruit_LittleFS.h>
|
||||||
|
#define FILESYSTEM Adafruit_LittleFS
|
||||||
|
|
||||||
|
using namespace Adafruit_LittleFS_Namespace;
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <Identity.h>
|
#include <Identity.h>
|
||||||
|
|
||||||
class IdentityStore {
|
class IdentityStore {
|
||||||
fs::FS* _fs;
|
FILESYSTEM* _fs;
|
||||||
const char* _dir;
|
const char* _dir;
|
||||||
public:
|
public:
|
||||||
IdentityStore(fs::FS& fs, const char* dir): _fs(&fs), _dir(dir) { }
|
IdentityStore(FILESYSTEM& fs, const char* dir): _fs(&fs), _dir(dir) { }
|
||||||
|
|
||||||
void begin() { _fs->mkdir(_dir); }
|
void begin() { _fs->mkdir(_dir); }
|
||||||
bool load(const char *name, mesh::LocalIdentity& id);
|
bool load(const char *name, mesh::LocalIdentity& id);
|
||||||
|
|||||||
63
src/helpers/RAK4631Board.h
Normal file
63
src/helpers/RAK4631Board.h
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <MeshCore.h>
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#if defined(NRF52_PLATFORM)
|
||||||
|
|
||||||
|
// LoRa radio module pins for RAK4631
|
||||||
|
#define P_LORA_DIO_1 47
|
||||||
|
#define P_LORA_NSS 42
|
||||||
|
#define P_LORA_RESET RADIOLIB_NC // 38
|
||||||
|
#define P_LORA_BUSY 46
|
||||||
|
#define P_LORA_SCLK 43
|
||||||
|
#define P_LORA_MISO 45
|
||||||
|
#define P_LORA_MOSI 44
|
||||||
|
#define SX126X_POWER_EN 37
|
||||||
|
|
||||||
|
#define SX126X_DIO2_AS_RF_SWITCH true
|
||||||
|
#define SX126X_DIO3_TCXO_VOLTAGE 1.8
|
||||||
|
|
||||||
|
// built-ins
|
||||||
|
#define PIN_VBAT_READ 1
|
||||||
|
#define ADC_MULTIPLIER 6.17
|
||||||
|
|
||||||
|
class RAK4631Board : public mesh::MainBoard {
|
||||||
|
protected:
|
||||||
|
uint8_t startup_reason;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void begin() {
|
||||||
|
// for future use, sub-classes SHOULD call this from their begin()
|
||||||
|
startup_reason = BD_STARTUP_NORMAL;
|
||||||
|
|
||||||
|
pinMode(SX126X_POWER_EN, OUTPUT);
|
||||||
|
digitalWrite(SX126X_POWER_EN, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t getStartupReason() const override { return startup_reason; }
|
||||||
|
|
||||||
|
#define BATTERY_SAMPLES 10
|
||||||
|
|
||||||
|
uint16_t getBattMilliVolts() override {
|
||||||
|
analogReadResolution(12);
|
||||||
|
|
||||||
|
uint32_t raw = 0;
|
||||||
|
for (int i = 0; i < BATTERY_SAMPLES; i++) {
|
||||||
|
raw += analogRead(PIN_VBAT_READ);
|
||||||
|
}
|
||||||
|
raw = raw / BATTERY_SAMPLES;
|
||||||
|
|
||||||
|
return (ADC_MULTIPLIER * raw) / 4096;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* getManufacturerName() const override {
|
||||||
|
return "RAK 4631";
|
||||||
|
}
|
||||||
|
|
||||||
|
void reboot() override {
|
||||||
|
NVIC_SystemReset();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user