[SYS] Add serial self test feature (#1964)
Add self testing for Theengs Bridge v1.1 (TBRIDGE02) This feature enables factory testing
This commit is contained in:
1 parent
e321448db0
commit
a74a6ebc06
4 files changed
+145
-7
No files matched your search
@@ -78,6 +78,7 @@ jobs:
|
|||||||
- "thingpulse-espgateway"
|
- "thingpulse-espgateway"
|
||||||
- "theengs-bridge"
|
- "theengs-bridge"
|
||||||
- "esp32dev-ble-idf"
|
- "esp32dev-ble-idf"
|
||||||
|
- "theengs-bridge-v11"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Build with PlatformIO
|
name: Build with PlatformIO
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -87,6 +87,47 @@ build_flags =
|
|||||||
custom_description = BLE gateway with external antenna and Ethernet/WiFi connectivity, [user guide](https://tbridge01.theengs.io/)
|
custom_description = BLE gateway with external antenna and Ethernet/WiFi connectivity, [user guide](https://tbridge01.theengs.io/)
|
||||||
custom_hardware = Theengs Bridge gateway ethernet
|
custom_hardware = Theengs Bridge gateway ethernet
|
||||||
|
|
||||||
|
[env:theengs-bridge-v11]
|
||||||
|
platform = ${com.esp32_platform}
|
||||||
|
board = esp32dev
|
||||||
|
extra_scripts = ${com-esp32.extra_scripts}
|
||||||
|
board_build.partitions = min_spiffs.csv
|
||||||
|
lib_deps =
|
||||||
|
${com-esp32.lib_deps}
|
||||||
|
${libraries.ble}
|
||||||
|
${libraries.adafruit_neopixel}
|
||||||
|
${libraries.decoder}
|
||||||
|
build_flags =
|
||||||
|
${com-esp32.build_flags}
|
||||||
|
'-DZgatewayBT="BT"'
|
||||||
|
'-DLED_SEND_RECEIVE=2'
|
||||||
|
'-DLED_SEND_RECEIVE_ON=0'
|
||||||
|
'-DESP32_ETHERNET=true'
|
||||||
|
'-DETH_PHY_TYPE=ETH_PHY_LAN8720'
|
||||||
|
'-DETH_PHY_ADDR=0'
|
||||||
|
'-DETH_PHY_POWER=5'
|
||||||
|
'-DETH_PHY_MDC=23'
|
||||||
|
'-DETH_PHY_MDIO=18'
|
||||||
|
'-DETH_CLK_MODE=ETH_CLOCK_GPIO16_OUT'
|
||||||
|
'-DANEOPIX_IND_DATA_GPIO=32'
|
||||||
|
'-DANEOPIX_IND_NUM_LEDS=4'
|
||||||
|
'-DANEOPIX_INFO_LED=0'
|
||||||
|
'-DANEOPIX_SEND_RECEIVE_LED=1'
|
||||||
|
'-DANEOPIX_ERROR_LED=1'
|
||||||
|
'-DANEOPIX_BRIGHTNESS=100'
|
||||||
|
'-DRGB_INDICATORS=true'
|
||||||
|
'-DAttemptBLEConnect=false'
|
||||||
|
'-DTRIGGER_GPIO=4'
|
||||||
|
'-DUSE_MAC_AS_GATEWAY_NAME'
|
||||||
|
'-DGATEWAY_MANUFACTURER="Theengs"'
|
||||||
|
'-DGATEWAY_MODEL="TBRIDGE02"'
|
||||||
|
;'-DBOARD_HAS_PSRAM'
|
||||||
|
'-UZwebUI="WebUI"' ; Disable WebUI
|
||||||
|
'-DSELF_TEST=true'
|
||||||
|
;'-mfix-esp32-psram-cache-issue'
|
||||||
|
custom_description = BLE gateway with external antenna and Ethernet/WiFi connectivity, [user guide](https://tbridge02.theengs.io/)
|
||||||
|
custom_hardware = Theengs Bridge gateway ethernet
|
||||||
|
|
||||||
[env:esp32dev-all-test]
|
[env:esp32dev-all-test]
|
||||||
platform = ${com.esp32_platform}
|
platform = ${com.esp32_platform}
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
#if SELF_TEST
|
||||||
|
# include <esp_system.h>
|
||||||
|
|
||||||
|
String getChipModel() {
|
||||||
|
esp_chip_info_t chip_info;
|
||||||
|
esp_chip_info(&chip_info);
|
||||||
|
|
||||||
|
switch (chip_info.model) {
|
||||||
|
case CHIP_ESP32:
|
||||||
|
return "ESP32";
|
||||||
|
case CHIP_ESP32S2:
|
||||||
|
return "ESP32-S2";
|
||||||
|
case CHIP_ESP32S3:
|
||||||
|
return "ESP32-S3";
|
||||||
|
case CHIP_ESP32C3:
|
||||||
|
return "ESP32-C3";
|
||||||
|
case CHIP_ESP32H2:
|
||||||
|
return "ESP32-H2";
|
||||||
|
default:
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// From https://github.com/ThingPulse/espgateway-ethernet-testbed
|
||||||
|
|
||||||
|
void addTestMessage(JsonArray& data, String name, String value, String result) {
|
||||||
|
JsonObject object = data.createNestedObject();
|
||||||
|
object["name"] = name;
|
||||||
|
object["value"] = value;
|
||||||
|
object["result"] = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testDevice() {
|
||||||
|
StaticJsonDocument<1200> doc;
|
||||||
|
JsonArray data = doc.to<JsonArray>();
|
||||||
|
|
||||||
|
addTestMessage(data, "Mac Address", String(WiFi.macAddress()), "OK");
|
||||||
|
addTestMessage(data, "Chip Model", String(ESP.getChipModel()), "OK");
|
||||||
|
addTestMessage(data, "Chip Revision", String(ESP.getChipRevision()), "OK");
|
||||||
|
addTestMessage(data, "Available Cores", String(ESP.getChipCores()), ESP.getChipCores() == 2 ? "OK" : "NOK");
|
||||||
|
addTestMessage(data, "Heap Size", String(ESP.getHeapSize() / 1024) + "kb", ESP.getHeapSize() > 100000 ? "OK" : "NOK");
|
||||||
|
addTestMessage(data, "Free Heap", String(ESP.getFreeHeap() / 1024) + "kb", ESP.getFreeHeap() > 100000 ? "OK" : "NOK");
|
||||||
|
addTestMessage(data, "ETH MAC Address", String(ETH.macAddress()), ETH.macAddress() ? "OK" : "NOK");
|
||||||
|
addTestMessage(data, "ETH Local IP", ETH.localIP().toString(), ETH.localIP() ? "OK" : "NOK");
|
||||||
|
addTestMessage(data, "ETH Full Duplex", ETH.fullDuplex() ? "true" : "false", ETH.fullDuplex() ? "OK" : "NOK");
|
||||||
|
addTestMessage(data, "ETH Link Speed", String(ETH.linkSpeed()) + "Mbs", ETH.linkSpeed() ? "OK" : "NOK");
|
||||||
|
addTestMessage(data, "Build Date", String(__DATE__), "OK");
|
||||||
|
addTestMessage(data, "Build Time", String(__TIME__), "OK");
|
||||||
|
serializeJson(doc, Serial);
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void testLeds() {
|
||||||
|
Log.notice(F("LED Test" CR));
|
||||||
|
InfoIndicatorON();
|
||||||
|
SendReceiveIndicatorON();
|
||||||
|
Log.notice(F("LED Test Finished" CR));
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkSerial() {
|
||||||
|
Log.notice(F("READY_FOR_SELFTEST" CR));
|
||||||
|
unsigned long start = millis();
|
||||||
|
while (millis() - start < 1000) {
|
||||||
|
if (Serial.available() > 0) {
|
||||||
|
String input = Serial.readStringUntil('\n');
|
||||||
|
input.trim(); // Remove any extra whitespace
|
||||||
|
if (input == "SELFTEST") {
|
||||||
|
Log.notice(F("SELFTEST Launched" CR));
|
||||||
|
testLeds();
|
||||||
|
// Print 20 times the test data
|
||||||
|
for (int i = 0; i < 20; i++) {
|
||||||
|
testDevice();
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
Log.notice(F("SELFTEST Finished" CR));
|
||||||
|
// Restart
|
||||||
|
ESPRestart(9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+21
-7
@@ -1134,6 +1134,12 @@ void setup() {
|
|||||||
# ifdef ESP32_ETHERNET
|
# ifdef ESP32_ETHERNET
|
||||||
setup_ethernet_esp32();
|
setup_ethernet_esp32();
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# if SELF_TEST
|
||||||
|
// Check serial input to trigger a Self Test sequence if required
|
||||||
|
checkSerial();
|
||||||
|
# endif
|
||||||
|
|
||||||
Log.notice(F("No config in flash, launching wifi manager" CR));
|
Log.notice(F("No config in flash, launching wifi manager" CR));
|
||||||
// In failSafeMode we don't want to setup wifi manager as it has already been done before
|
// In failSafeMode we don't want to setup wifi manager as it has already been done before
|
||||||
if (!failSafeMode) setupwifi(false);
|
if (!failSafeMode) setupwifi(false);
|
||||||
@@ -1507,6 +1513,7 @@ void setupTLS(int index) {
|
|||||||
6 - OTA Update
|
6 - OTA Update
|
||||||
7 - Parameters changed
|
7 - Parameters changed
|
||||||
8 - not enough memory to pursue
|
8 - not enough memory to pursue
|
||||||
|
9 - SELFTEST end
|
||||||
*/
|
*/
|
||||||
void ESPRestart(byte reason) {
|
void ESPRestart(byte reason) {
|
||||||
delay(1000);
|
delay(1000);
|
||||||
@@ -1862,7 +1869,7 @@ bool loadConfigFromFlash() {
|
|||||||
configFile.close();
|
configFile.close();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.notice(F("no config file found defining default values" CR));
|
Log.notice(F("No config file found defining default values" CR));
|
||||||
# ifdef USE_MAC_AS_GATEWAY_NAME
|
# ifdef USE_MAC_AS_GATEWAY_NAME
|
||||||
String s = WiFi.macAddress();
|
String s = WiFi.macAddress();
|
||||||
sprintf(gateway_name, "%.2s%.2s%.2s%.2s%.2s%.2s",
|
sprintf(gateway_name, "%.2s%.2s%.2s%.2s%.2s%.2s",
|
||||||
@@ -2075,14 +2082,21 @@ void setup_ethernet_esp32() {
|
|||||||
ETH.config(ip, gateway, subnet, Dns);
|
ETH.config(ip, gateway, subnet, Dns);
|
||||||
ethBeginSuccess = ETH.begin();
|
ethBeginSuccess = ETH.begin();
|
||||||
# else
|
# else
|
||||||
Log.trace(F("Spl eth cfg" CR));
|
Log.notice(F("Spl eth cfg" CR));
|
||||||
ethBeginSuccess = ETH.begin();
|
ethBeginSuccess = ETH.begin();
|
||||||
# endif
|
# endif
|
||||||
Log.trace(F("Connecting to Ethernet" CR));
|
if (ethBeginSuccess) {
|
||||||
while (!ethConnected && failure_number_ntwk <= maxConnectionRetryNetwork) {
|
Log.notice(F("Ethernet started" CR));
|
||||||
delay(500);
|
Log.notice(F("OpenMQTTGateway MAC: %s" CR), ETH.macAddress().c_str());
|
||||||
Log.trace(F("." CR));
|
Log.notice(F("OpenMQTTGateway IP: %s" CR), ETH.localIP().toString().c_str());
|
||||||
failure_number_ntwk++;
|
Log.notice(F("OpenMQTTGateway link speed: %d Mbps" CR), ETH.linkSpeed());
|
||||||
|
while (!ethConnected && failure_number_ntwk <= maxConnectionRetryNetwork) {
|
||||||
|
delay(500);
|
||||||
|
Log.notice(F("." CR));
|
||||||
|
failure_number_ntwk++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.error(F("Ethernet not started" CR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user