Skip to content

Commit 9f38835

Browse files
authored
Merge pull request #1 from meshcore-dev/dev
Merge dev branch
2 parents c89a0e9 + bccefd6 commit 9f38835

13 files changed

Lines changed: 646 additions & 5 deletions

File tree

boards/rak3401.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"build": {
3+
"arduino": {
4+
"ldscript": "nrf52840_s140_v6.ld"
5+
},
6+
"core": "nRF5",
7+
"cpu": "cortex-m4",
8+
"extra_flags": "-DARDUINO_NRF52840_FEATHER -DNRF52840_XXAA",
9+
"f_cpu": "64000000L",
10+
"hwids": [
11+
[
12+
"0x239A",
13+
"0x8029"
14+
],
15+
[
16+
"0x239A",
17+
"0x0029"
18+
],
19+
[
20+
"0x239A",
21+
"0x002A"
22+
],
23+
[
24+
"0x239A",
25+
"0x802A"
26+
]
27+
],
28+
"usb_product": "WisCore RAK3401 Board",
29+
"mcu": "nrf52840",
30+
"variant": "WisCore_RAK3401_Board",
31+
"bsp": {
32+
"name": "adafruit"
33+
},
34+
"softdevice": {
35+
"sd_flags": "-DS140",
36+
"sd_name": "s140",
37+
"sd_version": "6.1.1",
38+
"sd_fwid": "0x00B6"
39+
},
40+
"bootloader": {
41+
"settings_addr": "0xFF000"
42+
}
43+
},
44+
"connectivity": [
45+
"bluetooth"
46+
],
47+
"debug": {
48+
"jlink_device": "nRF52840_xxAA",
49+
"svd_path": "nrf52840.svd"
50+
},
51+
"frameworks": [
52+
"arduino"
53+
],
54+
"name": "WisCore RAK3401 Board",
55+
"upload": {
56+
"maximum_ram_size": 248832,
57+
"maximum_size": 815104,
58+
"speed": 115200,
59+
"protocol": "nrfutil",
60+
"protocols": [
61+
"jlink",
62+
"nrfjprog",
63+
"nrfutil",
64+
"stlink"
65+
],
66+
"use_1200bps_touch": true,
67+
"require_upload_port": true,
68+
"wait_for_upload_port": true
69+
},
70+
"url": "https://www.rakwireless.com",
71+
"vendor": "RAKwireless"
72+
}

examples/companion_radio/MyMesh.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ void MyMesh::onContactsFull() {
323323

324324
void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) {
325325
if (_serial->isConnected()) {
326-
if (!shouldAutoAddContactType(contact.type) && is_new) {
326+
if (is_new) {
327327
writeContactRespFrame(PUSH_CODE_NEW_ADVERT, contact);
328328
} else {
329329
out_frame[0] = PUSH_CODE_ADVERT;
@@ -358,7 +358,7 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
358358
memcpy(p->path, path, p->path_len);
359359
}
360360

361-
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
361+
if (!is_new) dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY); // only schedule lazy write for contacts that are in contacts[]
362362
}
363363

364364
static int sort_by_recent(const void *a, const void *b) {

src/helpers/BaseChatMesh.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
133133
}
134134
putBlobByKey(id.pub_key, PUB_KEY_SIZE, temp_buf, plen);
135135

136-
bool is_new = false;
136+
bool is_new = false; // true = not in contacts[], false = exists in contacts[]
137137
if (from == NULL) {
138138
if (!shouldAutoAddContactType(parser.getType())) {
139139
ContactInfo ci;
@@ -142,7 +142,6 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
142142
return;
143143
}
144144

145-
is_new = true;
146145
from = allocateContactSlot();
147146
if (from == NULL) {
148147
ContactInfo ci;

variants/rak3401/RAK3401Board.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <Arduino.h>
2+
#include <Wire.h>
3+
4+
#include "RAK3401Board.h"
5+
6+
void RAK3401Board::begin() {
7+
NRF52BoardDCDC::begin();
8+
pinMode(PIN_VBAT_READ, INPUT);
9+
#ifdef PIN_USER_BTN
10+
pinMode(PIN_USER_BTN, INPUT_PULLUP);
11+
#endif
12+
13+
#ifdef PIN_USER_BTN_ANA
14+
pinMode(PIN_USER_BTN_ANA, INPUT_PULLUP);
15+
#endif
16+
17+
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
18+
Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL);
19+
#endif
20+
21+
Wire.begin();
22+
23+
pinMode(PIN_3V3_EN, OUTPUT);
24+
digitalWrite(PIN_3V3_EN, HIGH);
25+
26+
#ifdef P_LORA_PA_EN
27+
// Initialize RAK13302 1W LoRa transceiver module PA control pin
28+
pinMode(P_LORA_PA_EN, OUTPUT);
29+
digitalWrite(P_LORA_PA_EN, LOW); // Start with PA disabled
30+
delay(10); // Allow PA module to initialize
31+
#endif
32+
}

variants/rak3401/RAK3401Board.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#pragma once
2+
3+
#include <MeshCore.h>
4+
#include <Arduino.h>
5+
#include <helpers/NRF52Board.h>
6+
7+
// LoRa radio module pins for RAK13302
8+
#define P_LORA_SCLK 3
9+
#define P_LORA_MISO 29
10+
#define P_LORA_MOSI 30
11+
#define P_LORA_NSS 26
12+
#define P_LORA_DIO_1 10
13+
#define P_LORA_BUSY 9
14+
#define P_LORA_RESET 4
15+
#ifndef P_LORA_PA_EN
16+
#define P_LORA_PA_EN 31
17+
#endif
18+
19+
//#define PIN_GPS_SDA 13 //GPS SDA pin (output option)
20+
//#define PIN_GPS_SCL 14 //GPS SCL pin (output option)
21+
// #define PIN_GPS_TX 16 //GPS TX pin
22+
// #define PIN_GPS_RX 15 //GPS RX pin
23+
#define PIN_GPS_1PPS 17 //GPS PPS pin
24+
#define GPS_BAUD_RATE 9600
25+
#define GPS_ADDRESS 0x42 //i2c address for GPS
26+
27+
#define SX126X_DIO2_AS_RF_SWITCH
28+
#define SX126X_DIO3_TCXO_VOLTAGE 1.8
29+
30+
31+
// built-ins
32+
#define PIN_VBAT_READ 5
33+
#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000)
34+
35+
#define PIN_3V3_EN (34)
36+
#define WB_IO2 PIN_3V3_EN
37+
38+
class RAK3401Board : public NRF52BoardDCDC, public NRF52BoardOTA {
39+
public:
40+
RAK3401Board() : NRF52BoardOTA("RAK3401_OTA") {}
41+
void begin();
42+
43+
#define BATTERY_SAMPLES 8
44+
45+
uint16_t getBattMilliVolts() override {
46+
analogReadResolution(12);
47+
48+
uint32_t raw = 0;
49+
for (int i = 0; i < BATTERY_SAMPLES; i++) {
50+
raw += analogRead(PIN_VBAT_READ);
51+
}
52+
raw = raw / BATTERY_SAMPLES;
53+
54+
return (ADC_MULTIPLIER * raw) / 4096;
55+
}
56+
57+
const char* getManufacturerName() const override {
58+
return "RAK 3401";
59+
}
60+
61+
#ifdef P_LORA_PA_EN
62+
void onBeforeTransmit() override {
63+
digitalWrite(P_LORA_PA_EN, HIGH); // Enable PA before transmission
64+
}
65+
66+
void onAfterTransmit() override {
67+
digitalWrite(P_LORA_PA_EN, LOW); // Disable PA after transmission to save power
68+
}
69+
#endif
70+
};

variants/rak3401/platformio.ini

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
[rak3401]
2+
extends = nrf52_base
3+
board = rak3401
4+
board_check = true
5+
build_flags = ${nrf52_base.build_flags}
6+
${sensor_base.build_flags}
7+
-I variants/rak3401
8+
-D RAK_3401
9+
-D RAK13302
10+
-D RADIO_CLASS=CustomSX1262
11+
-D WRAPPER_CLASS=CustomSX1262Wrapper
12+
-D LORA_TX_POWER=22
13+
-D SX126X_CURRENT_LIMIT=140
14+
-D SX126X_RX_BOOSTED_GAIN=1
15+
build_src_filter = ${nrf52_base.build_src_filter}
16+
+<../variants/rak3401>
17+
+<helpers/sensors>
18+
+<helpers/ui/SSD1306Display.cpp>
19+
+<helpers/ui/MomentaryButton.cpp>
20+
lib_deps =
21+
${nrf52_base.lib_deps}
22+
${sensor_base.lib_deps}
23+
adafruit/Adafruit SSD1306 @ ^2.5.13
24+
sparkfun/SparkFun u-blox GNSS Arduino Library@^2.2.27
25+
26+
[env:RAK_3401_repeater]
27+
extends = rak3401
28+
build_flags =
29+
${rak3401.build_flags}
30+
-D DISPLAY_CLASS=SSD1306Display
31+
-D ADVERT_NAME='"RAK3401 1W Repeater"'
32+
-D ADVERT_LAT=0.0
33+
-D ADVERT_LON=0.0
34+
-D ADMIN_PASSWORD='"password"'
35+
-D MAX_NEIGHBOURS=50
36+
;-D MESH_PACKET_LOGGING=1
37+
;-D MESH_DEBUG=1
38+
build_src_filter = ${rak3401.build_src_filter}
39+
+<helpers/ui/SSD1306Display.cpp>
40+
+<../examples/simple_repeater>
41+
42+
[env:RAK_3401_room_server]
43+
extends = rak3401
44+
build_flags =
45+
${rak3401.build_flags}
46+
-D DISPLAY_CLASS=SSD1306Display
47+
-D ADVERT_NAME='"Test Room"'
48+
-D ADVERT_LAT=0.0
49+
-D ADVERT_LON=0.0
50+
-D ADMIN_PASSWORD='"password"'
51+
-D ROOM_PASSWORD='"hello"'
52+
;-D MESH_PACKET_LOGGING=1
53+
;-D MESH_DEBUG=1
54+
build_src_filter = ${rak3401.build_src_filter}
55+
+<helpers/ui/SSD1306Display.cpp>
56+
+<../examples/simple_room_server>
57+
58+
[env:RAK_3401_companion_radio_usb]
59+
extends = rak3401
60+
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
61+
board_upload.maximum_size = 712704
62+
build_flags =
63+
${rak3401.build_flags}
64+
-I examples/companion_radio/ui-new
65+
-D DISPLAY_CLASS=SSD1306Display
66+
-D MAX_CONTACTS=350
67+
-D MAX_GROUP_CHANNELS=40
68+
; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1
69+
; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1
70+
build_src_filter = ${rak3401.build_src_filter}
71+
+<../examples/companion_radio/*.cpp>
72+
+<../examples/companion_radio/ui-new/*.cpp>
73+
lib_deps =
74+
${rak3401.lib_deps}
75+
densaugeo/base64 @ ~1.4.0
76+
77+
[env:RAK_3401_companion_radio_ble]
78+
extends = rak3401
79+
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
80+
board_upload.maximum_size = 712704
81+
build_flags =
82+
${rak3401.build_flags}
83+
-I examples/companion_radio/ui-new
84+
-D DISPLAY_CLASS=SSD1306Display
85+
-D MAX_CONTACTS=350
86+
-D MAX_GROUP_CHANNELS=40
87+
-D BLE_PIN_CODE=123456
88+
-D BLE_DEBUG_LOGGING=1
89+
-D OFFLINE_QUEUE_SIZE=256
90+
;-D MESH_PACKET_LOGGING=1
91+
;-D MESH_DEBUG=1
92+
build_src_filter = ${rak3401.build_src_filter}
93+
+<helpers/nrf52/SerialBLEInterface.cpp>
94+
+<../examples/companion_radio/*.cpp>
95+
+<../examples/companion_radio/ui-new/*.cpp>
96+
lib_deps =
97+
${rak3401.lib_deps}
98+
densaugeo/base64 @ ~1.4.0
99+
100+
[env:RAK_3401_terminal_chat]
101+
extends = rak3401
102+
build_flags =
103+
${rak3401.build_flags}
104+
-D MAX_CONTACTS=100
105+
-D MAX_GROUP_CHANNELS=1
106+
;-D MESH_PACKET_LOGGING=1
107+
;-D MESH_DEBUG=1
108+
build_src_filter = ${rak3401.build_src_filter}
109+
+<../examples/simple_secure_chat/main.cpp>
110+
lib_deps =
111+
${rak3401.lib_deps}
112+
densaugeo/base64 @ ~1.4.0
113+
114+
[env:RAK_3401_sensor]
115+
extends = rak3401
116+
build_flags =
117+
${rak3401.build_flags}
118+
-D DISPLAY_CLASS=SSD1306Display
119+
-D ADVERT_NAME='"RAK3401 Sensor"'
120+
-D ADVERT_LAT=0.0
121+
-D ADVERT_LON=0.0
122+
-D ADMIN_PASSWORD='"password"'
123+
;-D MESH_PACKET_LOGGING=1
124+
;-D MESH_DEBUG=1
125+
build_src_filter = ${rak3401.build_src_filter}
126+
+<helpers/ui/SSD1306Display.cpp>
127+
+<../examples/simple_sensor>

0 commit comments

Comments
 (0)