Serial console commands

This commit is contained in:
Lubos Petrovic
2020-12-05 14:42:20 +01:00
parent faf930425b
commit 1869ca1da5
3 changed files with 61 additions and 26 deletions

View File

@@ -174,7 +174,7 @@ void BoardInterface::loadSettings() {
// Save upgraded structure // Save upgraded structure
liveData->settings = liveData->tmpSettings; liveData->settings = liveData->tmpSettings;
saveSettings(); saveSettings();
} }
// Apply settings from flash if needed // Apply settings from flash if needed
@@ -183,10 +183,25 @@ void BoardInterface::loadSettings() {
} }
/** /**
* Custom commands Custom commands
*/ */
void BoardInterface::customConsoleCommand(String cmd) { void BoardInterface::customConsoleCommand(String cmd) {
int8_t idx = cmd.indexOf("=");
if (idx == -1)
return;
String key = cmd.substring(0, idx);
String value = cmd.substring(idx + 1);
if (key == "serviceUUID") value.toCharArray(liveData->settings.serviceUUID, value.length() + 1);
if (key == "charTxUUID") value.toCharArray(liveData->settings.charTxUUID, value.length() + 1);
if (key == "charRxUUID") value.toCharArray(liveData->settings.charRxUUID, value.length() + 1);
if (key == "wifiSsid") value.toCharArray(liveData->settings.wifiSsid, value.length() + 1);
if (key == "wifiPassword") value.toCharArray(liveData->settings.wifiPassword, value.length() + 1);
if (key == "gprsApn") value.toCharArray(liveData->settings.gprsApn, value.length() + 1);
if (key == "remoteApiUrl") value.toCharArray(liveData->settings.remoteApiUrl, value.length() + 1);
if (key == "remoteApiKey") value.toCharArray(liveData->settings.remoteApiKey, value.length() + 1);
} }
#endif // BOARDINTERFACE_CPP #endif // BOARDINTERFACE_CPP

View File

@@ -5,6 +5,15 @@
- settings v4 (wifi/gprs/sdcard/ntp/..) - settings v4 (wifi/gprs/sdcard/ntp/..)
- ble4 skipped if mac is not set (00:00:00:00:00:00) - ble4 skipped if mac is not set (00:00:00:00:00:00)
- improved menu - improved menu
- supported serial console commands
serviceUUID=xxx
charTxUUID=xxx
charRxUUID=xxx
wifiSsid=xxx
wifiPassword=xxx
gprsApn=xxx
remoteApiUrl=xxx
remoteApiKey=xxx
### v2.0.0 2020-12-02 ### v2.0.0 2020-12-02
- Project renamed from eNiroDashboard to evDash - Project renamed from eNiroDashboard to evDash

View File

@@ -1,11 +1,22 @@
/* /*
* 2020-12-02 2020-12-02
* Project renamed from eNiroDashboard to evDash Project renamed from eNiroDashboard to evDash
*
!! working only with OBD BLE 4.0 adapters !! working only with OBD BLE 4.0 adapters
!! Supported adapter is Vgate ICar Pro (must be BLE4.0 version) !! Supported adapter is Vgate ICar Pro (must be BLE4.0 version)
!! Not working with standard BLUETOOTH 3 adapters !! Not working with standard BLUETOOTH 3 adapters
Supported serial console commands
serviceUUID=xxx
charTxUUID=xxx
charRxUUID=xxx
wifiSsid=xxx
wifiPassword=xxx
gprsApn=xxx
remoteApiUrl=xxx
remoteApiKey=xxx
Required libraries Required libraries
- esp32 board support - esp32 board support
- tft_espi - tft_espi
@@ -403,7 +414,7 @@ void startBleScan() {
SIM800L SIM800L
*/ */
#ifdef SIM800L_ENABLED #ifdef SIM800L_ENABLED
bool sim800lSetup() { bool sim800lSetup() {
Serial.println("Setting SIM800L module"); Serial.println("Setting SIM800L module");
SoftwareSerial* serial = new SoftwareSerial(SIM800L_RX, SIM800L_TX); SoftwareSerial* serial = new SoftwareSerial(SIM800L_RX, SIM800L_TX);
serial->begin(9600); serial->begin(9600);
@@ -416,22 +427,22 @@ bool sim800lSetup() {
sim800l_ready = sim800l->isReady(); sim800l_ready = sim800l->isReady();
} }
if(!sim800l_ready) { if (!sim800l_ready) {
Serial.println("Problem to initialize SIM800L module"); Serial.println("Problem to initialize SIM800L module");
} else { } else {
Serial.println("SIM800L module initialized"); Serial.println("SIM800L module initialized");
Serial.print("Setting GPRS APN to: "); Serial.print("Setting GPRS APN to: ");
Serial.println(liveData->settings.gprsApn); Serial.println(liveData->settings.gprsApn);
bool sim800l_gprs = sim800l->setupGPRS(liveData->settings.gprsApn); bool sim800l_gprs = sim800l->setupGPRS(liveData->settings.gprsApn);
for(uint8_t i = 0; i < 5 && !sim800l_gprs; i++) { for (uint8_t i = 0; i < 5 && !sim800l_gprs; i++) {
Serial.println("Problem to set GPRS connection, retry in 1 sec"); Serial.println("Problem to set GPRS connection, retry in 1 sec");
delay(1000); delay(1000);
sim800l_gprs = sim800l->setupGPRS(liveData->settings.gprsApn); sim800l_gprs = sim800l->setupGPRS(liveData->settings.gprsApn);
} }
if(sim800l_gprs) { if (sim800l_gprs) {
liveData->params.sim800l_enabled = true; liveData->params.sim800l_enabled = true;
Serial.println("GPRS OK"); Serial.println("GPRS OK");
} else { } else {
@@ -494,7 +505,7 @@ bool sendDataViaGPRS() {
Serial.println(liveData->settings.remoteApiUrl); Serial.println(liveData->settings.remoteApiUrl);
uint16_t rc = sim800l->doPost(liveData->settings.remoteApiUrl, "application/json", payload, 10000, 10000); uint16_t rc = sim800l->doPost(liveData->settings.remoteApiUrl, "application/json", payload, 10000, 10000);
if(rc == 200) { if (rc == 200) {
Serial.println("HTTP POST successful"); Serial.println("HTTP POST successful");
} else { } else {
// Failed... // Failed...
@@ -563,7 +574,7 @@ void setup(void) {
// Hold right button // Hold right button
board->afterSetup(); board->afterSetup();
#ifdef SD_ENABLED #ifdef SD_ENABLED
// Init SDCARD // Init SDCARD
/*if (!SD.begin(SD_CS, SD_MOSI, SD_MISO, SD_SCLK)) { /*if (!SD.begin(SD_CS, SD_MOSI, SD_MISO, SD_SCLK)) {
Serial.println("SDCARD initialization failed!"); Serial.println("SDCARD initialization failed!");
@@ -576,7 +587,7 @@ void setup(void) {
} else { } else {
Serial.println("SDCARD initialization done."); Serial.println("SDCARD initialization done.");
}*/ }*/
#endif #endif
// Start BLE connection // Start BLE connection
line = ""; line = "";
@@ -632,18 +643,18 @@ void loop() {
} }
// Send command from TTY to OBD2 // Send command from TTY to OBD2
if (liveData->bleConnected) { if (Serial.available()) {
if (Serial.available()) { ch = Serial.read();
ch = Serial.read(); if (ch == '\r' || ch == '\n') {
if (ch == '\r' || ch == '\n') { board->customConsoleCommand(line);
board->customConsoleCommand(line); line = line + ch;
line = line + ch; Serial.println(line);
Serial.println(line); if (liveData->bleConnected) {
liveData->pRemoteCharacteristicWrite->writeValue(line.c_str(), line.length()); liveData->pRemoteCharacteristicWrite->writeValue(line.c_str(), line.length());
line = "";
} else {
line = line + ch;
} }
line = "";
} else {
line = line + ch;
} }
// Can send next command from queue to OBD // Can send next command from queue to OBD
@@ -654,7 +665,7 @@ void loop() {
} }
#ifdef SIM800L_ENABLED #ifdef SIM800L_ENABLED
if(liveData->params.lastDataSent + SIM800L_TIMER < liveData->params.currentTime && liveData->params.sim800l_enabled) { if (liveData->params.lastDataSent + SIM800L_TIMER < liveData->params.currentTime && liveData->params.sim800l_enabled) {
sendDataViaGPRS(); sendDataViaGPRS();
liveData->params.lastDataSent = liveData->params.currentTime; liveData->params.lastDataSent = liveData->params.currentTime;
} }