Skip to content

Commit

Permalink
Expose the ESP chip info and the build env
Browse files Browse the repository at this point in the history
This change exposes the ESP chip info (#49) and the Platform IO build env (#223) via the `/config` endpoint to help with hardware identification and selecting an appropriate software update.

Also includes a few bits of tidy-up.
  • Loading branch information
jeremypoulter committed Aug 30, 2021
1 parent 56c6629 commit c2390fd
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 168 deletions.
187 changes: 94 additions & 93 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ data_dir = src/data
default_envs = openevse_wifi_v1

[common]
version = -DBUILD_TAG=4.1.0
version = -D BUILD_TAG=4.1.0
monitor_speed = 115200
lib_deps =
ArduinoJson@6.15.1
ArduinoMongoose@0.0.16
Micro Debug@0.0.5
ConfigJson@0.0.3
OpenEVSE@0.0.7
ESPAL@0.0.1
ESPAL@0.0.3
StreamSpy@0.0.1
MicroTasks@0.0.2
ESP32 AnalogWrite@0.2
Expand All @@ -47,41 +47,42 @@ lib_ignore = WebSockets ; ArduinoOcpp: don't compile built-in WS library
extra_scripts = scripts/extra_script.py
debug_flags =
-ggdb
-DENABLE_DEBUG
#-DENABLE_DEBUG_WEB
#-DENABLE_DEBUG_WEB_REQUEST
#-DENABLE_DEBUG_SCHEDULER
#-DENABLE_DEBUG_EVSE_MAN
#-DENABLE_DEBUG_EVSE_MONITOR
#-DENABLE_DEBUG_DIVERT
#-DENABLE_DEBUG_LED
#-DENABLE_DEBUG_LCD
#-DENABLE_DEBUG_MQTT
#-DENABLE_DEBUG_EMONCMS
#-DENABLE_DEBUG_TESLA_CLIENT
#-DENABLE_PROFILE
-D ENABLE_DEBUG
#-D ENABLE_DEBUG_WEB
#-D ENABLE_DEBUG_WEB_REQUEST
#-D ENABLE_DEBUG_SCHEDULER
#-D ENABLE_DEBUG_EVSE_MAN
#-D ENABLE_DEBUG_EVSE_MONITOR
#-D ENABLE_DEBUG_DIVERT
#-D ENABLE_DEBUG_LED
#-D ENABLE_DEBUG_LCD
#-D ENABLE_DEBUG_MQTT
#-D ENABLE_DEBUG_EMONCMS
#-D ENABLE_DEBUG_TESLA_CLIENT
#-D ENABLE_PROFILE
src_build_flags =
# -DARDUINOJSON_USE_LONG_LONG
# -DENABLE_ASYNC_WIFI_SCAN
# -D ARDUINOJSON_USE_LONG_LONG
# -D ENABLE_ASYNC_WIFI_SCAN
build_flags =
-DCS_PLATFORM=CS_P_ESP32
-DMG_ENABLE_SSL=1
-DMG_ENABLE_HTTP_STREAMING_MULTIPART=1
-DMG_SSL_MBED_DUMMY_RANDOM=1
-DMG_SSL_IF=MG_SSL_IF_MBEDTLS
-DMG_SSL_IF_MBEDTLS_FREE_CERTS=1
#-DMG_SSL_IF_MBEDTLS_MAX_FRAG_LEN=2048
#-DARDUINO_MONGOOSE_DEFAULT_STREAM_BUFFER=2048
#-DARDUINO_MONGOOSE_SEND_BUFFER_SIZE=2048
#-DENABLE_DEBUG
#-DCS_ENABLE_DEBUG
#-DMBEDTLS_DEBUG_C
-DMG_ENABLE_SNTP=1
-DCS_PLATFORM=CS_P_ESP32
-DAO_CUSTOM_WS ; ArduinoOcpp: don't use built-in WS library
#-DENABLE_DEBUG
#-DENABLE_DEBUG_MONGOOSE_HTTP_CLIENT
-DRAPI_MAX_COMMANDS=20
-D CS_PLATFORM=CS_P_ESP32
-D MG_ENABLE_SSL=1
-D MG_ENABLE_HTTP_STREAMING_MULTIPART=1
-D MG_SSL_MBED_DUMMY_RANDOM=1
-D MG_SSL_IF=MG_SSL_IF_MBEDTLS
-D MG_SSL_IF_MBEDTLS_FREE_CERTS=1
#-D MG_SSL_IF_MBEDTLS_MAX_FRAG_LEN=2048
#-D ARDUINO_MONGOOSE_DEFAULT_STREAM_BUFFER=2048
#-D ARDUINO_MONGOOSE_SEND_BUFFER_SIZE=2048
#-D ENABLE_DEBUG
#-D CS_ENABLE_DEBUG
#-D MBEDTLS_DEBUG_C
-D MG_ENABLE_SNTP=1
-D CS_PLATFORM=CS_P_ESP32
-D AO_CUSTOM_WS ; ArduinoOcpp: don't use built-in WS library
#-D ENABLE_DEBUG
#-D ENABLE_DEBUG_MONGOOSE_HTTP_CLIENT
-D RAPI_MAX_COMMANDS=20
-D BUILD_ENV_NAME="$PIOENV"
build_partitions = min_spiffs.csv
monitor_flags = --filter=esp32_exception_decoder

Expand All @@ -104,9 +105,9 @@ src_build_flags =
${common.version}.dev
${common.src_build_flags}
${common.debug_flags}
-DWIFI_LED=LED_BUILTIN
-DWIFI_LED_ON_STATE=LOW
-DRAPI_PORT=Serial2
-D WIFI_LED=LED_BUILTIN
-D WIFI_LED_ON_STATE=LOW
-D RAPI_PORT=Serial2
build_flags =
${common.build_flags}
#upload_port = openevse.local
Expand All @@ -127,17 +128,17 @@ src_build_flags =
${common.version}.dev
${common.src_build_flags}
${common.debug_flags}
-DWIFI_BUTTON=2
-DRAPI_PORT=Serial1
-DNEO_PIXEL_PIN=18
-DNEO_PIXEL_LENGTH=2
-DRED_LED=0
-DGREEN_LED=2
-DBLUE_LED=4
-D WIFI_BUTTON=2
-D RAPI_PORT=Serial1
-D NEO_PIXEL_PIN=18
-D NEO_PIXEL_LENGTH=2
-D RED_LED=0
-D GREEN_LED=2
-D BLUE_LED=4
build_flags =
${common.build_flags}
-DRX1=25
-DTX1=27
-D RX1=25
-D TX1=27
-ggdb
#upload_port = openevse.local
upload_speed = 2000000
Expand All @@ -159,13 +160,13 @@ src_build_flags =
${common.version}.dev
${common.src_build_flags}
${common.debug_flags}
-DWIFI_LED=13
-DWIFI_LED_ON_STATE=HIGH
-DWIFI_BUTTON=0
-DWIFI_BUTTON_PRESSED_STATE=LOW
-DRAPI_PORT=Serial
-DDEBUG_PORT=Serial2
-DSERIAL_RX_PULLUP_PIN=3
-D WIFI_LED=13
-D WIFI_LED_ON_STATE=HIGH
-D WIFI_BUTTON=0
-D WIFI_BUTTON_PRESSED_STATE=LOW
-D RAPI_PORT=Serial
-D DEBUG_PORT=Serial2
-D SERIAL_RX_PULLUP_PIN=3
build_flags =
${common.build_flags}
upload_speed = 921600
Expand All @@ -182,13 +183,13 @@ lib_ignore = ${common.lib_ignore}
src_build_flags =
${common.version}
${common.src_build_flags}
-DWIFI_LED=13
-DWIFI_LED_ON_STATE=HIGH
-DWIFI_BUTTON=0
-DWIFI_BUTTON_PRESSED_STATE=LOW
-DRAPI_PORT=Serial
-DDEBUG_PORT=Serial2
-DSERIAL_RX_PULLUP_PIN=3
-D WIFI_LED=13
-D WIFI_LED_ON_STATE=HIGH
-D WIFI_BUTTON=0
-D WIFI_BUTTON_PRESSED_STATE=LOW
-D RAPI_PORT=Serial
-D DEBUG_PORT=Serial2
-D SERIAL_RX_PULLUP_PIN=3
build_flags =
${common.build_flags}
upload_speed = 921600
Expand All @@ -206,10 +207,10 @@ src_build_flags =
${common.version}.dev
${common.src_build_flags}
${common.debug_flags}
-DWIFI_LED=LED_BUILTIN
-DWIFI_BUTTON=LED_BUILTIN
-DRAPI_PORT=Serial2
-DENABLE_DEBUG_LED
-D WIFI_LED=LED_BUILTIN
-D WIFI_BUTTON=LED_BUILTIN
-D RAPI_PORT=Serial2
-D ENABLE_DEBUG_LED
build_flags =
${common.build_flags}
#upload_port = openevse.local
Expand All @@ -231,19 +232,19 @@ src_build_flags =
${common.version}
${common.src_build_flags}
${common.debug_flags}
-DNEO_PIXEL_PIN=17
-DNEO_PIXEL_LENGTH=2
-DWIFI_BUTTON=0
-DWIFI_BUTTON_PRESSED_STATE=LOW
-DRAPI_PORT=Serial
-DDEBUG_PORT=Serial1
-DSERIAL_RX_PULLUP_PIN=3
-DI2C_SDA=21
-DI2C_SCL=22
-DENABLE_MCP9808
-D NEO_PIXEL_PIN=17
-D NEO_PIXEL_LENGTH=2
-D WIFI_BUTTON=0
-D WIFI_BUTTON_PRESSED_STATE=LOW
-D RAPI_PORT=Serial
-D DEBUG_PORT=Serial1
-D SERIAL_RX_PULLUP_PIN=3
-D I2C_SDA=21
-D I2C_SCL=22
-D ENABLE_MCP9808
build_flags =
${common.build_flags}
-DTX1=16
-D TX1=16
upload_speed = 921600
monitor_speed = 115200
extra_scripts = ${common.extra_scripts}
Expand All @@ -259,14 +260,14 @@ lib_ignore = ${common.lib_ignore}
src_build_flags =
${common.version}
${common.src_build_flags}
-DWIFI_LED=33
-DWIFI_LED_ON_STATE=HIGH
-DWIFI_BUTTON=34
-DWIFI_BUTTON_PRESSED_STATE=LOW
-DDEBUG_PORT=Serial
-DRAPI_PORT=Serial2
-DENABLE_WIRED_ETHERNET
-DRANDOM_SEED_CHANNEL=1
-D WIFI_LED=33
-D WIFI_LED_ON_STATE=HIGH
-D WIFI_BUTTON=34
-D WIFI_BUTTON_PRESSED_STATE=LOW
-D DEBUG_PORT=Serial
-D RAPI_PORT=Serial2
-D ENABLE_WIRED_ETHERNET
-D RANDOM_SEED_CHANNEL=1
build_flags =
${common.build_flags}
upload_speed = 115200
Expand All @@ -282,9 +283,9 @@ extends = env:openevse_esp32-gateway
framework = arduino, espidf
build_flags =
${common.build_flags}
-DRX2=16
-DTX2=32
board_build.extra_flags = "-DARDUINO_ESP32_GATEWAY=\'E\'"
-D RX2=16
-D TX2=32
board_build.extra_flags = "-D ARDUINO_ESP32_GATEWAY=\'E\'"

[env:openevse_esp32-heltec-wifi-lora-v2]
platform = ${common.platform}
Expand All @@ -295,14 +296,14 @@ lib_ignore = ${common.lib_ignore}
src_build_flags =
${common.version}.dev
${common.src_build_flags}
-DWIFI_LED=25
-DWIFI_BUTTON=2
-DWIFI_LED_ON_STATE=HIGH
-DRAPI_PORT=Serial1
-D WIFI_LED=25
-D WIFI_BUTTON=2
-D WIFI_LED_ON_STATE=HIGH
-D RAPI_PORT=Serial1
build_flags =
${common.build_flags}
-DRX1=25
-DTX1=27
-D RX1=25
-D TX1=27
#upload_port = openevse.local
#upload_speed = 921600
upload_protocol = esptool
Expand Down
1 change: 1 addition & 0 deletions src/emonesp.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@
#endif // !SCHEDULE_PATH

extern String currentfirmware;
extern String buildenv;

#endif // _EMONESP_H
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static uint32_t last_mem = 0;
#define TEXTIFY(A) #A
#define ESCAPEQUOTE(A) TEXTIFY(A)
String currentfirmware = ESCAPEQUOTE(BUILD_TAG);
String buildenv = ESCAPEQUOTE(BUILD_ENV_NAME);

ArduinoOcppTask ocpp = ArduinoOcppTask();

Expand Down
76 changes: 1 addition & 75 deletions src/web_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const char _CONTENT_TYPE_SVG[] PROGMEM = "image/svg+xml";

#define RAPI_RESPONSE_BLOCKED -300

void handleConfig(MongooseHttpServerRequest *request);
void handleEvseClaims(MongooseHttpServerRequest *request);

void dumpRequest(MongooseHttpServerRequest *request)
Expand Down Expand Up @@ -637,81 +638,6 @@ handleStatus(MongooseHttpServerRequest *request) {
request->send(response);
}

// -------------------------------------------------------------------
// Returns OpenEVSE Config json
// url: /config
// -------------------------------------------------------------------
void
handleConfigGet(MongooseHttpServerRequest *request, MongooseHttpServerResponseStream *response)
{
const size_t capacity = JSON_OBJECT_SIZE(43) + 1024;
DynamicJsonDocument doc(capacity);

// EVSE Config
doc["firmware"] = evse.getFirmwareVersion();
doc["protocol"] = "-";
doc["espflash"] = ESPAL.getFlashChipSize();
doc["version"] = currentfirmware;
doc["diodet"] = evse.isDiodeCheckDisabled() ? 1 : 0;
doc["gfcit"] = evse.isGfiTestDisabled() ? 1 : 0;
doc["groundt"] = evse.isGroundCheckDisabled() ? 1 : 0;
doc["relayt"] = evse.isStuckRelayCheckDisabled() ? 1 : 0;
doc["ventt"] = evse.isVentRequiredDisabled() ? 1 : 0;
doc["tempt"] = evse.isTemperatureCheckDisabled() ? 1 : 0;
doc["service"] = static_cast<uint8_t>(evse.getServiceLevel());
doc["scale"] = current_scale;
doc["offset"] = current_offset;

// Static supported protocols
JsonArray mqtt_supported_protocols = doc.createNestedArray("mqtt_supported_protocols");
mqtt_supported_protocols.add("mqtt");
mqtt_supported_protocols.add("mqtts");

JsonArray http_supported_protocols = doc.createNestedArray("http_supported_protocols");
http_supported_protocols.add("http");
http_supported_protocols.add("https");

config_serialize(doc, true, false, true);

response->setCode(200);
serializeJson(doc, *response);
}

void
handleConfigPost(MongooseHttpServerRequest *request, MongooseHttpServerResponseStream *response)
{
String body = request->body().toString();
if(config_deserialize(body)) {
config_commit();
response->setCode(200);
response->print("{\"msg\":\"done\"}");
} else {
response->setCode(400);
response->print("{\"msg\":\"Could not parse JSON\"}");
}
}

void
handleConfig(MongooseHttpServerRequest *request)
{
MongooseHttpServerResponseStream *response;
if(false == requestPreProcess(request, response)) {
return;
}

if(HTTP_GET == request->method()) {
handleConfigGet(request, response);
} else if(HTTP_POST == request->method()) {
handleConfigPost(request, response);
} else if(HTTP_OPTIONS == request->method()) {
response->setCode(200);
} else {
response->setCode(405);
}

request->send(response);
}

// -------------------------------------------------------------------
//
// url: /schedule
Expand Down
Loading

0 comments on commit c2390fd

Please sign in to comment.