Skip to content

Commit d59724a

Browse files
committed
new variant: RAK WisMesh Tag
1 parent 0ebca4b commit d59724a

File tree

8 files changed

+518
-16
lines changed

8 files changed

+518
-16
lines changed

src/helpers/sensors/EnvironmentSensorManager.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ static Adafruit_INA260 INA260;
6666
#endif
6767

6868
#if ENV_INCLUDE_INA226
69-
#define TELEM_INA226_ADDRESS 0x44
70-
#define TELEM_INA226_SHUNT_VALUE 0.100
69+
#define TELEM_INA226_ADDRESS 0x44
70+
#define TELEM_INA226_SHUNT_VALUE 0.100
7171
#define TELEM_INA226_MAX_AMP 0.8
7272
#include <INA226.h>
7373
static INA226 INA226(TELEM_INA226_ADDRESS);
@@ -85,7 +85,11 @@ static Adafruit_MLX90614 MLX90614;
8585
static Adafruit_VL53L0X VL53L0X;
8686
#endif
8787

88-
#if ENV_INCLUDE_GPS && RAK_BOARD
88+
#if ENV_INCLUDE_GPS && defined(RAK_BOARD) && !defined(RAK_WISMESH_TAG)
89+
#define RAK_WISBLOCK_GPS
90+
#endif
91+
92+
#ifdef RAK_WISBLOCK_GPS
8993
static uint32_t gpsResetPin = 0;
9094
static bool i2cGPSFlag = false;
9195
static bool serialGPSFlag = false;
@@ -96,7 +100,7 @@ static SFE_UBLOX_GNSS ublox_GNSS;
96100

97101
bool EnvironmentSensorManager::begin() {
98102
#if ENV_INCLUDE_GPS
99-
#if RAK_BOARD
103+
#ifdef RAK_WISBLOCK_GPS
100104
rakGPSInit(); //probe base board/sockets for GPS
101105
#else
102106
initBasicGPS();
@@ -457,7 +461,7 @@ void EnvironmentSensorManager::initBasicGPS() {
457461
gps_active = false; //Set GPS visibility off until setting is changed
458462
}
459463

460-
#ifdef RAK_BOARD
464+
#ifdef RAK_WISBLOCK_GPS
461465
void EnvironmentSensorManager::rakGPSInit(){
462466

463467
Serial1.setPins(PIN_GPS_TX, PIN_GPS_RX);
@@ -531,7 +535,7 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){
531535

532536
void EnvironmentSensorManager::start_gps() {
533537
gps_active = true;
534-
#ifdef RAK_BOARD
538+
#ifdef RAK_WISBLOCK_GPS
535539
pinMode(gpsResetPin, OUTPUT);
536540
digitalWrite(gpsResetPin, HIGH);
537541
return;
@@ -547,7 +551,7 @@ void EnvironmentSensorManager::start_gps() {
547551

548552
void EnvironmentSensorManager::stop_gps() {
549553
gps_active = false;
550-
#ifdef RAK_BOARD
554+
#ifdef RAK_WISBLOCK_GPS
551555
pinMode(gpsResetPin, OUTPUT);
552556
digitalWrite(gpsResetPin, LOW);
553557
return;
@@ -568,13 +572,7 @@ void EnvironmentSensorManager::loop() {
568572

569573
if (millis() > next_gps_update) {
570574
if(gps_active){
571-
#ifndef RAK_BOARD
572-
if (_location->isValid()) {
573-
node_lat = ((double)_location->getLatitude())/1000000.;
574-
node_lon = ((double)_location->getLongitude())/1000000.;
575-
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
576-
}
577-
#else
575+
#ifdef RAK_WISBLOCK_GPS
578576
if(i2cGPSFlag){
579577
node_lat = ((double)ublox_GNSS.getLatitude())/10000000.;
580578
node_lon = ((double)ublox_GNSS.getLongitude())/10000000.;
@@ -585,8 +583,12 @@ void EnvironmentSensorManager::loop() {
585583
node_lon = ((double)_location->getLongitude())/1000000.;
586584
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
587585
}
588-
//else
589-
//MESH_DEBUG_PRINTLN("No valid GPS data");
586+
#else
587+
if (_location->isValid()) {
588+
node_lat = ((double)_location->getLatitude())/1000000.;
589+
node_lon = ((double)_location->getLongitude())/1000000.;
590+
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
591+
}
590592
#endif
591593
}
592594
next_gps_update = millis() + 1000;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include <Arduino.h>
2+
#include "RAKWismeshTagBoard.h"
3+
4+
#include <bluefruit.h>
5+
#include <Wire.h>
6+
7+
static BLEDfu bledfu;
8+
9+
static void connect_callback(uint16_t conn_handle) {
10+
(void)conn_handle;
11+
MESH_DEBUG_PRINTLN("BLE client connected");
12+
}
13+
14+
static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
15+
(void)conn_handle;
16+
(void)reason;
17+
18+
MESH_DEBUG_PRINTLN("BLE client disconnected");
19+
}
20+
21+
void RAKWismeshTagBoard::begin() {
22+
// for future use, sub-classes SHOULD call this from their begin()
23+
startup_reason = BD_STARTUP_NORMAL;
24+
pinMode(PIN_VBAT_READ, INPUT);
25+
pinMode(PIN_USER_BTN, INPUT_PULLUP);
26+
27+
Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL);
28+
Wire.begin();
29+
30+
pinMode(SX126X_POWER_EN, OUTPUT);
31+
digitalWrite(SX126X_POWER_EN, HIGH);
32+
delay(10); // give sx1262 some time to power up
33+
}
34+
35+
bool RAKWismeshTagBoard::startOTAUpdate(const char* id, char reply[]) {
36+
// Config the peripheral connection with maximum bandwidth
37+
// more SRAM required by SoftDevice
38+
// Note: All config***() function must be called before begin()
39+
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
40+
Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16);
41+
42+
Bluefruit.begin(1, 0);
43+
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
44+
Bluefruit.setTxPower(4);
45+
// Set the BLE device name
46+
Bluefruit.setName("WISMESHTAG_OTA");
47+
48+
Bluefruit.Periph.setConnectCallback(connect_callback);
49+
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
50+
51+
// To be consistent OTA DFU should be added first if it exists
52+
bledfu.begin();
53+
54+
// Set up and start advertising
55+
// Advertising packet
56+
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
57+
Bluefruit.Advertising.addTxPower();
58+
Bluefruit.Advertising.addName();
59+
60+
/* Start Advertising
61+
- Enable auto advertising if disconnected
62+
- Interval: fast mode = 20 ms, slow mode = 152.5 ms
63+
- Timeout for fast mode is 30 seconds
64+
- Start(timeout) with timeout = 0 will advertise forever (until connected)
65+
66+
For recommended advertising interval
67+
https://developer.apple.com/library/content/qa/qa1931/_index.html
68+
*/
69+
Bluefruit.Advertising.restartOnDisconnect(true);
70+
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
71+
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
72+
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
73+
74+
uint8_t mac_addr[6];
75+
memset(mac_addr, 0, sizeof(mac_addr));
76+
Bluefruit.getAddr(mac_addr);
77+
sprintf(reply, "OK - mac: %02X:%02X:%02X:%02X:%02X:%02X",
78+
mac_addr[5], mac_addr[4], mac_addr[3], mac_addr[2], mac_addr[1], mac_addr[0]);
79+
80+
return true;
81+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#pragma once
2+
3+
#include <MeshCore.h>
4+
#include <Arduino.h>
5+
6+
// built-ins
7+
#define PIN_VBAT_READ 5
8+
#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000)
9+
10+
class RAKWismeshTagBoard : public mesh::MainBoard {
11+
protected:
12+
uint8_t startup_reason;
13+
14+
public:
15+
void begin();
16+
uint8_t getStartupReason() const override { return startup_reason; }
17+
18+
#if defined(P_LORA_TX_LED) && defined(LED_STATE_ON)
19+
void onBeforeTransmit() override {
20+
digitalWrite(P_LORA_TX_LED, LED_STATE_ON); // turn TX LED on
21+
}
22+
void onAfterTransmit() override {
23+
digitalWrite(P_LORA_TX_LED, !LED_STATE_ON); // turn TX LED off
24+
}
25+
#endif
26+
27+
#define BATTERY_SAMPLES 8
28+
29+
uint16_t getBattMilliVolts() override {
30+
analogReadResolution(12);
31+
32+
uint32_t raw = 0;
33+
for (int i = 0; i < BATTERY_SAMPLES; i++) {
34+
raw += analogRead(PIN_VBAT_READ);
35+
}
36+
raw = raw / BATTERY_SAMPLES;
37+
38+
return (ADC_MULTIPLIER * raw) / 4096;
39+
}
40+
41+
const char* getManufacturerName() const override {
42+
return "RAK WisMesh Tag";
43+
}
44+
45+
void reboot() override {
46+
NVIC_SystemReset();
47+
}
48+
49+
bool startOTAUpdate(const char* id, char reply[]) override;
50+
51+
void powerOff() override {
52+
#ifdef BUZZER_EN
53+
digitalWrite(BUZZER_EN, LOW);
54+
#endif
55+
56+
#ifdef PIN_GPS_EN
57+
digitalWrite(PIN_GPS_EN, LOW);
58+
#endif
59+
60+
// set led on and wait for button release before poweroff
61+
#ifdef LED_PIN
62+
digitalWrite(LED_PIN, HIGH);
63+
#endif
64+
#ifdef BUTTON_PIN
65+
while(digitalRead(BUTTON_PIN));
66+
#endif
67+
#ifdef LED_GREEN
68+
digitalWrite(LED_GREEN, LOW);
69+
#endif
70+
#ifdef LED_BLUE
71+
digitalWrite(LED_BLUE, LOW);
72+
#endif
73+
74+
#ifdef BUTTON_PIN
75+
nrf_gpio_cfg_sense_input(digitalPinToInterrupt(BUTTON_PIN), NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);
76+
#endif
77+
78+
sd_power_system_off();
79+
}
80+
};
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
[rak_wismesh_tag]
2+
extends = nrf52_base
3+
platform = https://github.com/maxgerhardt/platform-nordicnrf52.git#rak
4+
board = wiscore_rak4631
5+
board_check = true
6+
build_flags = ${nrf52_base.build_flags}
7+
${sensor_base.build_flags}
8+
-I variants/rak_wismesh_tag
9+
-I src/helpers/ui
10+
-D RAK_WISMESH_TAG
11+
-D RAK_BOARD
12+
-D P_LORA_TX_LED=LED_GREEN
13+
-D P_LORA_DIO_1=SX126X_DIO1
14+
-D P_LORA_NSS=PIN_SPI_NSS
15+
-D P_LORA_RESET=SX126X_RESET
16+
-D P_LORA_BUSY=SX126X_BUSY
17+
-D P_LORA_SCLK=PIN_SPI_SCK
18+
-D P_LORA_MISO=PIN_SPI_MISO
19+
-D P_LORA_MOSI=PIN_SPI_MOSI
20+
-D RADIO_CLASS=CustomSX1262
21+
-D WRAPPER_CLASS=CustomSX1262Wrapper
22+
-D DISPLAY_CLASS=NullDisplayDriver
23+
-D LORA_TX_POWER=22
24+
-D SX126X_CURRENT_LIMIT=140
25+
-D SX126X_RX_BOOSTED_GAIN=1
26+
-D PIN_BUZZER=21
27+
-D PIN_BOARD_SDA=PIN_WIRE_SDA
28+
-D PIN_BOARD_SCL=PIN_WIRE_SCL
29+
build_src_filter = ${nrf52_base.build_src_filter}
30+
+<../variants/rak_wismesh_tag>
31+
+<helpers/ui/buzzer.cpp>
32+
+<helpers/ui/MomentaryButton.cpp>
33+
+<helpers/ui/NullDisplayDriver.cpp>
34+
+<helpers/sensors>
35+
lib_deps =
36+
${nrf52_base.lib_deps}
37+
${sensor_base.lib_deps}
38+
39+
[env:RAK_WisMesh_Tag_Repeater]
40+
extends = rak_wismesh_tag
41+
build_flags =
42+
${rak_wismesh_tag.build_flags}
43+
-D ADVERT_NAME='"RAK WM Repeater"'
44+
-D ADVERT_LAT=0.0
45+
-D ADVERT_LON=0.0
46+
-D ADMIN_PASSWORD='"password"'
47+
-D MAX_NEIGHBOURS=8
48+
; -D MESH_PACKET_LOGGING=1
49+
; -D MESH_DEBUG=1
50+
build_src_filter = ${rak_wismesh_tag.build_src_filter}
51+
+<../examples/simple_repeater>
52+
53+
[env:RAK_WisMesh_Tag_room_server]
54+
extends = rak_wismesh_tag
55+
build_flags =
56+
${rak_wismesh_tag.build_flags}
57+
-D ADVERT_NAME='"RAK WM Room"'
58+
-D ADVERT_LAT=0.0
59+
-D ADVERT_LON=0.0
60+
-D ADMIN_PASSWORD='"password"'
61+
-D ROOM_PASSWORD='"hello"'
62+
; -D MESH_PACKET_LOGGING=1
63+
; -D MESH_DEBUG=1
64+
build_src_filter = ${rak_wismesh_tag.build_src_filter}
65+
+<../examples/simple_room_server>
66+
67+
[env:RAK_WisMesh_Tag_companion_radio_usb]
68+
extends = rak_wismesh_tag
69+
build_flags =
70+
${rak_wismesh_tag.build_flags}
71+
-I examples/companion_radio/ui-orig
72+
-D MAX_CONTACTS=100
73+
-D MAX_GROUP_CHANNELS=8
74+
; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1
75+
; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1
76+
build_src_filter = ${rak_wismesh_tag.build_src_filter}
77+
+<../examples/companion_radio/*.cpp>
78+
+<../examples/companion_radio/ui-orig/*.cpp>
79+
lib_deps =
80+
${rak_wismesh_tag.lib_deps}
81+
densaugeo/base64 @ ~1.4.0
82+
end2endzone/NonBlockingRTTTL@^1.3.0
83+
84+
[env:RAK_WisMesh_Tag_companion_radio_ble]
85+
extends = rak_wismesh_tag
86+
build_flags =
87+
${rak_wismesh_tag.build_flags}
88+
-I examples/companion_radio/ui-orig
89+
-D MAX_CONTACTS=100
90+
-D MAX_GROUP_CHANNELS=8
91+
-D BLE_PIN_CODE=123456
92+
-D BLE_DEBUG_LOGGING=1
93+
-D OFFLINE_QUEUE_SIZE=256
94+
; -D MESH_PACKET_LOGGING=1
95+
-D MESH_DEBUG=1
96+
build_src_filter = ${rak_wismesh_tag.build_src_filter}
97+
+<helpers/nrf52/SerialBLEInterface.cpp>
98+
+<../examples/companion_radio/*.cpp>
99+
+<../examples/companion_radio/ui-orig/*.cpp>
100+
lib_deps =
101+
${rak4631.lib_deps}
102+
densaugeo/base64 @ ~1.4.0
103+
end2endzone/NonBlockingRTTTL@^1.3.0
104+
105+
[env:RAK_WisMesh_Tag_sensor]
106+
extends = rak4631
107+
build_flags =
108+
${rak4631.build_flags}
109+
-D ADVERT_NAME='"RAK WM Sensor"'
110+
-D ADVERT_LAT=0.0
111+
-D ADVERT_LON=0.0
112+
-D ADMIN_PASSWORD='"password"'
113+
; -D MESH_PACKET_LOGGING=1
114+
-D MESH_DEBUG=1
115+
build_src_filter = ${rak4631.build_src_filter}
116+
+<../examples/simple_sensor>

0 commit comments

Comments
 (0)