mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-03-30 14:55:46 +00:00
@@ -47,10 +47,23 @@ static Adafruit_INA3221 INA3221;
|
||||
static Adafruit_INA219 INA219(TELEM_INA219_ADDRESS);
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_GPS && RAK_BOARD
|
||||
static uint32_t gpsResetPin = 0;
|
||||
static bool i2cGPSFlag = false;
|
||||
static bool serialGPSFlag = false;
|
||||
#define TELEM_RAK12500_ADDRESS 0x42 //RAK12500 Ublox GPS via i2c
|
||||
#include <SparkFun_u-blox_GNSS_Arduino_Library.h>
|
||||
static SFE_UBLOX_GNSS ublox_GNSS;
|
||||
#endif
|
||||
|
||||
bool EnvironmentSensorManager::begin() {
|
||||
#if ENV_INCLUDE_GPS
|
||||
#if RAK_BOARD
|
||||
rakGPSInit(); //probe base board/sockets for GPS
|
||||
#else
|
||||
initBasicGPS();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_AHTX0
|
||||
if (AHTX0.begin(&Wire, 0, TELEM_AHTX_ADDRESS)) {
|
||||
@@ -296,8 +309,85 @@ void EnvironmentSensorManager::initBasicGPS() {
|
||||
gps_active = false; //Set GPS visibility off until setting is changed
|
||||
}
|
||||
|
||||
#ifdef RAK_BOARD
|
||||
void EnvironmentSensorManager::rakGPSInit(){
|
||||
|
||||
Serial1.setPins(PIN_GPS_TX, PIN_GPS_RX);
|
||||
|
||||
#ifdef GPS_BAUD_RATE
|
||||
Serial1.begin(GPS_BAUD_RATE);
|
||||
#else
|
||||
Serial1.begin(9600);
|
||||
#endif
|
||||
|
||||
//search for the correct IO standby pin depending on socket used
|
||||
if(gpsIsAwake(WB_IO2)){
|
||||
// MESH_DEBUG_PRINTLN("RAK base board is RAK19007/10");
|
||||
// MESH_DEBUG_PRINTLN("GPS is installed on Socket A");
|
||||
}
|
||||
else if(gpsIsAwake(WB_IO4)){
|
||||
// MESH_DEBUG_PRINTLN("RAK base board is RAK19003/9");
|
||||
// MESH_DEBUG_PRINTLN("GPS is installed on Socket C");
|
||||
}
|
||||
else if(gpsIsAwake(WB_IO5)){
|
||||
// MESH_DEBUG_PRINTLN("RAK base board is RAK19001/11");
|
||||
// MESH_DEBUG_PRINTLN("GPS is installed on Socket F");
|
||||
}
|
||||
else{
|
||||
MESH_DEBUG_PRINTLN("No GPS found");
|
||||
gps_active = false;
|
||||
gps_detected = false;
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef FORCE_GPS_ALIVE // for use with repeaters, until GPS toggle is implimented
|
||||
//Now that GPS is found and set up, set to sleep for initial state
|
||||
stop_gps();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){
|
||||
|
||||
//set initial waking state
|
||||
pinMode(ioPin,OUTPUT);
|
||||
digitalWrite(ioPin,LOW);
|
||||
delay(500);
|
||||
digitalWrite(ioPin,HIGH);
|
||||
delay(500);
|
||||
|
||||
//Try to init RAK12500 on I2C
|
||||
if (ublox_GNSS.begin(Wire) == true){
|
||||
MESH_DEBUG_PRINTLN("RAK12500 GPS init correctly with pin %i",ioPin);
|
||||
ublox_GNSS.setI2COutput(COM_TYPE_NMEA);
|
||||
ublox_GNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT);
|
||||
gpsResetPin = ioPin;
|
||||
i2cGPSFlag = true;
|
||||
gps_active = true;
|
||||
gps_detected = true;
|
||||
return true;
|
||||
}
|
||||
else if(Serial1){
|
||||
MESH_DEBUG_PRINTLN("Serial GPS init correctly and is turned on");
|
||||
if(PIN_GPS_EN){
|
||||
gpsResetPin = PIN_GPS_EN;
|
||||
}
|
||||
serialGPSFlag = true;
|
||||
gps_active = true;
|
||||
gps_detected = true;
|
||||
return true;
|
||||
}
|
||||
MESH_DEBUG_PRINTLN("GPS did not init with this IO pin... try the next");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
void EnvironmentSensorManager::start_gps() {
|
||||
gps_active = true;
|
||||
#ifdef RAK_BOARD
|
||||
pinMode(gpsResetPin, OUTPUT);
|
||||
digitalWrite(gpsResetPin, HIGH);
|
||||
return;
|
||||
#endif
|
||||
#ifdef PIN_GPS_EN
|
||||
pinMode(PIN_GPS_EN, OUTPUT);
|
||||
digitalWrite(PIN_GPS_EN, HIGH);
|
||||
@@ -309,6 +399,11 @@ void EnvironmentSensorManager::start_gps() {
|
||||
|
||||
void EnvironmentSensorManager::stop_gps() {
|
||||
gps_active = false;
|
||||
#ifdef RAK_BOARD
|
||||
pinMode(gpsResetPin, OUTPUT);
|
||||
digitalWrite(gpsResetPin, LOW);
|
||||
return;
|
||||
#endif
|
||||
#ifdef PIN_GPS_EN
|
||||
pinMode(PIN_GPS_EN, OUTPUT);
|
||||
digitalWrite(PIN_GPS_EN, LOW);
|
||||
@@ -324,11 +419,28 @@ void EnvironmentSensorManager::loop() {
|
||||
_location->loop();
|
||||
|
||||
if (millis() > next_gps_update) {
|
||||
if (gps_active && _location->isValid()) {
|
||||
if(gps_active){
|
||||
#ifndef RAK_BOARD
|
||||
if (_location->isValid()) {
|
||||
node_lat = ((double)_location->getLatitude())/1000000.;
|
||||
node_lon = ((double)_location->getLongitude())/1000000.;
|
||||
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
|
||||
}
|
||||
#else
|
||||
if(i2cGPSFlag){
|
||||
node_lat = ((double)ublox_GNSS.getLatitude())/10000000.;
|
||||
node_lon = ((double)ublox_GNSS.getLongitude())/10000000.;
|
||||
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
|
||||
}
|
||||
else if (serialGPSFlag && _location->isValid()) {
|
||||
node_lat = ((double)_location->getLatitude())/1000000.;
|
||||
node_lon = ((double)_location->getLongitude())/1000000.;
|
||||
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
|
||||
}
|
||||
//else
|
||||
//MESH_DEBUG_PRINTLN("No valid GPS data");
|
||||
#endif
|
||||
}
|
||||
next_gps_update = millis() + 1000;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,10 @@ protected:
|
||||
void start_gps();
|
||||
void stop_gps();
|
||||
void initBasicGPS();
|
||||
#ifdef RAK_BOARD
|
||||
void rakGPSInit();
|
||||
bool gpsIsAwake(uint8_t ioPin);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -13,14 +13,11 @@
|
||||
#define P_LORA_MOSI 44
|
||||
#define SX126X_POWER_EN 37
|
||||
|
||||
#define P_GPS_SDA 13 //GPS SDA pin (output option)
|
||||
#define P_GPS_SCL 14 //GPS SCL pin (output option)
|
||||
#define P_GPS_TX 16 //GPS TX pin
|
||||
#define P_GPS_RX 15 //GPS RX pin
|
||||
#define P_GPS_STANDBY_A 34 //GPS Reset/Standby pin (IO2 for socket A)
|
||||
#define P_GPS_STANDBY_C 4 //GPS Reset/Standby pin (IO4 for socket C)
|
||||
#define P_GPS_STANDBY_F 9 //GPS Reset/Standby pin (IO5 for socket F)
|
||||
#define P_GPS_1PPS 17 //GPS PPS pin
|
||||
//#define PIN_GPS_SDA 13 //GPS SDA pin (output option)
|
||||
//#define PIN_GPS_SCL 14 //GPS SCL pin (output option)
|
||||
//#define PIN_GPS_TX 16 //GPS TX pin
|
||||
//#define PIN_GPS_RX 15 //GPS RX pin
|
||||
#define PIN_GPS_1PPS 17 //GPS PPS pin
|
||||
#define GPS_BAUD_RATE 9600
|
||||
#define GPS_ADDRESS 0x42 //i2c address for GPS
|
||||
|
||||
|
||||
@@ -6,20 +6,33 @@ board_check = true
|
||||
build_flags = ${nrf52_base.build_flags}
|
||||
-I variants/rak4631
|
||||
-D RAK_4631
|
||||
-D RAK_BOARD
|
||||
-D PIN_BOARD_SCL=14
|
||||
-D PIN_BOARD_SDA=13
|
||||
-D PIN_GPS_TX=16
|
||||
-D PIN_GPS_RX=15
|
||||
-D PIN_GPS_EN=-1
|
||||
-D PIN_OLED_RESET=-1
|
||||
-D RADIO_CLASS=CustomSX1262
|
||||
-D WRAPPER_CLASS=CustomSX1262Wrapper
|
||||
-D LORA_TX_POWER=22
|
||||
-D SX126X_CURRENT_LIMIT=140
|
||||
-D SX126X_RX_BOOSTED_GAIN=1
|
||||
-D ENV_INCLUDE_GPS=1
|
||||
-D ENV_INCLUDE_SHTC3=1
|
||||
-D ENV_INCLUDE_LPS22HB=1
|
||||
-D ENV_INCLUDE_INA219=1
|
||||
build_src_filter = ${nrf52_base.build_src_filter}
|
||||
+<../variants/rak4631>
|
||||
+<helpers/sensors>
|
||||
lib_deps =
|
||||
${nrf52_base.lib_deps}
|
||||
adafruit/Adafruit SSD1306 @ ^2.5.13
|
||||
stevemarple/MicroNMEA @ ^2.0.6
|
||||
adafruit/Adafruit SHTC3 Library@^1.0.1
|
||||
arduino-libraries/Arduino_LPS22HB@^1.0.2
|
||||
adafruit/Adafruit INA219@^1.2.3
|
||||
sparkfun/SparkFun u-blox GNSS Arduino Library@^2.2.27
|
||||
|
||||
[env:RAK_4631_Repeater]
|
||||
extends = rak4631
|
||||
@@ -37,30 +50,6 @@ build_src_filter = ${rak4631.build_src_filter}
|
||||
+<helpers/ui/SSD1306Display.cpp>
|
||||
+<../examples/simple_repeater>
|
||||
|
||||
[env:RAK_4631_GPS_Repeater]
|
||||
extends = rak4631
|
||||
build_flags =
|
||||
${rak4631.build_flags}
|
||||
-D DISPLAY_CLASS=SSD1306Display
|
||||
-D ADVERT_NAME='"RAK4631 GPS Repeater"'
|
||||
-D ADVERT_LAT=0.0
|
||||
-D ADVERT_LON=0.0
|
||||
-D ADMIN_PASSWORD='"password"'
|
||||
-D MAX_NEIGHBOURS=8
|
||||
-D FORCE_GPS_ALIVE=1
|
||||
-D ENV_INCLUDE_GPS=1
|
||||
-D ENV_INCLUDE_BME680=1
|
||||
; -D MESH_PACKET_LOGGING=1
|
||||
; -D MESH_DEBUG=1
|
||||
build_src_filter = ${rak4631.build_src_filter}
|
||||
+<helpers/ui/SSD1306Display.cpp>
|
||||
+<../examples/simple_repeater>
|
||||
lib_deps =
|
||||
${rak4631.lib_deps}
|
||||
sparkfun/SparkFun u-blox GNSS Arduino Library @ ^2.2.27
|
||||
https://github.com/boschsensortec/Bosch-BSEC2-Library
|
||||
https://github.com/boschsensortec/Bosch-BME68x-Library
|
||||
|
||||
[env:RAK_4631_room_server]
|
||||
extends = rak4631
|
||||
build_flags =
|
||||
@@ -117,33 +106,6 @@ lib_deps =
|
||||
${rak4631.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
|
||||
[env:RAK_4631_GPS_companion_radio_ble]
|
||||
extends = rak4631
|
||||
build_flags =
|
||||
${rak4631.build_flags}
|
||||
-D PIN_USER_BTN=9
|
||||
-D PIN_USER_BTN_ANA=31
|
||||
-D DISPLAY_CLASS=SSD1306Display
|
||||
-D MAX_CONTACTS=100
|
||||
-D MAX_GROUP_CHANNELS=8
|
||||
-D BLE_PIN_CODE=123456
|
||||
-D BLE_DEBUG_LOGGING=1
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
-D ENV_INCLUDE_GPS=1
|
||||
-D ENV_INCLUDE_BME680=1
|
||||
; -D MESH_PACKET_LOGGING=1
|
||||
; -D MESH_DEBUG=1
|
||||
build_src_filter = ${rak4631.build_src_filter}
|
||||
+<helpers/ui/SSD1306Display.cpp>
|
||||
+<helpers/nrf52/SerialBLEInterface.cpp>
|
||||
+<../examples/companion_radio>
|
||||
lib_deps =
|
||||
${rak4631.lib_deps}
|
||||
sparkfun/SparkFun u-blox GNSS Arduino Library @ ^2.2.27
|
||||
https://github.com/boschsensortec/Bosch-BSEC2-Library
|
||||
https://github.com/boschsensortec/Bosch-BME68x-Library
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
|
||||
[env:RAK_4631_terminal_chat]
|
||||
extends = rak4631
|
||||
build_flags =
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
#include <Arduino.h>
|
||||
#include "target.h"
|
||||
#include <helpers/ArduinoHelpers.h>
|
||||
#include <helpers/sensors/MicroNMEALocationProvider.h>
|
||||
|
||||
RAK4631Board board;
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
DISPLAY_CLASS display;
|
||||
#endif
|
||||
|
||||
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
|
||||
|
||||
WRAPPER_CLASS radio_driver(radio, board);
|
||||
@@ -13,80 +16,11 @@ VolatileRTCClock fallback_clock;
|
||||
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
||||
|
||||
#if ENV_INCLUDE_GPS
|
||||
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Wire);
|
||||
RAK4631SensorManager sensors = RAK4631SensorManager(nmea);
|
||||
#include <helpers/sensors/MicroNMEALocationProvider.h>
|
||||
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1);
|
||||
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
|
||||
#else
|
||||
RAK4631SensorManager sensors;
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_BME680
|
||||
#ifndef TELEM_BME680_ADDRESS
|
||||
#define TELEM_BME680_ADDRESS 0x76 // BME680 environmental sensor I2C address
|
||||
#endif
|
||||
#include <bsec2.h>
|
||||
static Bsec2 BME680;
|
||||
static float rawPressure = 0;
|
||||
static float rawTemperature = 0;
|
||||
static float compTemperature = 0;
|
||||
static float rawHumidity = 0;
|
||||
static float compHumidity = 0;
|
||||
static float readIAQ = 0;
|
||||
static float readStaticIAQ = 0;
|
||||
static float readCO2 = 0;
|
||||
#endif
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
DISPLAY_CLASS display;
|
||||
#endif
|
||||
|
||||
#ifdef MESH_DEBUG
|
||||
uint32_t deviceOnline = 0x00;
|
||||
static void scanDevices(TwoWire *w)
|
||||
{
|
||||
uint8_t err, addr;
|
||||
int nDevices = 0;
|
||||
uint32_t start = 0;
|
||||
|
||||
Serial.println("Scanning I2C for Devices");
|
||||
for (addr = 1; addr < 127; addr++) {
|
||||
start = millis();
|
||||
w->beginTransmission(addr); delay(2);
|
||||
err = w->endTransmission();
|
||||
if (err == 0) {
|
||||
nDevices++;
|
||||
switch (addr) {
|
||||
case 0x42:
|
||||
Serial.println("\tFound RAK12500 GPS Sensor");
|
||||
deviceOnline |= RAK12500_ONLINE;
|
||||
break;
|
||||
case 0x76:
|
||||
Serial.println("\tFound RAK1906 Environment Sensor");
|
||||
deviceOnline |= BME680_ONLINE;
|
||||
break;
|
||||
default:
|
||||
Serial.print("\tI2C device found at address 0x");
|
||||
if (addr < 16) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.print(addr, HEX);
|
||||
Serial.println(" !");
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (err == 4) {
|
||||
Serial.print("Unknow error at address 0x");
|
||||
if (addr < 16) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.println(addr, HEX);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
Serial.println("No I2C devices found\n");
|
||||
|
||||
Serial.println("Scan for devices is complete.");
|
||||
Serial.println("\n");
|
||||
}
|
||||
EnvironmentSensorManager sensors;
|
||||
#endif
|
||||
|
||||
bool radio_init() {
|
||||
@@ -109,324 +43,6 @@ void radio_set_tx_power(uint8_t dbm) {
|
||||
radio.setOutputPower(dbm);
|
||||
}
|
||||
|
||||
#if ENV_INCLUDE_GPS
|
||||
void RAK4631SensorManager::start_gps()
|
||||
{
|
||||
//function currently not used
|
||||
gps_active = true;
|
||||
pinMode(disStandbyPin, OUTPUT);
|
||||
digitalWrite(disStandbyPin, 1);
|
||||
MESH_DEBUG_PRINTLN("GPS should be on now");
|
||||
}
|
||||
|
||||
void RAK4631SensorManager::stop_gps()
|
||||
{
|
||||
//function currently not used
|
||||
gps_active = false;
|
||||
pinMode(disStandbyPin, OUTPUT);
|
||||
digitalWrite(disStandbyPin, 0);
|
||||
MESH_DEBUG_PRINTLN("GPS should be off now");
|
||||
}
|
||||
|
||||
void RAK4631SensorManager::sleep_gps() {
|
||||
gps_active = false;
|
||||
ublox_GNSS.powerSaveMode();
|
||||
MESH_DEBUG_PRINTLN("GPS should be sleeping now");
|
||||
}
|
||||
|
||||
void RAK4631SensorManager::wake_gps() {
|
||||
gps_active = true;
|
||||
ublox_GNSS.powerSaveMode(false);
|
||||
MESH_DEBUG_PRINTLN("GPS should be waking now");
|
||||
}
|
||||
|
||||
bool RAK4631SensorManager::gpsIsAwake(uint32_t ioPin){
|
||||
|
||||
int pinInitialState = 0;
|
||||
|
||||
//set initial waking state
|
||||
pinMode(ioPin,OUTPUT);
|
||||
digitalWrite(ioPin,0);
|
||||
delay(1000);
|
||||
digitalWrite(ioPin,1);
|
||||
delay(1000);
|
||||
|
||||
if (ublox_GNSS.begin(Wire) == true){
|
||||
MESH_DEBUG_PRINTLN("GPS init correctly and GPS is turned on");
|
||||
ublox_GNSS.setI2COutput(COM_TYPE_NMEA);
|
||||
ublox_GNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT);
|
||||
disStandbyPin = ioPin;
|
||||
gps_active = true;
|
||||
gps_detected = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
MESH_DEBUG_PRINTLN("GPS failed to init on this IO pin... try the next");
|
||||
//digitalWrite(ioPin,pinInitialState); //reset the IO pin to initial state
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_BME680
|
||||
static void checkBMEStatus(Bsec2 bsec) {
|
||||
if (bsec.status < BSEC_OK)
|
||||
{
|
||||
MESH_DEBUG_PRINTLN("BSEC error code : %f", float(bsec.status));
|
||||
}
|
||||
else if (bsec.status > BSEC_OK)
|
||||
{
|
||||
MESH_DEBUG_PRINTLN("BSEC warning code : %f", float(bsec.status));
|
||||
}
|
||||
|
||||
if (bsec.sensor.status < BME68X_OK)
|
||||
{
|
||||
MESH_DEBUG_PRINTLN("BME68X error code : %f", bsec.sensor.status);
|
||||
}
|
||||
else if (bsec.sensor.status > BME68X_OK)
|
||||
{
|
||||
MESH_DEBUG_PRINTLN("BME68X warning code : %f", bsec.sensor.status);
|
||||
}
|
||||
}
|
||||
|
||||
static void newDataCallback(const bme68xData data, const bsecOutputs outputs, Bsec2 bsec) {
|
||||
if (!outputs.nOutputs) {
|
||||
MESH_DEBUG_PRINTLN("No new data to report out");
|
||||
return;
|
||||
}
|
||||
|
||||
MESH_DEBUG_PRINTLN("BSEC outputs:\n\tTime stamp = %f", (int) (outputs.output[0].time_stamp / INT64_C(1000000)));
|
||||
for (uint8_t i = 0; i < outputs.nOutputs; i++) {
|
||||
const bsecData output = outputs.output[i];
|
||||
switch (output.sensor_id)
|
||||
{
|
||||
case BSEC_OUTPUT_IAQ:
|
||||
readIAQ = output.signal;
|
||||
MESH_DEBUG_PRINTLN("\tIAQ = %f", output.signal);
|
||||
MESH_DEBUG_PRINTLN("\tIAQ accuracy = %f", output.accuracy);
|
||||
break;
|
||||
case BSEC_OUTPUT_RAW_TEMPERATURE:
|
||||
rawTemperature = output.signal;
|
||||
MESH_DEBUG_PRINTLN("\tTemperature = %f", output.signal);
|
||||
break;
|
||||
case BSEC_OUTPUT_RAW_PRESSURE:
|
||||
rawPressure = output.signal;
|
||||
MESH_DEBUG_PRINTLN("\tPressure = %f", output.signal);
|
||||
break;
|
||||
case BSEC_OUTPUT_RAW_HUMIDITY:
|
||||
rawHumidity = output.signal;
|
||||
MESH_DEBUG_PRINTLN("\tHumidity = %f", output.signal);
|
||||
break;
|
||||
case BSEC_OUTPUT_RAW_GAS:
|
||||
MESH_DEBUG_PRINTLN("\tGas resistance = %f", output.signal);
|
||||
break;
|
||||
case BSEC_OUTPUT_STABILIZATION_STATUS:
|
||||
MESH_DEBUG_PRINTLN("\tStabilization status = %f", output.signal);
|
||||
break;
|
||||
case BSEC_OUTPUT_RUN_IN_STATUS:
|
||||
MESH_DEBUG_PRINTLN("\tRun in status = %f", output.signal);
|
||||
break;
|
||||
case BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE:
|
||||
compTemperature = output.signal;
|
||||
MESH_DEBUG_PRINTLN("\tCompensated temperature = %f", output.signal);
|
||||
break;
|
||||
case BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY:
|
||||
compHumidity = output.signal;
|
||||
MESH_DEBUG_PRINTLN("\tCompensated humidity = %f", output.signal);
|
||||
break;
|
||||
case BSEC_OUTPUT_STATIC_IAQ:
|
||||
readStaticIAQ = output.signal;
|
||||
MESH_DEBUG_PRINTLN("\tStatic IAQ = %f", output.signal);
|
||||
break;
|
||||
case BSEC_OUTPUT_CO2_EQUIVALENT:
|
||||
readCO2 = output.signal;
|
||||
MESH_DEBUG_PRINTLN("\tCO2 Equivalent = %f", output.signal);
|
||||
break;
|
||||
case BSEC_OUTPUT_BREATH_VOC_EQUIVALENT:
|
||||
MESH_DEBUG_PRINTLN("\tbVOC equivalent = %f", output.signal);
|
||||
break;
|
||||
case BSEC_OUTPUT_GAS_PERCENTAGE:
|
||||
MESH_DEBUG_PRINTLN("\tGas percentage = %f", output.signal);
|
||||
break;
|
||||
case BSEC_OUTPUT_COMPENSATED_GAS:
|
||||
MESH_DEBUG_PRINTLN("\tCompensated gas = %f", output.signal);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool RAK4631SensorManager::begin() {
|
||||
|
||||
#ifdef MESH_DEBUG
|
||||
scanDevices(&Wire);
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_GPS
|
||||
//search for the correct IO standby pin depending on socket used
|
||||
if(gpsIsAwake(P_GPS_STANDBY_A)){
|
||||
MESH_DEBUG_PRINTLN("GPS is on socket A");
|
||||
}
|
||||
else if(gpsIsAwake(P_GPS_STANDBY_C)){
|
||||
MESH_DEBUG_PRINTLN("GPS is on socket C");
|
||||
}
|
||||
else if(gpsIsAwake(P_GPS_STANDBY_F)){
|
||||
MESH_DEBUG_PRINTLN("GPS is on socket F");
|
||||
}
|
||||
else{
|
||||
MESH_DEBUG_PRINTLN("Error: No GPS found on sockets A, C or F");
|
||||
gps_active = false;
|
||||
gps_detected = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef FORCE_GPS_ALIVE
|
||||
//Now that GPS is found and set up, set to sleep for initial state
|
||||
stop_gps();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_BME680
|
||||
|
||||
bsecSensor sensorList[5] = {
|
||||
BSEC_OUTPUT_IAQ,
|
||||
// BSEC_OUTPUT_RAW_TEMPERATURE,
|
||||
BSEC_OUTPUT_RAW_PRESSURE,
|
||||
// BSEC_OUTPUT_RAW_HUMIDITY,
|
||||
// BSEC_OUTPUT_RAW_GAS,
|
||||
// BSEC_OUTPUT_STABILIZATION_STATUS,
|
||||
// BSEC_OUTPUT_RUN_IN_STATUS,
|
||||
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
|
||||
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
|
||||
BSEC_OUTPUT_STATIC_IAQ,
|
||||
// BSEC_OUTPUT_CO2_EQUIVALENT,
|
||||
// BSEC_OUTPUT_BREATH_VOC_EQUIVALENT,
|
||||
// BSEC_OUTPUT_GAS_PERCENTAGE,
|
||||
// BSEC_OUTPUT_COMPENSATED_GAS
|
||||
};
|
||||
|
||||
if(!BME680.begin(TELEM_BME680_ADDRESS, Wire)){
|
||||
checkBMEStatus(BME680);
|
||||
bme680_present = false;
|
||||
bme680_active = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
MESH_DEBUG_PRINTLN("Found BME680 at address: %02X", TELEM_BME680_ADDRESS);
|
||||
bme680_present = true;
|
||||
bme680_active = true;
|
||||
|
||||
if (SAMPLING_RATE == BSEC_SAMPLE_RATE_ULP)
|
||||
{
|
||||
BME680.setTemperatureOffset(BSEC_SAMPLE_RATE_ULP);
|
||||
}
|
||||
else if (SAMPLING_RATE == BSEC_SAMPLE_RATE_LP)
|
||||
{
|
||||
BME680.setTemperatureOffset(TEMP_OFFSET_LP);
|
||||
}
|
||||
|
||||
if (!BME680.updateSubscription(sensorList, ARRAY_LEN(sensorList), SAMPLING_RATE))
|
||||
{
|
||||
checkBMEStatus(BME680);
|
||||
}
|
||||
|
||||
BME680.attachCallback(newDataCallback);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RAK4631SensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) {
|
||||
#ifdef ENV_INCLUDE_GPS
|
||||
if (requester_permissions & TELEM_PERM_LOCATION && gps_active) { // does requester have permission?
|
||||
telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (requester_permissions & TELEM_PERM_ENVIRONMENT) {
|
||||
|
||||
#if ENV_INCLUDE_BME680
|
||||
if (bme680_active) {
|
||||
telemetry.addTemperature(TELEM_CHANNEL_SELF, compTemperature);
|
||||
telemetry.addRelativeHumidity(TELEM_CHANNEL_SELF, compHumidity);
|
||||
telemetry.addBarometricPressure(TELEM_CHANNEL_SELF, rawPressure);
|
||||
telemetry.addTemperature(TELEM_CHANNEL_SELF+1, readIAQ);
|
||||
telemetry.addRelativeHumidity(TELEM_CHANNEL_SELF+1, readStaticIAQ);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RAK4631SensorManager::loop() {
|
||||
static long next_update = 0;
|
||||
|
||||
#ifdef ENV_INCLUDE_GPS
|
||||
_nmea->loop();
|
||||
#endif
|
||||
|
||||
if (millis() > next_update) {
|
||||
|
||||
#ifdef ENV_INCLUDE_GPS
|
||||
if(gps_active){
|
||||
node_lat = (double)ublox_GNSS.getLatitude()/10000000.;
|
||||
node_lon = (double)ublox_GNSS.getLongitude()/10000000.;
|
||||
node_altitude = (double)ublox_GNSS.getAltitude()/1000.;
|
||||
MESH_DEBUG_PRINT("lat %f lon %f alt %f\r\n", node_lat, node_lon, node_altitude);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENV_INCLUDE_BME680
|
||||
if(bme680_active){
|
||||
if (!BME680.run()){
|
||||
checkBMEStatus(BME680);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
next_update = millis() + 1000;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int RAK4631SensorManager::getNumSettings() const {
|
||||
#if ENV_INCLUDE_GPS
|
||||
return gps_detected ? 1 : 0; // only show GPS setting if GPS is detected
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* RAK4631SensorManager::getSettingName(int i) const {
|
||||
#if ENV_INCLUDE_GPS
|
||||
return (gps_detected && i == 0) ? "gps" : NULL;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* RAK4631SensorManager::getSettingValue(int i) const {
|
||||
#if ENV_INCLUDE_GPS
|
||||
if (gps_detected && i == 0) {
|
||||
return gps_active ? "1" : "0";
|
||||
}
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool RAK4631SensorManager::setSettingValue(const char* name, const char* value) {
|
||||
#if ENV_INCLUDE_GPS
|
||||
if (gps_detected && strcmp(name, "gps") == 0) {
|
||||
if (strcmp(value, "0") == 0) {
|
||||
stop_gps();
|
||||
} else {
|
||||
start_gps();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false; // not supported
|
||||
}
|
||||
|
||||
mesh::LocalIdentity radio_new_identity() {
|
||||
RadioNoiseListener rng(radio);
|
||||
return mesh::LocalIdentity(&rng); // create new random identity
|
||||
|
||||
@@ -6,80 +6,17 @@
|
||||
#include <RAK4631Board.h>
|
||||
#include <helpers/radiolib/CustomSX1262Wrapper.h>
|
||||
#include <helpers/AutoDiscoverRTCClock.h>
|
||||
#include <helpers/SensorManager.h>
|
||||
#if ENV_INCLUDE_GPS
|
||||
#include <helpers/sensors/LocationProvider.h>
|
||||
#include <SparkFun_u-blox_GNSS_Arduino_Library.h>
|
||||
#endif
|
||||
#include <helpers/sensors/EnvironmentSensorManager.h>
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
#include <helpers/ui/SSD1306Display.h>
|
||||
extern DISPLAY_CLASS display;
|
||||
#endif
|
||||
|
||||
#define _BV(x) (1 << x)
|
||||
|
||||
class RAK4631SensorManager: public SensorManager {
|
||||
#if ENV_INCLUDE_GPS
|
||||
bool gps_active = false;
|
||||
bool gps_detected = false;
|
||||
LocationProvider * _nmea;
|
||||
SFE_UBLOX_GNSS ublox_GNSS;
|
||||
uint32_t disStandbyPin = 0;
|
||||
|
||||
void start_gps();
|
||||
void stop_gps();
|
||||
void sleep_gps();
|
||||
void wake_gps();
|
||||
bool gpsIsAwake(uint32_t ioPin);
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_BME680
|
||||
bool bme680_active = false;
|
||||
bool bme680_present = false;
|
||||
#define SAMPLING_RATE BSEC_SAMPLE_RATE_ULP
|
||||
#endif
|
||||
|
||||
public:
|
||||
#if ENV_INCLUDE_GPS
|
||||
RAK4631SensorManager(LocationProvider &nmea): _nmea(&nmea) { }
|
||||
#else
|
||||
RAK4631SensorManager() { }
|
||||
#endif
|
||||
|
||||
void loop() override;
|
||||
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override;
|
||||
int getNumSettings() const override;
|
||||
const char* getSettingName(int i) const override;
|
||||
const char* getSettingValue(int i) const override;
|
||||
bool setSettingValue(const char* name, const char* value) override;
|
||||
bool begin() override;
|
||||
};
|
||||
|
||||
extern RAK4631Board board;
|
||||
extern WRAPPER_CLASS radio_driver;
|
||||
extern AutoDiscoverRTCClock rtc_clock;
|
||||
extern RAK4631SensorManager sensors;
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
extern DISPLAY_CLASS display;
|
||||
#endif
|
||||
|
||||
enum {
|
||||
POWERMANAGE_ONLINE = _BV(0),
|
||||
DISPLAY_ONLINE = _BV(1),
|
||||
RADIO_ONLINE = _BV(2),
|
||||
GPS_ONLINE = _BV(3),
|
||||
PSRAM_ONLINE = _BV(4),
|
||||
SDCARD_ONLINE = _BV(5),
|
||||
AXDL345_ONLINE = _BV(6),
|
||||
BME280_ONLINE = _BV(7),
|
||||
BMP280_ONLINE = _BV(8),
|
||||
BME680_ONLINE = _BV(9),
|
||||
QMC6310_ONLINE = _BV(10),
|
||||
QMI8658_ONLINE = _BV(11),
|
||||
PCF8563_ONLINE = _BV(12),
|
||||
OSC32768_ONLINE = _BV(13),
|
||||
RAK12500_ONLINE = _BV(14),
|
||||
};
|
||||
extern EnvironmentSensorManager sensors;
|
||||
|
||||
bool radio_init();
|
||||
uint32_t radio_get_rng_seed();
|
||||
|
||||
Reference in New Issue
Block a user