Compare commits

..

34 Commits

Author SHA1 Message Date
Ben Meadors
9db7c62a49 1.2.55 release 2022-02-10 21:02:43 -06:00
Ben Meadors
d79dc631f1 Fixed RAK11200 configuration and added to build-all (#1192)
* Fixed RAK11200 configuration and added to build-all 

Co-authored-by: Mike Kinney <mike.kinney@gmail.com>
2022-02-10 20:21:36 -06:00
Ben Meadors
7ea6babb7f Add workflow_dispatch back 2022-02-10 16:23:34 -06:00
Garth Vander Houwen
0b4b901504 Merge pull request #1196 from meshtastic/mkinney-patch-1
Update main.yml
2022-02-10 14:09:49 -08:00
mkinney
cc7b5cf136 Update main.yml 2022-02-10 14:06:09 -08:00
Clemens H / OE1RFC / datacop
e3df4fe4b4 fix: log error if node_db is full instead of firmware crash (#1191) 2022-02-10 11:44:58 -06:00
Jm Casler
288f2be8ea bump to 1.2.54 2022-02-09 16:46:26 -08:00
Ben Meadors
c867af8522 Adjusted adc_multiplier for heltec2.1 and added adc_mulitplier_override (#1183) 2022-02-09 13:37:48 -06:00
Ric Letson
856f2f9589 MCP9808 sensor implementation (#1188)
* MCP9808 Sensor Implementation Initial Test
2022-02-08 11:03:34 -06:00
Ben Meadors
e649bc84e1 Fix PR artifact permissions (#1190) 2022-02-08 10:29:57 -06:00
Ben Meadors
bbcd59ec7b Specify branch for PR artifact storage (#1187) 2022-02-07 12:44:10 -06:00
Ben Meadors
e11fd593ae Update github action to flatten firmware zip and attach artifacts (#1186) 2022-02-07 11:15:03 -06:00
Thomas Göttgens
868af9dd6b Get rid of log clutter during oled screen animation (#1182) 2022-02-03 07:22:46 -06:00
Garth Vander Houwen
10800a6914 Merge pull request #1180 from meshtastic/create-pull-request/patch
Changes by create-pull-request action
2022-02-02 19:59:41 -08:00
thebentern
e567fe7322 [create-pull-request] automated change 2022-02-03 03:21:12 +00:00
Ben Meadors
365120e9c2 Added RAK11200 board variant support (#1177)
* Added RAK11200 board variant support
2022-02-02 12:41:07 -06:00
Ben Meadors
b21b7de04b Clear bluetooth bonds on multi-press and factory_reset (#1176)
* Clear bluetooth bonds on multi-press and factory_reset
2022-02-01 18:32:26 -06:00
github-actions[bot]
dd31a829fb Update and regen protobufs (#1175)
* Update and regen protobufs
2022-02-01 09:41:56 -06:00
Thomas Göttgens
9a505c27fa add missing Config definition for PRIVATE_HW (#1174) 2022-02-01 08:08:03 -06:00
Ben Meadors
ed9cd7b03d Update nimble (#1173) 2022-01-31 20:56:31 -06:00
Ben Meadors
66413d8b7f Refactored sensors (#1172)
* Refactored sensors
2022-01-31 20:24:32 -06:00
Jm Casler
e4fe2c159a Merge pull request #1165 from joshpirihi/master
Allow publishing of decrypted packets to MQTT
2022-01-28 21:10:00 -08:00
Jm Casler
f5e0718052 Merge branch 'master' into master 2022-01-28 20:13:46 -08:00
Jm Casler
64ff48c4a5 Merge pull request #1163 from caveman99/caveman99-patch-1
Fixed typo
2022-01-28 13:05:52 -08:00
Jm Casler
50969c4e42 Merge branch 'master' into caveman99-patch-1 2022-01-28 13:05:45 -08:00
Jm Casler
5288f1846a Merge pull request #1166 from rnauber/fix_nullptrderef
Prevent null pointer dereference in setup() if radio is not available.
2022-01-28 13:05:25 -08:00
Jm Casler
c545155b03 Merge branch 'master' into fix_nullptrderef 2022-01-28 13:05:11 -08:00
Vladislav Osmanov
a4e9fca80c DIY versions cleaning - moved to the one folder (#1167) 2022-01-28 14:58:27 -06:00
Richard Nauber
3611293a98 Prevent null pointer dereference in setup() if radio is not available. 2022-01-28 21:02:02 +01:00
joshpirihi
dc7f376778 Correct a comment 2022-01-29 06:40:17 +13:00
Joshua Pirihi
ff2cad9cac Allow publishing of decrypted mqtt packets 2022-01-29 06:06:49 +13:00
Joshua Pirihi
b781fb613c Allow publishing of decrypted mqtt packets 2022-01-29 06:03:48 +13:00
Thomas Göttgens
0a1125d7e4 Merge branch 'master' into caveman99-patch-1 2022-01-28 08:44:46 +01:00
Thomas Göttgens
ed2de3b885 Fixed typo 2022-01-28 08:43:48 +01:00
42 changed files with 682 additions and 201 deletions

View File

@@ -6,11 +6,14 @@ on:
paths-ignore:
- '**.md'
- '**.yml'
pull_request:
# Note: This is different from "pull_request". Need to specify ref when doing checkouts.
pull_request_target:
branches: [ master ]
paths-ignore:
- '**.md'
- '**.yml'
jobs:
ci-check:
@@ -21,6 +24,8 @@ jobs:
uses: actions/checkout@v2
with:
submodules: 'recursive'
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Install cppcheck
run: |
@@ -60,6 +65,8 @@ jobs:
uses: actions/checkout@v2
with:
submodules: 'recursive'
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Setup Python
uses: actions/setup-python@v2
@@ -114,22 +121,23 @@ jobs:
echo "Simulator started, launching python test..."
python3 -c 'from meshtastic.test import testSimulator; testSimulator()'
# - name: Build for tbeam
# run: platformio run -e tbeam
# - name: Build for heltec
# run: platformio run -e heltec
# - name: Build for wisblock RAK4631
# run: platformio run -e rak4631
- name: Cat bin/build-all.sh
run: |
cat bin/build-all.sh
- name: Build everything
run: bin/build-all.sh
- name: Get release version string
run: echo "::set-output name=version::$(./bin/buildinfo.py long)"
id: version
- name: Store binaries as an artifact
uses: actions/upload-artifact@v2
with:
name: built
path: release/archive/firmware-*.zip
retention-days: 30
name: firmware-${{ steps.version.outputs.version }}.zip
path: release/archive/firmware-${{ steps.version.outputs.version }}.zip
retention-days: 90
- name: Store debugging elf files as an artifact
uses: actions/upload-artifact@v2
@@ -137,3 +145,18 @@ jobs:
name: debug-elfs
path: release/archive/elfs-*.zip
retention-days: 7
- name: Download firmware.zip
uses: actions/download-artifact@master
with:
name: firmware-${{ steps.version.outputs.version }}.zip
path: ./
- name: Pull request artifacts
if: ${{ github.event_name == 'pull_request_target' || github.event_name == 'pull_request' }}
uses: gavv/pull-request-artifacts@v1.0.0
with:
commit: ${{ (github.event.pull_request_target || github.event.pull_request).head.sha }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
artifacts-branch: artifacts
artifacts: ./firmware-${{ steps.version.outputs.version }}.zip

View File

@@ -1,7 +1,7 @@
name: Make Release
on:
# Can optionally take parameters from the github UI, more info here https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/#:~:text=You%20can%20now%20create%20workflows,the%20workflow%20is%20run%20on.
# workflow_dispatch:
workflow_dispatch:
# inputs:
# Only want to run if version.properties is bumped in master

View File

@@ -5,7 +5,7 @@ set -e
VERSION=`bin/buildinfo.py long`
SHORT_VERSION=`bin/buildinfo.py short`
BOARDS_ESP32="tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec-v1 heltec-v2.0 heltec-v2.1 tbeam0.7 meshtastic-diy-v1"
BOARDS_ESP32="rak11200 tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec-v1 heltec-v2.0 heltec-v2.1 tbeam0.7 meshtastic-diy-v1"
#BOARDS_ESP32=tbeam
# FIXME note nrf52840dk build is for some reason only generating a BIN file but not a HEX file nrf52840dk-geeksville is fine
@@ -28,7 +28,7 @@ function do_build() {
BOARD=$1
isNrf=$3
echo "Building for $BOARD with $PLATFORMIO_BUILD_FLAGS"
echo "Building for $BOARD ($isNrf) with $PLATFORMIO_BUILD_FLAGS"
rm -f .pio/build/$BOARD/firmware.*
# The shell vars the build tool expects to find
@@ -59,6 +59,7 @@ function do_boards() {
declare isNrf=$2
for board in $boards; do
# Build universal
echo "about to build $board $isNrf"
do_build $board "" "$isNrf"
done
}

View File

@@ -11,12 +11,12 @@ export APP_VERSION=$VERSION
if [[ $# -gt 0 ]]; then
# can override which environment by passing arg
BOARDS="-e $@"
BOARDS="$@"
else
BOARDS="tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec-v1 heltec-v2.0 heltec-v2.1 tbeam0.7 meshtastic-diy-v1 rak4631_5005 rak4631_19003 t-echo"
BOARDS="tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec-v1 heltec-v2.0 heltec-v2.1 tbeam0.7 meshtastic-diy-v1 rak4631_5005 rak4631_19003 rak11200 t-echo"
fi
#echo "BOARDS:${BOARDS}"
echo "BOARDS:${BOARDS}"
CHECK=""
for BOARD in $BOARDS; do

View File

@@ -0,0 +1,39 @@
{
"build": {
"arduino":{
"ldscript": "esp32_out.ld"
},
"core": "esp32",
"extra_flags": "-DARDUINO_ESP32_DEV",
"f_cpu": "240000000L",
"f_flash": "40000000L",
"flash_mode": "dio",
"mcu": "esp32",
"variant": "WisCore_RAK11200_Board"
},
"connectivity": [
"wifi",
"bluetooth",
"ethernet",
"can"
],
"frameworks": [
"arduino",
"espidf"
],
"name": "WisCore RAK11200 Board",
"upload": {
"flash_size": "4MB",
"maximum_ram_size": 327680,
"maximum_size": 4194304,
"protocols": [
"esptool",
"espota",
"ftdi"
],
"require_upload_port": true,
"speed": 460800
},
"url": "https://www.rakwireless.com",
"vendor": "RAKwireless"
}

View File

@@ -116,6 +116,7 @@ lib_deps =
robtillaart/DS18B20@^0.1.11
adafruit/Adafruit BME280 Library@^2.2.2
adafruit/Adafruit BME680 Library@^2.0.1
adafruit/Adafruit MCP9808 Library@^2.0.0
; Common settings for ESP targes, mixin with extends = esp32_base
[esp32_base]
@@ -137,7 +138,7 @@ lib_deps =
${arduino_base.lib_deps}
${environmental.lib_deps}
https://github.com/meshtastic/esp32_https_server.git
h2zero/NimBLE-Arduino@1.3.4
h2zero/NimBLE-Arduino@1.3.6
tobozo/ESP32-targz@^1.1.4
arduino-libraries/NTPClient#531eff39d9fbc831f3d03f706a161739203fbe2a
@@ -263,4 +264,4 @@ monitor_port = /dev/ttyUSB0
monitor_speed = 115200
# For experimenting with RAM sizes
# board_build.ldscript = linker/nrf52840_s140_sim832.ld
# board_build.ldscript = linker/nrf52840_s140_sim832.ld

2
proto

Submodule proto updated: 07ed86d8b4...2930129e8e

View File

@@ -63,7 +63,9 @@ class GPSStatus : public Status
int32_t getLatitude() const {
if (radioConfig.preferences.fixed_position){
#if GPS_EXTRAVERBOSE
DEBUG_MSG("WARNING: Using fixed latitude\n");
#endif
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
return node->position.latitude_i;
} else {
@@ -73,7 +75,9 @@ class GPSStatus : public Status
int32_t getLongitude() const {
if (radioConfig.preferences.fixed_position){
#if GPS_EXTRAVERBOSE
DEBUG_MSG("WARNING: Using fixed longitude\n");
#endif
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
return node->position.longitude_i;
} else {
@@ -83,7 +87,9 @@ class GPSStatus : public Status
int32_t getAltitude() const {
if (radioConfig.preferences.fixed_position){
#if GPS_EXTRAVERBOSE
DEBUG_MSG("WARNING: Using fixed altitude\n");
#endif
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
return node->position.altitude;
} else {

View File

@@ -100,6 +100,10 @@ class AnalogBatteryLevel : public HasBatteryLevel
#ifndef ADC_MULTIPLIER
#define ADC_MULTIPLIER 2.0
#endif
// Override variant or default ADC_MULTIPLIER if we have the override pref
float operativeAdcMultiplier = radioConfig.preferences.adc_multiplier_override > 0 ?
radioConfig.preferences.adc_multiplier_override :
ADC_MULTIPLIER;
#ifdef BATTERY_PIN
// Do not call analogRead() often.
@@ -109,7 +113,7 @@ class AnalogBatteryLevel : public HasBatteryLevel
uint32_t raw = analogRead(BATTERY_PIN);
float scaled;
#ifndef VBAT_RAW_TO_SCALED
scaled = 1000.0 * ADC_MULTIPLIER * (AREF_VOLTAGE / 1024.0) * raw;
scaled = 1000.0 * operativeAdcMultiplier * (AREF_VOLTAGE / 1024.0) * raw;
#else
scaled = VBAT_RAW_TO_SCALED(raw); //defined in variant.h
#endif

View File

@@ -161,6 +161,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// This string must exactly match the case used in release file names or the android updater won't work
#define HW_VENDOR HardwareModel_DIY_V1
#elif defined(RAK_11200)
// This string must exactly match the case used in release file names or the android updater won't work
#define HW_VENDOR HardwareModel_RAK11200
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32_V2)
#ifdef HELTEC_V2_0
@@ -199,6 +203,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// This string must exactly match the case used in release file names or the android updater won't work
#define HW_VENDOR HardwareModel_GENIEBLOCKS
#elif defined(PRIVATE_HW)
// This string must exactly match the case used in release file names or the android updater won't work
#define HW_VENDOR HardwareModel_PRIVATE_HW
#endif
#ifdef ARDUINO_NRF52840_PCA10056

View File

@@ -340,6 +340,9 @@ class ButtonThread : public OSThread
{
#ifndef NO_ESP32
clearNVS();
#endif
#ifdef NRF52_SERIES
clearBonds();
#endif
}
@@ -658,16 +661,16 @@ void setup()
if (!rIf)
RECORD_CRITICALERROR(CriticalErrorCode_NoRadio);
else
else{
router->addInterface(rIf);
// Calculate and save the bit rate to myNodeInfo
// TODO: This needs to be added what ever method changes the channel from the phone.
myNodeInfo.bitrate = (float(Constants_DATA_PAYLOAD_LEN) /
(float(rIf->getPacketTime(Constants_DATA_PAYLOAD_LEN)))
) * 1000;
DEBUG_MSG("myNodeInfo.bitrate = %f bytes / sec\n", myNodeInfo.bitrate);
// Calculate and save the bit rate to myNodeInfo
// TODO: This needs to be added what ever method changes the channel from the phone.
myNodeInfo.bitrate = (float(Constants_DATA_PAYLOAD_LEN) /
(float(rIf->getPacketTime(Constants_DATA_PAYLOAD_LEN)))
) * 1000;
DEBUG_MSG("myNodeInfo.bitrate = %f bytes / sec\n", myNodeInfo.bitrate);
}
// This must be _after_ service.init because we need our preferences loaded from flash to have proper timeout values
PowerFSM_setup(); // we will transition to ON in a couple of seconds, FIXME, only do this for cold boots, not waking from SDS

View File

@@ -27,4 +27,4 @@ extern uint32_t shutdownAtMsec;
// This will supress the current delay and instead try to run ASAP.
extern bool runASAP;
void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop();
void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(), clearBonds();

View File

@@ -26,6 +26,11 @@
#include <nvs_flash.h>
#endif
#ifdef NRF52_SERIES
#include <bluefruit.h>
#include <utility/bonding.h>
#endif
NodeDB nodeDB;
// we have plenty of ram so statically alloc this tempbuf (for now)
@@ -90,6 +95,16 @@ bool NodeDB::resetRadioConfig()
#ifndef NO_ESP32
// This will erase what's in NVS including ssl keys, persistant variables and ble pairing
nvs_flash_erase();
#endif
#ifdef NRF52_SERIES
Bluefruit.begin();
DEBUG_MSG("Clearing bluetooth bonds!\n");
bond_print_list(BLE_GAP_ROLE_PERIPH);
bond_print_list(BLE_GAP_ROLE_CENTRAL);
Bluefruit.Periph.clearBonds();
Bluefruit.Central.clearBonds();
#endif
didFactoryReset = true;
}
@@ -459,6 +474,9 @@ size_t NodeDB::getNumOnlineNodes()
void NodeDB::updatePosition(uint32_t nodeId, const Position &p, RxSource src)
{
NodeInfo *info = getOrCreateNode(nodeId);
if (!info) {
return;
}
if (src == RX_SRC_LOCAL) {
// Local packet, fully authoritative
@@ -502,6 +520,9 @@ void NodeDB::updatePosition(uint32_t nodeId, const Position &p, RxSource src)
void NodeDB::updateUser(uint32_t nodeId, const User &p)
{
NodeInfo *info = getOrCreateNode(nodeId);
if (!info) {
return;
}
DEBUG_MSG("old user %s/%s/%s\n", info->user.id, info->user.long_name, info->user.short_name);
@@ -531,6 +552,9 @@ void NodeDB::updateFrom(const MeshPacket &mp)
DEBUG_MSG("Update DB node 0x%x, rx_time=%u\n", mp.from, mp.rx_time);
NodeInfo *info = getOrCreateNode(getFrom(&mp));
if (!info) {
return;
}
if (mp.rx_time) // if the packet has a valid timestamp use it to update our last_heard
info->last_heard = mp.rx_time;
@@ -557,8 +581,12 @@ NodeInfo *NodeDB::getOrCreateNode(NodeNum n)
NodeInfo *info = getNode(n);
if (!info) {
if (*numNodes >= MAX_NUM_NODES) {
screen->print("error: node_db full!\n");
DEBUG_MSG("ERROR! could not create new node, node_db is full! (%d nodes)", *numNodes);
return NULL;
}
// add the node
assert(*numNodes < MAX_NUM_NODES);
info = &nodes[(*numNodes)++];
// everything is missing except the nodenum

View File

@@ -210,6 +210,33 @@ ErrorCode Router::send(MeshPacket *p)
if (p->which_payloadVariant == MeshPacket_decoded_tag) {
ChannelIndex chIndex = p->channel; // keep as a local because we are about to change it
#if defined(HAS_WIFI) || defined(PORTDUINO)
//check if we should send decrypted packets to mqtt
//truth table:
/* mqtt_server mqtt_encryption_enabled should_encrypt
* not set 0 1
* not set 1 1
* set 0 0
* set 1 1
*
* => so we only decrypt mqtt if they have a custom mqtt server AND mqtt_encryption_enabled is FALSE
*/
bool shouldActuallyEncrypt = true;
if (*radioConfig.preferences.mqtt_server && !radioConfig.preferences.mqtt_encryption_enabled) {
shouldActuallyEncrypt = false;
}
DEBUG_MSG("Should encrypt MQTT?: %d\n", shouldActuallyEncrypt);
//the packet is currently in a decrypted state. send it now if they want decrypted packets
if (mqtt && !shouldActuallyEncrypt)
mqtt->onSend(*p, chIndex);
#endif
auto encodeResult = perhapsEncode(p);
if (encodeResult != Routing_Error_NONE) {
abortSendAndNak(encodeResult, p);
@@ -217,7 +244,9 @@ ErrorCode Router::send(MeshPacket *p)
}
#if defined(HAS_WIFI) || defined(PORTDUINO)
if (mqtt)
//the packet is now encrypted.
//check if we should send encrypted packets to mqtt
if (mqtt && shouldActuallyEncrypt)
mqtt->onSend(*p, chIndex);
#endif
}
@@ -368,4 +397,4 @@ void Router::perhapsHandleReceived(MeshPacket *p)
handleReceived(p);
packetPool.release(p);
}
}

View File

@@ -145,7 +145,7 @@ extern const pb_msgdesc_t AdminMessage_msg;
#define AdminMessage_fields &AdminMessage_msg
/* Maximum encoded size of messages (where known) */
#define AdminMessage_size 798
#define AdminMessage_size 804
#ifdef __cplusplus
} /* extern "C" */

View File

@@ -97,7 +97,8 @@ typedef enum _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType {
RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT21 = 3,
RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT22 = 4,
RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME280 = 5,
RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680 = 6
RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680 = 6,
RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MCP9808 = 7
} RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType;
/* Struct definitions */
@@ -185,6 +186,7 @@ typedef struct _RadioConfig_UserPreferences {
char canned_message_plugin_messages[200];
bool canned_message_plugin_send_bell;
bool mqtt_encryption_enabled;
float adc_multiplier_override;
} RadioConfig_UserPreferences;
typedef struct _RadioConfig {
@@ -223,8 +225,8 @@ typedef struct _RadioConfig {
#define _InputEventChar_ARRAYSIZE ((InputEventChar)(InputEventChar_KEY_BACK+1))
#define _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11
#define _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MAX RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680
#define _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_ARRAYSIZE ((RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType)(RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680+1))
#define _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MAX RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MCP9808
#define _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_ARRAYSIZE ((RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType)(RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MCP9808+1))
#ifdef __cplusplus
@@ -233,9 +235,9 @@ extern "C" {
/* Initializer values for message structs */
#define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default}
#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, 0, 0, 0, 0, 0, _InputEventChar_MIN, _InputEventChar_MIN, _InputEventChar_MIN, 0, "", "", 0, 0}
#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, 0, 0, 0, 0, 0, _InputEventChar_MIN, _InputEventChar_MIN, _InputEventChar_MIN, 0, "", "", 0, 0, 0}
#define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero}
#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, 0, 0, 0, 0, 0, _InputEventChar_MIN, _InputEventChar_MIN, _InputEventChar_MIN, 0, "", "", 0, 0}
#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, 0, 0, 0, 0, 0, _InputEventChar_MIN, _InputEventChar_MIN, _InputEventChar_MIN, 0, "", "", 0, 0, 0}
/* Field tags (for use in manual encoding/decoding) */
#define RadioConfig_UserPreferences_position_broadcast_secs_tag 1
@@ -320,6 +322,7 @@ extern "C" {
#define RadioConfig_UserPreferences_canned_message_plugin_messages_tag 172
#define RadioConfig_UserPreferences_canned_message_plugin_send_bell_tag 173
#define RadioConfig_UserPreferences_mqtt_encryption_enabled_tag 174
#define RadioConfig_UserPreferences_adc_multiplier_override_tag 175
#define RadioConfig_preferences_tag 1
/* Struct field encoding specification for nanopb */
@@ -411,7 +414,8 @@ X(a, STATIC, SINGULAR, BOOL, canned_message_plugin_enabled, 170) \
X(a, STATIC, SINGULAR, STRING, canned_message_plugin_allow_input_source, 171) \
X(a, STATIC, SINGULAR, STRING, canned_message_plugin_messages, 172) \
X(a, STATIC, SINGULAR, BOOL, canned_message_plugin_send_bell, 173) \
X(a, STATIC, SINGULAR, BOOL, mqtt_encryption_enabled, 174)
X(a, STATIC, SINGULAR, BOOL, mqtt_encryption_enabled, 174) \
X(a, STATIC, SINGULAR, FLOAT, adc_multiplier_override, 175)
#define RadioConfig_UserPreferences_CALLBACK NULL
#define RadioConfig_UserPreferences_DEFAULT NULL
@@ -423,8 +427,8 @@ extern const pb_msgdesc_t RadioConfig_UserPreferences_msg;
#define RadioConfig_UserPreferences_fields &RadioConfig_UserPreferences_msg
/* Maximum encoded size of messages (where known) */
#define RadioConfig_size 795
#define RadioConfig_UserPreferences_size 792
#define RadioConfig_size 801
#define RadioConfig_UserPreferences_size 798
#ifdef __cplusplus
} /* extern "C" */

View File

@@ -5,6 +5,7 @@
#include "mesh/PhoneAPI.h"
#include "mesh/mesh-pb-constants.h"
#include <bluefruit.h>
#include <utility/bonding.h>
static BLEService meshBleService = BLEService(BLEUuid(MESH_SERVICE_UUID_16));
static BLECharacteristic fromNum = BLECharacteristic(BLEUuid(FROMNUM_UUID_16));
@@ -266,3 +267,13 @@ void updateBatteryLevel(uint8_t level)
{
blebas.write(level);
}
void NRF52Bluetooth::clearBonds()
{
DEBUG_MSG("Clearing bluetooth bonds!\n");
bond_print_list(BLE_GAP_ROLE_PERIPH);
bond_print_list(BLE_GAP_ROLE_CENTRAL);
Bluefruit.Periph.clearBonds();
Bluefruit.Central.clearBonds();
}

View File

@@ -5,5 +5,6 @@ class NRF52Bluetooth
public:
void setup();
void shutdown();
void clearBonds();
};

View File

@@ -75,7 +75,7 @@ void setBluetoothEnable(bool on)
else {
nrf52Bluetooth = new NRF52Bluetooth();
nrf52Bluetooth->setup();
// We delay brownout init until after BLE because BLE starts soft device
initBrownout();
}
@@ -185,4 +185,12 @@ void cpuDeepSleep(uint64_t msecToWake)
delay(5000);
DEBUG_MSG(".");
}
}
void clearBonds() {
if (!nrf52Bluetooth) {
nrf52Bluetooth = new NRF52Bluetooth();
nrf52Bluetooth->setup();
}
nrf52Bluetooth->clearBonds();
}

View File

@@ -6,19 +6,22 @@
#include "Router.h"
#include "configuration.h"
#include "main.h"
#include <DHT.h>
#include <DS18B20.h>
#include <OLEDDisplay.h>
#include <OLEDDisplayUi.h>
#include <OneWire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Adafruit_BME680.h>
#define DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
#define DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
#define DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
#define BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
// Sensors
#include "Sensor/BME280Sensor.h"
#include "Sensor/BME680Sensor.h"
#include "Sensor/DHTSensor.h"
#include "Sensor/DallasSensor.h"
#include "Sensor/MCP9808Sensor.h"
BME280Sensor bme280Sensor;
BME680Sensor bme680Sensor;
DHTSensor dhtSensor;
DallasSensor dallasSensor;
MCP9808Sensor mcp9808Sensor;
#define FAILED_STATE_SENSOR_READ_MULTIPLIER 10
#define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true
@@ -38,6 +41,7 @@
#define FONT_HEIGHT_SMALL fontHeight(FONT_SMALL)
#define FONT_HEIGHT_MEDIUM fontHeight(FONT_MEDIUM)
int32_t EnvironmentalMeasurementPlugin::runOnce()
{
#ifndef PORTDUINO
@@ -45,8 +49,8 @@ int32_t EnvironmentalMeasurementPlugin::runOnce()
Uncomment the preferences below if you want to use the plugin
without having to configure it from the PythonAPI or WebUI.
*/
/*radioConfig.preferences.environmental_measurement_plugin_measurement_enabled = 1;
/*
radioConfig.preferences.environmental_measurement_plugin_measurement_enabled = 1;
radioConfig.preferences.environmental_measurement_plugin_screen_enabled = 1;
radioConfig.preferences.environmental_measurement_plugin_read_error_count_threshold = 5;
radioConfig.preferences.environmental_measurement_plugin_update_interval = 600;
@@ -75,72 +79,30 @@ int32_t EnvironmentalMeasurementPlugin::runOnce()
// therefore, we should only enable the sensor loop if measurement is also enabled
switch (radioConfig.preferences.environmental_measurement_plugin_sensor_type) {
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT12:
dht = new DHT(radioConfig.preferences.environmental_measurement_plugin_sensor_pin, DHT11);
this->dht->begin();
this->dht->read();
DEBUG_MSG("EnvironmentalMeasurement: Opened DHT11/DHT12 on pin: %d\n",
radioConfig.preferences.environmental_measurement_plugin_sensor_pin);
return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DS18B20:
oneWire = new OneWire(radioConfig.preferences.environmental_measurement_plugin_sensor_pin);
ds18b20 = new DS18B20(oneWire);
this->ds18b20->begin();
this->ds18b20->setResolution(12);
this->ds18b20->requestTemperatures();
DEBUG_MSG("EnvironmentalMeasurement: Opened DS18B20 on pin: %d\n",
radioConfig.preferences.environmental_measurement_plugin_sensor_pin);
return (DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT21:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT22:
dht = new DHT(radioConfig.preferences.environmental_measurement_plugin_sensor_pin, DHT22);
this->dht->begin();
this->dht->read();
DEBUG_MSG("EnvironmentalMeasurement: Opened DHT21/DHT22 on pin: %d\n",
radioConfig.preferences.environmental_measurement_plugin_sensor_pin);
return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME280:
unsigned bme280Status;
// Default i2c address for BME280
bme280Status = bme280.begin(0x76);
if (!bme280Status) {
DEBUG_MSG("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
// TODO more verbose diagnostics
} else {
DEBUG_MSG("EnvironmentalMeasurement: Opened BME280 on default i2c bus");
}
return (BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680:
unsigned bme680Status;
// Default i2c address for BME280
bme680Status = bme680.begin(0x76);
if (!bme680Status) {
DEBUG_MSG("Could not find a valid BME680 sensor, check wiring, address, sensor ID!");
// TODO more verbose diagnostics
} else {
DEBUG_MSG("EnvironmentalMeasurement: Opened BME680 on default i2c bus");
// Set up oversampling and filter initialization
bme680.setTemperatureOversampling(BME680_OS_8X);
bme680.setHumidityOversampling(BME680_OS_2X);
bme680.setPressureOversampling(BME680_OS_4X);
bme680.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme680.setGasHeater(320, 150); // 320*C for 150 ms
}
return (BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
default:
DEBUG_MSG("EnvironmentalMeasurement: Invalid sensor type selected; Disabling plugin");
return (INT32_MAX);
break;
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT12:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT21:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT22:
return dhtSensor.runOnce();
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DS18B20:
return dallasSensor.runOnce();
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME280:
return bme280Sensor.runOnce();
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680:
return bme680Sensor.runOnce();
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MCP9808:
return mcp9808Sensor.runOnce();
default:
DEBUG_MSG("EnvironmentalMeasurement: Invalid sensor type selected; Disabling plugin");
return (INT32_MAX);
break;
}
}
return (INT32_MAX);
} else {
if (!radioConfig.preferences.environmental_measurement_plugin_measurement_enabled) {
// if we somehow got to a second run of this plugin with measurement disabled, then just wait forever
// I can't imagine we'd ever get here though.
// if we somehow got to a second run of this plugin with measurement disabled, then just wait forever
if (!radioConfig.preferences.environmental_measurement_plugin_measurement_enabled)
return (INT32_MAX);
}
// this is not the first time OSThread library has called this function
// so just do what we intend to do on the interval
if (sensor_read_error_count > radioConfig.preferences.environmental_measurement_plugin_read_error_count_threshold) {
@@ -167,22 +129,22 @@ int32_t EnvironmentalMeasurementPlugin::runOnce()
if (!sendOurEnvironmentalMeasurement()) {
// if we failed to read the sensor, then try again
// as soon as we can according to the maximum polling frequency
// return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
switch (radioConfig.preferences.environmental_measurement_plugin_sensor_type) {
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT12:
return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DS18B20:
return (DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT21:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT22:
return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME280:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680:
return (BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
default:
return (DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT12:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT21:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT22:
return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DS18B20:
return (DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME280:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680:
return (BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MCP9808:
return (MCP_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
default:
return (DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
}
}
}
@@ -256,7 +218,6 @@ void EnvironmentalMeasurementPlugin::drawFrame(OLEDDisplay *display, OLEDDisplay
String last_temp = String(lastMeasurement.temperature, 0) + "°C";
if (radioConfig.preferences.environmental_measurement_plugin_display_farenheit) {
last_temp = String(CelsiusToFarenheit(lastMeasurement.temperature), 0) + "°F";
;
}
display->drawString(x, y += fontHeight(FONT_MEDIUM) - 2, "From: " + lastSender + "(" + String(agoSecs) + "s)");
display->drawString(x, y += fontHeight(FONT_SMALL) - 2,"Temp/Hum: " + last_temp + " / " + String(lastMeasurement.relative_humidity, 0) + "%");
@@ -278,6 +239,7 @@ bool EnvironmentalMeasurementPlugin::handleReceivedProtobuf(const MeshPacket &mp
DEBUG_MSG("EnvironmentalMeasurement->relative_humidity: %f\n", p->relative_humidity);
DEBUG_MSG("EnvironmentalMeasurement->temperature: %f\n", p->temperature);
DEBUG_MSG("EnvironmentalMeasurement->barometric_pressure: %f\n", p->barometric_pressure);
DEBUG_MSG("EnvironmentalMeasurement->gas_resistance: %f\n", p->gas_resistance);
lastMeasurementPacket = packetPool.allocCopy(mp);
@@ -287,62 +249,42 @@ bool EnvironmentalMeasurementPlugin::handleReceivedProtobuf(const MeshPacket &mp
bool EnvironmentalMeasurementPlugin::sendOurEnvironmentalMeasurement(NodeNum dest, bool wantReplies)
{
EnvironmentalMeasurement m;
m.barometric_pressure = 0; // TODO: Add support for barometric sensors
m.barometric_pressure = 0;
m.gas_resistance = 0;
DEBUG_MSG("-----------------------------------------\n");
DEBUG_MSG("EnvironmentalMeasurement: Read data\n");
switch (radioConfig.preferences.environmental_measurement_plugin_sensor_type) {
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT12:
if (!this->dht->read(true)) {
sensor_read_error_count++;
DEBUG_MSG("EnvironmentalMeasurement: FAILED TO READ DATA\n");
return false;
}
m.relative_humidity = this->dht->readHumidity();
m.temperature = this->dht->readTemperature();
break;
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DS18B20:
if (this->ds18b20->isConversionComplete()) {
m.temperature = this->ds18b20->getTempC();
m.relative_humidity = 0; // This sensor is temperature only
this->ds18b20->requestTemperatures();
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DS18B20:
if (!dallasSensor.getMeasurement(&m))
sensor_read_error_count++;
break;
} else {
sensor_read_error_count++;
DEBUG_MSG("EnvironmentalMeasurement: FAILED TO READ DATA\n");
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT12:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT21:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT22:
if (!dhtSensor.getMeasurement(&m))
sensor_read_error_count++;
break;
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME280:
bme280Sensor.getMeasurement(&m);
break;
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680:
bme680Sensor.getMeasurement(&m);
break;
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MCP9808:
mcp9808Sensor.getMeasurement(&m);
break;
default:
DEBUG_MSG("EnvironmentalMeasurement: Invalid sensor type selected; Disabling plugin");
return false;
}
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT21:
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT22:
if (!this->dht->read(true)) {
sensor_read_error_count++;
DEBUG_MSG("EnvironmentalMeasurement: FAILED TO READ DATA\n");
return false;
}
m.relative_humidity = this->dht->readHumidity();
m.temperature = this->dht->readTemperature();
break;
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME280:
m.temperature = bme280.readTemperature();
m.relative_humidity = bme280.readHumidity();
m.barometric_pressure = bme280.readPressure() / 100.0F;
break;
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680:
m.temperature = bme680.readTemperature();
m.relative_humidity = bme680.readHumidity();
m.barometric_pressure = bme680.readPressure() / 100.0F;
break;
default:
DEBUG_MSG("EnvironmentalMeasurement: Invalid sensor type selected; Disabling plugin");
return false;
}
DEBUG_MSG("EnvironmentalMeasurement->relative_humidity: %f\n", m.relative_humidity);
DEBUG_MSG("EnvironmentalMeasurement->temperature: %f\n", m.temperature);
DEBUG_MSG("EnvironmentalMeasurement->barometric_pressure: %f\n", m.barometric_pressure);
DEBUG_MSG("EnvironmentalMeasurement->gas_resistance: %f\n", m.gas_resistance);
sensor_read_error_count = 0;

View File

@@ -1,14 +1,8 @@
#pragma once
#include "../mesh/generated/environmental_measurement.pb.h"
#include "ProtobufPlugin.h"
#include <DHT.h>
#include <DS18B20.h>
#include <OLEDDisplay.h>
#include <OLEDDisplayUi.h>
#include <OneWire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Adafruit_BME680.h>
class EnvironmentalMeasurementPlugin : private concurrency::OSThread, public ProtobufPlugin<EnvironmentalMeasurement>
{
@@ -36,11 +30,6 @@ class EnvironmentalMeasurementPlugin : private concurrency::OSThread, public Pro
private:
float CelsiusToFarenheit(float c);
bool firstTime = 1;
DHT *dht = NULL;
OneWire *oneWire = NULL;
DS18B20 *ds18b20 = NULL;
Adafruit_BME280 bme280;
Adafruit_BME680 bme680;
const MeshPacket *lastMeasurementPacket;
uint32_t sensor_read_error_count = 0;
};

View File

@@ -0,0 +1,29 @@
#include "../mesh/generated/environmental_measurement.pb.h"
#include "configuration.h"
#include "EnvironmentalMeasurementSensor.h"
#include "BME280Sensor.h"
#include <Adafruit_BME280.h>
BME280Sensor::BME280Sensor() : EnvironmentalMeasurementSensor {} {
}
int32_t BME280Sensor::runOnce() {
unsigned bme280Status;
// Default i2c address for BME280
bme280Status = bme280.begin(0x76);
if (!bme280Status) {
DEBUG_MSG("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
// TODO more verbose diagnostics
} else {
DEBUG_MSG("EnvironmentalMeasurement: Opened BME280 on default i2c bus");
}
return BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
}
bool BME280Sensor::getMeasurement(EnvironmentalMeasurement *measurement) {
measurement->temperature = bme280.readTemperature();
measurement->relative_humidity = bme280.readHumidity();
measurement->barometric_pressure = bme280.readPressure() / 100.0F;
return true;
}

View File

@@ -0,0 +1,15 @@
#include "../mesh/generated/environmental_measurement.pb.h"
#include "EnvironmentalMeasurementSensor.h"
#include <Adafruit_BME280.h>
#define BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
class BME280Sensor : virtual public EnvironmentalMeasurementSensor {
private:
Adafruit_BME280 bme280;
public:
BME280Sensor();
virtual int32_t runOnce() override;
virtual bool getMeasurement(EnvironmentalMeasurement *measurement) override;
};

View File

@@ -0,0 +1,36 @@
#include "../mesh/generated/environmental_measurement.pb.h"
#include "configuration.h"
#include "EnvironmentalMeasurementSensor.h"
#include "BME680Sensor.h"
#include <Adafruit_BME680.h>
BME680Sensor::BME680Sensor() : EnvironmentalMeasurementSensor {} {
}
int32_t BME680Sensor::runOnce() {
unsigned bme680Status;
// Default i2c address for BME680
bme680Status = bme680.begin(0x76);
if (!bme680Status) {
DEBUG_MSG("Could not find a valid BME680 sensor, check wiring, address, sensor ID!");
// TODO more verbose diagnosticsEnvironmentalMeasurementSensor
} else {
DEBUG_MSG("EnvironmentalMeasurement: Opened BME680 on default i2c bus");
// Set up oversampling and filter initialization
bme680.setTemperatureOversampling(BME680_OS_8X);
bme680.setHumidityOversampling(BME680_OS_2X);
bme680.setPressureOversampling(BME680_OS_4X);
bme680.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme680.setGasHeater(320, 150); // 320*C for 150 ms
}
return (BME_680_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
}
bool BME680Sensor::getMeasurement(EnvironmentalMeasurement *measurement) {
measurement->temperature = bme680.readTemperature();
measurement->relative_humidity = bme680.readHumidity();
measurement->barometric_pressure = bme680.readPressure() / 100.0F;
measurement->gas_resistance = bme680.readGas() / 1000.0;
return true;
}

View File

@@ -0,0 +1,15 @@
#include "../mesh/generated/environmental_measurement.pb.h"
#include "EnvironmentalMeasurementSensor.h"
#include <Adafruit_BME680.h>
#define BME_680_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
class BME680Sensor : virtual public EnvironmentalMeasurementSensor {
private:
Adafruit_BME680 bme680;
public:
BME680Sensor();
virtual int32_t runOnce() override;
virtual bool getMeasurement(EnvironmentalMeasurement *measurement) override;
};

View File

@@ -0,0 +1,36 @@
#include "../mesh/generated/environmental_measurement.pb.h"
#include "configuration.h"
#include "MeshService.h"
#include "EnvironmentalMeasurementSensor.h"
#include "DHTSensor.h"
#include <DHT.h>
DHTSensor::DHTSensor() : EnvironmentalMeasurementSensor {} {
}
int32_t DHTSensor::runOnce() {
if (RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11 ||
RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT12) {
dht = new DHT(radioConfig.preferences.environmental_measurement_plugin_sensor_pin, DHT11);
}
else {
dht = new DHT(radioConfig.preferences.environmental_measurement_plugin_sensor_pin, DHT22);
}
dht->begin();
dht->read();
DEBUG_MSG("EnvironmentalMeasurement: Opened DHT11/DHT12 on pin: %d\n",
radioConfig.preferences.environmental_measurement_plugin_sensor_pin);
return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
}
bool DHTSensor::getMeasurement(EnvironmentalMeasurement *measurement) {
if (!dht->read(true)) {
DEBUG_MSG("EnvironmentalMeasurement: FAILED TO READ DATA\n");
return false;
}
measurement->relative_humidity = dht->readHumidity();
measurement->temperature = dht->readTemperature();
return true;
}

View File

@@ -0,0 +1,15 @@
#include "../mesh/generated/environmental_measurement.pb.h"
#include "EnvironmentalMeasurementSensor.h"
#include <DHT.h>
#define DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
class DHTSensor : virtual public EnvironmentalMeasurementSensor {
private:
DHT *dht = NULL;
public:
DHTSensor();
virtual int32_t runOnce() override;
virtual bool getMeasurement(EnvironmentalMeasurement *measurement) override;
};

View File

@@ -0,0 +1,31 @@
#include "../mesh/generated/environmental_measurement.pb.h"
#include "configuration.h"
#include "MeshService.h"
#include "EnvironmentalMeasurementSensor.h"
#include "DallasSensor.h"
#include <DS18B20.h>
#include <OneWire.h>
DallasSensor::DallasSensor() : EnvironmentalMeasurementSensor {} {
}
int32_t DallasSensor::runOnce() {
oneWire = new OneWire(radioConfig.preferences.environmental_measurement_plugin_sensor_pin);
ds18b20 = new DS18B20(oneWire);
ds18b20->begin();
ds18b20->setResolution(12);
ds18b20->requestTemperatures();
DEBUG_MSG("EnvironmentalMeasurement: Opened DS18B20 on pin: %d\n",
radioConfig.preferences.environmental_measurement_plugin_sensor_pin);
return (DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
}
bool DallasSensor::getMeasurement(EnvironmentalMeasurement *measurement) {
if (ds18b20->isConversionComplete()) {
measurement->temperature = ds18b20->getTempC();
measurement->relative_humidity = 0;
ds18b20->requestTemperatures();
return true;
}
return false;
}

View File

@@ -0,0 +1,17 @@
#include "../mesh/generated/environmental_measurement.pb.h"
#include "EnvironmentalMeasurementSensor.h"
#include <DS18B20.h>
#include <OneWire.h>
#define DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
class DallasSensor : virtual public EnvironmentalMeasurementSensor {
private:
OneWire *oneWire = NULL;
DS18B20 *ds18b20 = NULL;
public:
DallasSensor();
virtual int32_t runOnce() override;
virtual bool getMeasurement(EnvironmentalMeasurement *measurement) override;
};

View File

@@ -0,0 +1,12 @@
#pragma once
#include "../mesh/generated/environmental_measurement.pb.h"
#define DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
class EnvironmentalMeasurementSensor {
protected:
EnvironmentalMeasurementSensor() { }
public:
virtual int32_t runOnce() = 0;
virtual bool getMeasurement(EnvironmentalMeasurement *measurement) = 0;
};

View File

@@ -0,0 +1,28 @@
#include "../mesh/generated/environmental_measurement.pb.h"
#include "configuration.h"
#include "EnvironmentalMeasurementSensor.h"
#include "MCP9808Sensor.h"
#include <Adafruit_MCP9808.h>
MCP9808Sensor::MCP9808Sensor() : EnvironmentalMeasurementSensor {} {
}
int32_t MCP9808Sensor::runOnce() {
unsigned mcp9808Status;
// Default i2c address for MCP9808
mcp9808Status = mcp9808.begin(0x18);
if (!mcp9808Status) {
DEBUG_MSG("Could not find a valid MCP9808 sensor, check wiring, address, sensor ID!");
} else {
DEBUG_MSG("EnvironmentalMeasurement: Opened MCP9808 on default i2c bus");
// Reduce resolution from 0.0625 degrees (precision) to 0.125 degrees (high).
mcp9808.setResolution(2);
}
return (MCP_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
}
bool MCP9808Sensor::getMeasurement(EnvironmentalMeasurement *measurement) {
measurement->temperature = mcp9808.readTempC();
return true;
}

View File

@@ -0,0 +1,15 @@
#include "../mesh/generated/environmental_measurement.pb.h"
#include "EnvironmentalMeasurementSensor.h"
#include <Adafruit_MCP9808.h>
#define MCP_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
class MCP9808Sensor : virtual public EnvironmentalMeasurementSensor {
private:
Adafruit_MCP9808 mcp9808;
public:
MCP9808Sensor();
virtual int32_t runOnce() override;
virtual bool getMeasurement(EnvironmentalMeasurement *measurement) override;
};

View File

@@ -12,7 +12,7 @@
#include "plugins/AdminPlugin.h"
#include "plugins/CannedMessagePlugin.h"
#ifndef PORTDUINO
#include "plugins/EnvironmentalMeasurementPlugin.h"
#include "plugins/EnvironmentalMeasurement/EnvironmentalMeasurementPlugin.h"
#endif
#ifndef NO_ESP32
#include "plugins/esp32/SerialPlugin.h"

View File

@@ -1,3 +1,13 @@
; Meshtastic DIY v1 by Nano VHF Schematic based on ESP32-WROOM-32 (38 pins) devkit & EBYTE E22 SX1262/SX1268 module
[env:meshtastic-diy-v1]
extends = esp32_base
board = esp32doit-devkit-v1
build_flags =
${esp32_base.build_flags}
-D DIY_V1
-D EBYTE_E22
-I variants/diy/v1
; Meshtastic DIY v1.1 new schematic based on ESP32-WROOM-32 & SX1262/SX1268 modules
[env:meshtastic-diy-v1.1]
extends = esp32_base

View File

@@ -24,8 +24,7 @@
#define LORA_DIO1 35 // Not really used
#define LORA_DIO2 34 // Not really used
// ratio of voltage divider = 3.20 (schematic R12=100k, R10=220k)
// device to device variations, the actual ratio can be between 3.2 and 4
#define ADC_MULTIPLIER 3.6 // best fit
#define ADC_MULTIPLIER 3.8
#define BATTERY_PIN 37 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage
#define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Plugin.

View File

@@ -1,9 +0,0 @@
; Meshtastic DIY v1 by Nano VHF Schematic based on ESP32-WROOM-32 (38 pins) devkit & EBYTE E22 SX1262/SX1268 module
[env:meshtastic-diy-v1]
extends = esp32_base
board = esp32doit-devkit-v1
build_flags =
${esp32_base.build_flags}
-D DIY_V1
-D EBYTE_E22
-I variants/meshtastic_diy_v1

View File

@@ -8,7 +8,7 @@ src_filter =
-<nrf52/>
-<mesh/http/>
-<plugins/esp32>
-<plugins/EnvironmentalMeasurementPlugin.cpp*>
-<plugins/EnvironmentalMeasurement>
+<../variants/portduino>
build_flags = ${arduino_base.build_flags} -O0 -I variants/portduino
framework = arduino
@@ -27,7 +27,7 @@ src_filter =
-<nrf52/>
-<mesh/http/>
-<plugins/esp32>
-<plugins/EnvironmentalMeasurementPlugin.cpp*>
-<plugins/EnvironmentalMeasurement>
+<../variants/portduino>
build_flags = ${arduino_base.build_flags} -O0 -lgpiod -I variants/portduino
framework = arduino

View File

@@ -0,0 +1,46 @@
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <stdint.h>
#define EXTERNAL_NUM_INTERRUPTS 16
#define NUM_DIGITAL_PINS 40
#define NUM_ANALOG_INPUTS 16
#define analogInputToDigitalPin(p) (((p) < 20) ? (esp32_adc2gpio[(p)]) : -1)
#define digitalPinToInterrupt(p) (((p) < 40) ? (p) : -1)
#define digitalPinHasPWM(p) (p < 34)
#define LED_GREEN 12
#define LED_BLUE 2
#define LED_BUILTIN LED_GREEN
static const uint8_t TX = 1;
static const uint8_t RX = 3;
#define TX1 21
#define RX1 19
#define WB_IO1 14
#define WB_IO2 27
#define WB_IO3 26
#define WB_IO4 23
#define WB_IO5 13
#define WB_IO6 22
#define WB_SW1 34
#define WB_A0 36
#define WB_A1 39
#define WB_CS 32
#define WB_LED1 12
#define WB_LED2 2
static const uint8_t SDA = 4;
static const uint8_t SCL = 5;
static const uint8_t SS = 32;
static const uint8_t MOSI = 25;
static const uint8_t MISO = 35;
static const uint8_t SCK = 33;
#endif /* Pins_Arduino_h */

View File

@@ -0,0 +1,5 @@
[env:rak11200]
extends = esp32_base
board = wiscore_rak11200
build_flags =
${esp32_base.build_flags} -D RAK_11200 -I variants/rak11200

View File

@@ -0,0 +1,84 @@
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <stdint.h>
#define EXTERNAL_NUM_INTERRUPTS 16
#define NUM_DIGITAL_PINS 40
#define NUM_ANALOG_INPUTS 16
#define analogInputToDigitalPin(p) (((p) < 20) ? (esp32_adc2gpio[(p)]) : -1)
#define digitalPinToInterrupt(p) (((p) < 40) ? (p) : -1)
#define digitalPinHasPWM(p) (p < 34)
#define LED_GREEN 12
#define LED_BLUE 2
#define LED_BUILTIN LED_GREEN
static const uint8_t TX = 1;
static const uint8_t RX = 3;
#define TX1 21
#define RX1 19
#define WB_IO1 14
#define WB_IO2 27
#define WB_IO3 26
#define WB_IO4 23
#define WB_IO5 13
#define WB_IO6 22
#define WB_SW1 34
#define WB_A0 36
#define WB_A1 39
#define WB_CS 32
#define WB_LED1 12
#define WB_LED2 2
static const uint8_t SDA = 4;
static const uint8_t SCL = 5;
static const uint8_t SS = 32;
static const uint8_t MOSI = 25;
static const uint8_t MISO = 35;
static const uint8_t SCK = 33;
#endif /* Pins_Arduino_h */
/* -------- Meshtastic pins -------- */
#define I2C_SDA SDA
#define I2C_SCL SCL
#undef GPS_RX_PIN
#define GPS_RX_PIN (RX1)
#undef GPS_TX_PIN
#define GPS_TX_PIN (TX1)
#define LED_PIN LED_BLUE
#define PIN_VBAT WB_A0
// https://docs.rakwireless.com/Product-Categories/WisBlock/RAK13300/
#define LORA_DIO0 26 // a No connect on the SX1262/SX1268 module
#define LORA_RESET WB_IO4 // RST for SX1276, and for SX1262/SX1268
#define LORA_DIO1 WB_IO6 // IRQ for SX1262/SX1268
#define LORA_DIO2 WB_IO5 // BUSY for SX1262/SX1268
#define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262/SX1268, if DIO3 is high the TXCO is enabled
#undef RF95_SCK
#define RF95_SCK SCK
#undef RF95_MISO
#define RF95_MISO MISO
#undef RF95_MOSI
#define RF95_MOSI MOSI
#undef RF95_NSS
#define RF95_NSS SS
#define USE_SX1262
#define SX126X_CS (SS)// NSS for SX126X
#define SX126X_DIO1 (LORA_DIO1)
#define SX126X_BUSY (LORA_DIO2)
#define SX126X_RESET (LORA_RESET)
#define SX126X_TXEN (-1)
#define SX126X_RXEN (WB_IO3)
#define SX126X_E22 // DIO2 controlls an antenna switch and the TCXO voltage is controlled by DIO3

View File

@@ -1,4 +1,4 @@
[VERSION]
major = 1
minor = 2
build = 53
build = 55