mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-26 17:46:14 +01:00
ESP32: Experimental BT support, enable with #define SERIAL_BT_COMMANDS
This commit is contained in:
parent
2f9c8faa77
commit
9dabf14aa3
|
@ -1 +1 @@
|
||||||
#define GITHUB_SHA "PORTX-HAL-20220823"
|
#define GITHUB_SHA "PORTX-HAL-20220828"
|
||||||
|
|
|
@ -24,6 +24,18 @@
|
||||||
#include "DCCEXParser.h"
|
#include "DCCEXParser.h"
|
||||||
#include "StringFormatter.h"
|
#include "StringFormatter.h"
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
|
#ifdef SERIAL_BT_COMMANDS
|
||||||
|
#include <BluetoothSerial.h>
|
||||||
|
//#include <BleSerial.h>
|
||||||
|
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
|
||||||
|
#error No Bluetooth library available
|
||||||
|
#endif //ENABLED
|
||||||
|
BluetoothSerial SerialBT;
|
||||||
|
//BleSerial SerialBT;
|
||||||
|
#endif //COMMANDS
|
||||||
|
#endif //ESP32
|
||||||
|
|
||||||
SerialManager * SerialManager::first=NULL;
|
SerialManager * SerialManager::first=NULL;
|
||||||
|
|
||||||
SerialManager::SerialManager(Stream * myserial) {
|
SerialManager::SerialManager(Stream * myserial) {
|
||||||
|
@ -51,6 +63,17 @@ void SerialManager::init() {
|
||||||
Serial1.begin(115200);
|
Serial1.begin(115200);
|
||||||
new SerialManager(&Serial1);
|
new SerialManager(&Serial1);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef SERIAL_BT_COMMANDS
|
||||||
|
{
|
||||||
|
uint64_t chipid = ESP.getEfuseMac();
|
||||||
|
char idstr[16] = {0};
|
||||||
|
snprintf(idstr, 15, "DCCEX-%08X",
|
||||||
|
__builtin_bswap32((uint32_t)(chipid>>16)));
|
||||||
|
SerialBT.begin(idstr);
|
||||||
|
new SerialManager(&SerialBT);
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialManager::broadcast(char * stringBuffer) {
|
void SerialManager::broadcast(char * stringBuffer) {
|
||||||
|
|
|
@ -115,6 +115,10 @@ bool WifiESP::setup(const char *SSid,
|
||||||
bool wifiUp = false;
|
bool wifiUp = false;
|
||||||
uint8_t tries = 40;
|
uint8_t tries = 40;
|
||||||
|
|
||||||
|
//#ifdef SERIAL_BT_COMMANDS
|
||||||
|
//return false;
|
||||||
|
//#endif
|
||||||
|
|
||||||
// tests
|
// tests
|
||||||
// enableCoreWDT(1);
|
// enableCoreWDT(1);
|
||||||
// disableCoreWDT(0);
|
// disableCoreWDT(0);
|
||||||
|
@ -135,7 +139,11 @@ bool WifiESP::setup(const char *SSid,
|
||||||
|
|
||||||
if (haveSSID && havePassword) {
|
if (haveSSID && havePassword) {
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
|
#ifdef SERIAL_BT_COMMANDS
|
||||||
|
WiFi.setSleep(true);
|
||||||
|
#else
|
||||||
WiFi.setSleep(false);
|
WiFi.setSleep(false);
|
||||||
|
#endif
|
||||||
WiFi.setAutoReconnect(true);
|
WiFi.setAutoReconnect(true);
|
||||||
WiFi.begin(SSid, password);
|
WiFi.begin(SSid, password);
|
||||||
while (WiFi.status() != WL_CONNECTED && tries) {
|
while (WiFi.status() != WL_CONNECTED && tries) {
|
||||||
|
@ -178,7 +186,11 @@ bool WifiESP::setup(const char *SSid,
|
||||||
strPass.concat(strMac);
|
strPass.concat(strMac);
|
||||||
|
|
||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_AP);
|
||||||
|
#ifdef SERIAL_BT_COMMANDS
|
||||||
|
WiFi.setSleep(true);
|
||||||
|
#else
|
||||||
WiFi.setSleep(false);
|
WiFi.setSleep(false);
|
||||||
|
#endif
|
||||||
if (WiFi.softAP(strSSID.c_str(),
|
if (WiFi.softAP(strSSID.c_str(),
|
||||||
havePassword ? password : strPass.c_str(),
|
havePassword ? password : strPass.c_str(),
|
||||||
channel, false, 8)) {
|
channel, false, 8)) {
|
||||||
|
@ -319,7 +331,8 @@ void WifiESP::loop() {
|
||||||
}
|
}
|
||||||
} else if (!APmode) { // in STA mode but not connected any more
|
} else if (!APmode) { // in STA mode but not connected any more
|
||||||
// kick it again
|
// kick it again
|
||||||
DIAG(F("Wifi aborted with error %s. Kicking Wifi!"), wlStatus <= 6 ? wlerror[wlStatus] : "UNKNOWN");
|
if (wlStatus <= 6) {
|
||||||
|
DIAG(F("Wifi aborted with error %s. Kicking Wifi!"), wlerror[wlStatus]);
|
||||||
esp_wifi_start();
|
esp_wifi_start();
|
||||||
esp_wifi_connect();
|
esp_wifi_connect();
|
||||||
uint8_t tries=40;
|
uint8_t tries=40;
|
||||||
|
@ -328,6 +341,10 @@ void WifiESP::loop() {
|
||||||
tries--;
|
tries--;
|
||||||
delay(500);
|
delay(500);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// all well, probably
|
||||||
|
//DIAG(F("Running BT"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// when loop() is running on core0 we must
|
// when loop() is running on core0 we must
|
||||||
|
|
Loading…
Reference in New Issue
Block a user