|
|
|
@ -1,35 +1,10 @@ |
|
|
|
#include <Arduino.h> |
|
|
|
#include "RAKWismeshTagBoard.h" |
|
|
|
|
|
|
|
#include <bluefruit.h> |
|
|
|
#include <Wire.h> |
|
|
|
|
|
|
|
static BLEDfu bledfu; |
|
|
|
|
|
|
|
static void connect_callback(uint16_t conn_handle) { |
|
|
|
(void)conn_handle; |
|
|
|
MESH_DEBUG_PRINTLN("BLE client connected"); |
|
|
|
} |
|
|
|
|
|
|
|
static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { |
|
|
|
(void)conn_handle; |
|
|
|
(void)reason; |
|
|
|
|
|
|
|
MESH_DEBUG_PRINTLN("BLE client disconnected"); |
|
|
|
} |
|
|
|
#include "RAKWismeshTagBoard.h" |
|
|
|
|
|
|
|
void RAKWismeshTagBoard::begin() { |
|
|
|
// for future use, sub-classes SHOULD call this from their begin()
|
|
|
|
startup_reason = BD_STARTUP_NORMAL; |
|
|
|
|
|
|
|
// Enable DC/DC converter for improved power efficiency
|
|
|
|
uint8_t sd_enabled = 0; |
|
|
|
sd_softdevice_is_enabled(&sd_enabled); |
|
|
|
if (sd_enabled) { |
|
|
|
sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE); |
|
|
|
} else { |
|
|
|
NRF_POWER->DCDCEN = 1; |
|
|
|
} |
|
|
|
NRF52BoardDCDC::begin(); |
|
|
|
|
|
|
|
pinMode(PIN_VBAT_READ, INPUT); |
|
|
|
pinMode(PIN_USER_BTN, INPUT_PULLUP); |
|
|
|
@ -40,52 +15,4 @@ void RAKWismeshTagBoard::begin() { |
|
|
|
pinMode(SX126X_POWER_EN, OUTPUT); |
|
|
|
digitalWrite(SX126X_POWER_EN, HIGH); |
|
|
|
delay(10); // give sx1262 some time to power up
|
|
|
|
} |
|
|
|
|
|
|
|
bool RAKWismeshTagBoard::startOTAUpdate(const char* id, char reply[]) { |
|
|
|
// Config the peripheral connection with maximum bandwidth
|
|
|
|
// more SRAM required by SoftDevice
|
|
|
|
// Note: All config***() function must be called before begin()
|
|
|
|
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); |
|
|
|
Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); |
|
|
|
|
|
|
|
Bluefruit.begin(1, 0); |
|
|
|
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
|
|
|
|
Bluefruit.setTxPower(4); |
|
|
|
// Set the BLE device name
|
|
|
|
Bluefruit.setName("WISMESHTAG_OTA"); |
|
|
|
|
|
|
|
Bluefruit.Periph.setConnectCallback(connect_callback); |
|
|
|
Bluefruit.Periph.setDisconnectCallback(disconnect_callback); |
|
|
|
|
|
|
|
// To be consistent OTA DFU should be added first if it exists
|
|
|
|
bledfu.begin(); |
|
|
|
|
|
|
|
// Set up and start advertising
|
|
|
|
// Advertising packet
|
|
|
|
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); |
|
|
|
Bluefruit.Advertising.addTxPower(); |
|
|
|
Bluefruit.Advertising.addName(); |
|
|
|
|
|
|
|
/* Start Advertising
|
|
|
|
- Enable auto advertising if disconnected |
|
|
|
- Interval: fast mode = 20 ms, slow mode = 152.5 ms |
|
|
|
- Timeout for fast mode is 30 seconds |
|
|
|
- Start(timeout) with timeout = 0 will advertise forever (until connected) |
|
|
|
|
|
|
|
For recommended advertising interval |
|
|
|
https://developer.apple.com/library/content/qa/qa1931/_index.html
|
|
|
|
*/ |
|
|
|
Bluefruit.Advertising.restartOnDisconnect(true); |
|
|
|
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
|
|
|
|
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
|
|
|
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
|
|
|
|
|
|
|
|
uint8_t mac_addr[6]; |
|
|
|
memset(mac_addr, 0, sizeof(mac_addr)); |
|
|
|
Bluefruit.getAddr(mac_addr); |
|
|
|
sprintf(reply, "OK - mac: %02X:%02X:%02X:%02X:%02X:%02X", |
|
|
|
mac_addr[5], mac_addr[4], mac_addr[3], mac_addr[2], mac_addr[1], mac_addr[0]); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |