Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ Here are some general principals you should try to adhere to:

There are a number of fairly major features in the pipeline, with no particular time-frames attached yet. In very rough chronological order:
- [X] Companion radio: UI redesign
- [ ] Repeater + Room Server: add ACL's (like Sensor Node has)
- [ ] Standardise Bridge mode for repeaters
- [X] Repeater + Room Server: add ACL's (like Sensor Node has)
- [X] Standardise Bridge mode for repeaters
- [ ] Repeater/Bridge: Standardise the Transport Codes for zoning/filtering
- [ ] Core + Repeater: enhanced zero-hop neighbour discovery
- [X] Core + Repeater: enhanced zero-hop neighbour discovery
- [ ] Core: round-trip manual path support
- [ ] Companion + Apps: support for multiple sub-meshes (and 'off-grid' client repeat mode)
- [ ] Core + Apps: support for LZW message compression
Expand All @@ -113,12 +113,3 @@ There are a number of fairly major features in the pipeline, with no particular
- Report bugs and request features on the [GitHub Issues](https://github.com/ripplebiz/MeshCore/issues) page.
- Find additional guides and components on [my site](https://buymeacoffee.com/ripplebiz).
- Join [MeshCore Discord](https://discord.gg/BMwCtwHj5V) to chat with the developers and get help from the community.

## RAK Wireless Board Support in PlatformIO

Before building/flashing the RAK4631 targets in this project, there is, unfortunately, some patching you have to do to your platformIO packages to make it work. There is a guide here on the process:
[RAK Wireless: How to Perform Installation of Board Support Package in PlatformIO](https://learn.rakwireless.com/hc/en-us/articles/26687276346775-How-To-Perform-Installation-of-Board-Support-Package-in-PlatformIO)

After building, you will need to convert the output firmware.hex file into a .uf2 file you can copy over to your RAK4631 device (after doing a full erase) by using the command `uf2conv.py -f 0xADA52840 -c firmware.hex` with the python script available from:
[GitHub: Microsoft - uf2](https://github.com/Microsoft/uf2/blob/master/utils/uf2conv.py)

229 changes: 121 additions & 108 deletions docs/faq.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/payloads.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,4 @@ The plaintext contained in the ciphertext matches the format described in [plain

# Custom packet

Custom packets have no defined format.
Custom packets have no defined format.
2 changes: 1 addition & 1 deletion examples/simple_room_server/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ void MyMesh::loop() {
if (c->extra.room.pending_ack && millisHasNowPassed(c->extra.room.ack_timeout)) {
c->extra.room.push_failures++;
c->extra.room.pending_ack = 0; // reset (TODO: keep prev expected_ack's in a list, incase they arrive LATER, after we retry)
MESH_DEBUG_PRINTLN("pending ACK timed out: push_failures: %d", (uint32_t)c->push_failures);
MESH_DEBUG_PRINTLN("pending ACK timed out: push_failures: %d", (uint32_t)c->extra.room.push_failures);
}
}
// check next Round-Robin client, and sync next new post
Expand Down
50 changes: 50 additions & 0 deletions variants/arduino_nesso_n1/ArduinoNessoN1Board.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "ArduinoNessoN1Board.h"
#include <Arduino.h>

void ArduinoNessoN1Board::begin() {
ESP32Board::begin();

#ifdef MESH_DEBUG
// delay for 2s after boot to ensure early output below makes it to the serial logger
delay(2000);
#endif

#ifdef P_LORA_TX_LED
MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): setup TX LED mode");
pinMode(P_LORA_TX_LED, OUTPUT);
digitalWrite(P_LORA_TX_LED, HIGH);
#endif

battery.enableCharge();

MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): set Nesso N1 pin modes and default states...");
pinMode(LORA_ENABLE, OUTPUT); // RESET
pinMode(LORA_ANTENNA_SWITCH, OUTPUT); // ANTENNA_SWITCH
pinMode(LORA_LNA_ENABLE, OUTPUT); // LNA_ENABLE
pinMode(LCD_BACKLIGHT, OUTPUT);
pinMode(BEEP_PIN, OUTPUT);

// Toggle LoRa reset via expander
MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): Enable LoRa...");
digitalWrite(LORA_ENABLE, LOW);
delay(10);
digitalWrite(LORA_ENABLE, HIGH);

// Configure antenna switch and LNA
digitalWrite(LORA_ANTENNA_SWITCH, HIGH); // enable antenna switch
digitalWrite(LORA_LNA_ENABLE, HIGH); // enable LNA

// Configure initial state of further devices on expander
MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): Set LCD_BACKLIGHT and BEEP_PIN to low initial state...");
digitalWrite(LCD_BACKLIGHT, LOW);
digitalWrite(BEEP_PIN, LOW);

// Toggle LCD backlight to show the device has powered on until we get the screen working
MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): Now high...");
digitalWrite(LCD_BACKLIGHT, HIGH);
digitalWrite(BEEP_PIN, HIGH);
delay(2000);
digitalWrite(LCD_BACKLIGHT, LOW);
digitalWrite(BEEP_PIN, LOW);
MESH_DEBUG_PRINTLN("ArduinoNessoN1.begin(): Now low...");
}
44 changes: 44 additions & 0 deletions variants/arduino_nesso_n1/ArduinoNessoN1Board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include <Arduino.h>
#include <MeshCore.h>
#include <helpers/ESP32Board.h>
#include "pins_arduino.h"

#define P_LORA_TX_LED LED_BUILTIN // defined in pins_arduino.h / expander.cpp through pin handling functions specific to the IO expander
// #define PIN_TFT_RST LCD_RESET
// #define PIN_TFT_LEDA_CTL LCD_BACKLIGHT

class ArduinoNessoN1Board : public ESP32Board {
private:
NessoBattery battery;

public:
void begin(); // Defined in ArduinoNessoN1Board.cpp

#ifdef P_LORA_TX_LED
void onBeforeTransmit() override {
MESH_DEBUG_PRINTLN("onBeforeTransmit: LOW LED for On");
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED on
}
void onAfterTransmit() override {
MESH_DEBUG_PRINTLN("onBeforeTransmit: HIGH LED for Off");
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED off
}
#endif

const char* getManufacturerName() const override {
return "Arduino Nesso N1";
}

uint16_t getBattMilliVolts() override {
return battery.getMilliVoltage();
}

void reboot() override {
MESH_DEBUG_PRINTLN("ArduinoNessoN1.reboot(): noop() instead");
// esp_restart();
}
};


157 changes: 157 additions & 0 deletions variants/arduino_nesso_n1/expander.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#pragma once
// Based off here https://github.com/espressif/arduino-esp32/blob/d1eb62d7c6dda16c254c374504aa93188d7c386b/variants/arduino_nesso_n1/expander.cpp
// Should be OK based on this? https://opensource.stackexchange.com/a/6406

#include "pins_arduino.h"
#include <helpers/ESP32Board.h>
#include <Wire.h>

static bool wireInitialized = true; // initialised in ESP32Board.begin() ; ToDo: Remove all these conditions in future
static bool expanderInitialized = false;

// From https://www.diodes.com/datasheet/download/PI4IOE5V6408.pdf
static void writeRegister(uint8_t address, uint8_t reg, uint8_t value) {
Wire.beginTransmission(address);
Wire.write(reg);
Wire.write(value);
Wire.endTransmission();
}

static uint8_t readRegister(uint8_t address, uint8_t reg) {
Wire.beginTransmission(address);
Wire.write(reg);
Wire.endTransmission(false);
Wire.requestFrom(address, 1);
return Wire.read();
}

static void writeBitRegister(uint8_t address, uint8_t reg, uint8_t bit, uint8_t value) {
MESH_DEBUG_PRINTLN("ExpanderPin writeBitRegister(address=%u, reg=%u, bit=%u, value=%u)", address, reg, bit, value);
uint8_t val = readRegister(address, reg);
if (value) {
writeRegister(address, reg, val | (1 << bit));
} else {
writeRegister(address, reg, val & ~(1 << bit));
}
}

static bool readBitRegister(uint8_t address, uint8_t reg, uint8_t bit) {
MESH_DEBUG_PRINTLN("ExpanderPin readBitRegister(address=%u, reg=%u, bit=%u)", address, reg, bit);
uint8_t val = readRegister(address, reg);
return ((val & (1 << bit)) > 0);
}

void pinMode(ExpanderPin pin, uint8_t mode) {
if (!wireInitialized) {
Wire.begin(SDA, SCL);
wireInitialized = true;
// reset all registers to default state
}
if (!expanderInitialized) {
writeRegister(pin.address, 0x1, 0x1);
// set all pins as high as default state
writeRegister(pin.address, 0x9, 0xFF);
// interrupt mask to all pins
writeRegister(pin.address, 0x11, 0xFF);
// all input
writeRegister(pin.address, 0x3, 0);
expanderInitialized = true;
}
MESH_DEBUG_PRINTLN("ExpanderPin pinMode(pin=%u, mode=%u)", pin.pin, mode);
writeBitRegister(pin.address, 0x3, pin.pin, mode == OUTPUT);
if (mode == OUTPUT) {
// remove high impedance
writeBitRegister(pin.address, 0x7, pin.pin, false);
} else if (mode == INPUT_PULLUP) {
// set pull-up resistor
writeBitRegister(pin.address, 0xB, pin.pin, true);
writeBitRegister(pin.address, 0xD, pin.pin, true);
} else if (mode == INPUT_PULLDOWN) {
// disable pull-up resistor
writeBitRegister(pin.address, 0xB, pin.pin, true);
writeBitRegister(pin.address, 0xD, pin.pin, false);
} else if (mode == INPUT) {
// disable pull selector resistor
writeBitRegister(pin.address, 0xB, pin.pin, false);
}
}

void digitalWrite(ExpanderPin pin, uint8_t val) {
if (!wireInitialized) {
Wire.begin(SDA, SCL);
wireInitialized = true;
}
MESH_DEBUG_PRINTLN("ExpanderPin digitalWrite(%u)", pin.pin);
writeBitRegister(pin.address, 0x5, pin.pin, val == HIGH);
}

int digitalRead(ExpanderPin pin) {
if (!wireInitialized) {
Wire.begin(SDA, SCL);
wireInitialized = true;
}
MESH_DEBUG_PRINTLN("ExpanderPin digitalRead(%u)", pin.pin);
return readBitRegister(pin.address, 0xF, pin.pin);
}

void NessoBattery::enableCharge() {
// AW32001E - address 0x49
// set CEB bit low (charge enable)
if (!wireInitialized) {
Wire.begin(SDA, SCL);
wireInitialized = true;
}

MESH_DEBUG_PRINTLN("NessoBattery::enableCharge()");
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current charge level %u %%", NessoBattery::getChargeLevel());
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current voltage %f V", NessoBattery::getVoltage());
MESH_DEBUG_PRINTLN("NessoBattery::enableCharge(): Current voltage %u mV", NessoBattery::getMilliVoltage());

writeBitRegister(0x49, 0x1, 3, false);
}

float NessoBattery::getVoltage() {
// BQ27220 - address 0x55
if (!wireInitialized) {
Wire.begin(SDA, SCL);
wireInitialized = true;
}
MESH_DEBUG_PRINTLN("NessoBattery::getVoltage()");
uint16_t voltage = (readRegister(0x55, 0x9) << 8) | readRegister(0x55, 0x8);
return (float)voltage / 1000.0f;
}

uint16_t NessoBattery::getMilliVoltage() {
// BQ27220 - address 0x55
if (!wireInitialized) {
Wire.begin(SDA, SCL);
wireInitialized = true;
}
MESH_DEBUG_PRINTLN("NessoBattery::getMilliVoltage()");
uint16_t voltage = (readRegister(0x55, 0x9) << 8) | readRegister(0x55, 0x8);
return voltage;
}

uint16_t NessoBattery::getChargeLevel() {
// BQ27220 - address 0x55
if (!wireInitialized) {
Wire.begin(SDA, SCL);
wireInitialized = true;
}
MESH_DEBUG_PRINTLN("NessoBattery::getChargeLevel()");
uint16_t current_capacity = readRegister(0x55, 0x11) << 8 | readRegister(0x55, 0x10);
uint16_t total_capacity = readRegister(0x55, 0x13) << 8 | readRegister(0x55, 0x12);
return (current_capacity * 100) / total_capacity;
}

ExpanderPin LORA_LNA_ENABLE(5);
ExpanderPin LORA_ANTENNA_SWITCH(6);
ExpanderPin LORA_ENABLE(7);
ExpanderPin KEY1(0);
ExpanderPin KEY2(1);
ExpanderPin POWEROFF((1 << 8) | 0);
ExpanderPin LCD_RESET((1 << 8) | 1);
ExpanderPin GROVE_POWER_EN((1 << 8) | 2);
ExpanderPin VIN_DETECT((1 << 8) | 5);
ExpanderPin LCD_BACKLIGHT((1 << 8) | 6);
ExpanderPin LED_BUILTIN((1 << 8) | 7);
79 changes: 79 additions & 0 deletions variants/arduino_nesso_n1/pins_arduino.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// from https://github.com/espressif/arduino-esp32/pull/11985/files
#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <stdint.h>
#include "soc/soc_caps.h"

#define USB_VID 0x303A
#define USB_PID 0x1001
#define USB_MANUFACTURER "Arduino"
#define USB_PRODUCT "Nesso N1"
#define USB_SERIAL ""

static const uint8_t TX = -1;
static const uint8_t RX = -1;

static const uint8_t SDA = 10;
static const uint8_t SCL = 8;

static const uint8_t MOSI = 21;
static const uint8_t MISO = 22;
static const uint8_t SCK = 20;
static const uint8_t SS = 23;

static const uint8_t D1 = 7;
static const uint8_t D2 = 2;
static const uint8_t D3 = 6;

static const uint8_t IR_TX_PIN = 9;
static const uint8_t BEEP_PIN = 11;

static const uint8_t GROVE_IO_0 = 5;
static const uint8_t GROVE_IO_1 = 4;

static const uint8_t LORA_IRQ = 15;
static const uint8_t LORA_CS = 23;
static const uint8_t LORA_BUSY = 19;

static const uint8_t SYS_IRQ = 3;

static const uint8_t LCD_CS = 17;
static const uint8_t LCD_RS = 16;

#if !defined(MAIN_ESP32_HAL_GPIO_H_) && defined(__cplusplus)
/* address: 0x43/0x44 */
class ExpanderPin {
public:
ExpanderPin(uint16_t _pin) : pin(_pin & 0xFF), address(_pin & 0x100 ? 0x44 : 0x43){};
uint8_t pin;
uint8_t address;
};

class NessoBattery {
public:
NessoBattery(){};
void enableCharge(); // enable charging
float getVoltage(); // get battery voltage in Volts
uint16_t getMilliVoltage(); // get battery voltage in millivolts
uint16_t getChargeLevel(); // get battery charge level in percents
};

extern ExpanderPin LORA_LNA_ENABLE;
extern ExpanderPin LORA_ANTENNA_SWITCH;
extern ExpanderPin LORA_ENABLE;
extern ExpanderPin POWEROFF;
extern ExpanderPin GROVE_POWER_EN;
extern ExpanderPin VIN_DETECT;
extern ExpanderPin LCD_RESET;
extern ExpanderPin LCD_BACKLIGHT;
extern ExpanderPin LED_BUILTIN;
extern ExpanderPin KEY1;
extern ExpanderPin KEY2;

void pinMode(ExpanderPin pin, uint8_t mode);
void digitalWrite(ExpanderPin pin, uint8_t val);
int digitalRead(ExpanderPin pin);
#endif

#endif /* Pins_Arduino_h */
Loading