Skip to content

Commit

Permalink
Merge branch 'master' into jeremypoulter/issue643
Browse files Browse the repository at this point in the history
  • Loading branch information
glynhudson authored Aug 30, 2023
2 parents 3e586b4 + 0dd3cc7 commit d636dd7
Show file tree
Hide file tree
Showing 22 changed files with 6,776 additions and 6,735 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ jobs:
fail-fast: false
matrix:
env:
- openevse_nodemcu-32s
- openevse_esp-wrover-kit
- openevse_esp-wrover-kit_latest
- openevse_huzzah32_dev
- openevse_huzzah32
- openevse_featheresp32
- nodemcu-32s
- espressif_esp-wrover-kit
- espressif_esp-wrover-kit_latest
- adafruit_huzzah32_dev
- adafruit_huzzah32
- adafruit_featheresp32
- openevse_wifi_v1
- openevse_esp32-gateway-old
- openevse_esp32-gateway-e
- openevse_esp32-gateway-f
- openevse_esp32-gateway-e_dev
- openevse_esp32-gateway-f_dev
- openevse_esp32-poe-iso
- openevse_esp32-heltec-wifi-lora-v2
- olimex_esp32-gateway-old
- olimex_esp32-gateway-e
- olimex_esp32-gateway-f
- olimex_esp32-gateway-e_dev
- olimex_esp32-gateway-f_dev
- olimex_esp32-poe-iso
- heltec_esp32-wifi-lora-v2
gui:
- name: gui-v2
repo: OpenEVSE/openevse-gui-v2
Expand Down
4 changes: 4 additions & 0 deletions api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -773,10 +773,14 @@ paths:
x-stoplight:
id: 7h1cpgfjj5j9j
format: date-time
uptime:
type: integer
description: EVSE gateway uptime, in seconds
required:
- time
- offset
- local_time
- uptime
operationId: get-time
description: Gets the time set on the OpenEVSE
post:
Expand Down
2 changes: 1 addition & 1 deletion docs/developer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pio run -t upload
If you are using a different development board, you can specify one of the envs setup in `platformio.ini`, for example:

```bash
pio run -e openevse_huzzah32_idf -t upload
pio run -e adafruit_huzzah32 -t upload
```

Build artifacts will be in `.pio/build/your_openevse_env`
Expand Down
8 changes: 4 additions & 4 deletions docs/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ For releases and PR approval the builds are built using the [Build/Release OpenE
1. Click `Publish release`
1. The GitHub build workflow will generate the binaries and upload them to the release
1. Remove any unwanted binaries, need at least:
- `openevse_esp32-gateway-e.bin`
- `openevse_huzzah32.bin`
- `olimex_esp32-gateway-e.bin`
- `adafruit_huzzah32.bin`
- `openevse_wifi_v1.bin`
- `openevse_esp-wrover-kit`
- `openevse_nodemcu-32s`
- `espressif_esp-wrover-kit`
- `nodemcu-32s`
1. Test the uploaded binaries
1. Unselect the `Pre-release` checkbox
1. Click `Update release`
Expand Down
16 changes: 8 additions & 8 deletions docs/wired-ethernet.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ ESP32-gateway can be connected by micro USB and firmware can be uploaded using e
First upload:

```bash
esptool.py --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader.bin 0x8000 partitions.bin 0x10000 openevse_esp32-gateway-e.bin
esptool.py --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader.bin 0x8000 partitions.bin 0x10000 olimex_esp32-gateway-e.bin
```

Subsequent upgrades:

```bash
esptool.py --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 openevse_esp32-gateway-e.bin
esptool.py --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 olimex_esp32-gateway-e.bin
```

*Note: On Ubuntu 22.04 if you notice the ESP gateway is continually disconnect from the USB serail port,check this using `dmesg` then`sudo apt remove brltty` will fix this. This is because there is an ebook reader which shares the same serial adaptor chip as the ESP gateway and the udev rules conflict.*
Expand All @@ -65,28 +65,28 @@ For Ubuntu 22.04 the simplest solution is to remove the package brltty via sudo
First upload:

```bash
esptool.py --before default_reset --after hard_reset write_flash 0x1000 bootloader.bin 0x8000 partitions.bin 0x10000 openevse_esp32-gateway-f.bin
esptool.py --before default_reset --after hard_reset write_flash 0x1000 bootloader.bin 0x8000 partitions.bin 0x10000 olimex_esp32-gateway-f.bin
```

Subsequent upgrades:

```bash
esptool.py --before default_reset --after hard_reset write_flash 0x10000 openevse_esp32-gateway-f.bin`
esptool.py --before default_reset --after hard_reset write_flash 0x10000 olimex_esp32-gateway-f.bin`
```

## Compile and Upload

| Board | Environment |
| :------------------------ | :----------------------- |
| ESP32-GATEWAY pre-E | openevse_esp32-gateway |
| ESP32-GATEWAY E and later | openevse_esp32-gateway-e |
| ESP32-PoE-ISO | openevse_esp32-poe-iso |
| ESP32-GATEWAY pre-E | olimex_esp32-gateway |
| ESP32-GATEWAY E and later | olimex_esp32-gateway-e |
| ESP32-PoE-ISO | olimex_esp32-poe-iso |


Firmware can be compiled using PlatformIO `pio run -e <Environment>`. The `-t upload` option installs firmware over USB.

```bash
pio run -e openevse_esp32-gateway-e -t upload
pio run -e olimex_esp32-gateway-e -t upload
```

## Operation
Expand Down
4 changes: 2 additions & 2 deletions models/Config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ x-examples:
protocol: '-'
espflash: 4194304
espinfo: ESP32r1 2 core WiFi BLE BT
buildenv: openevse_esp-wrover-kit
buildenv: espressif_esp-wrover-kit
version: 4.1.0.dev
diode_check: true
gfci_check: true
Expand Down Expand Up @@ -329,7 +329,7 @@ properties:
default: 600
description: |
The maximum number of seconds to randomly add/subtract from the a scheduled charge start time, eg a value of 600 will adjust the start time my +/- 10 minutes. This is to help prevent large syncrinised loads when multiple verchiles start charging at the same time.
is_threephase:
is_threephase:
type: boolean
description: |
Needs to be enabled if charging with 3 phases setup for proper calculations
Expand Down
3 changes: 3 additions & 0 deletions models/Status.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,6 @@ properties:
limit_version:
type: integer
description: /limit endpoint current version
uptime:
type: integer
description: EVSE gateway uptime, in seconds
42 changes: 21 additions & 21 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ lib_deps =
matth-x/[email protected]
matth-x/[email protected]
lib_ignore = WebSockets ; ArduinoOcpp: don't compile built-in WS library
extra_scripts =
extra_scripts =
pre:scripts/auto_fw_version.py
scripts/extra_script.py
debug_flags =
Expand Down Expand Up @@ -129,7 +129,7 @@ monitor_speed = 115200
monitor_filters =
esp32_exception_decoder

[env:openevse_nodemcu-32s]
[env:nodemcu-32s]
board = nodemcu-32s
build_flags =
${common.build_flags}
Expand All @@ -139,7 +139,7 @@ build_flags =
-D WIFI_LED_ON_STATE=LOW
-D RAPI_PORT=Serial2

[env:openevse_esp-wrover-kit]
[env:espressif_esp-wrover-kit]
board = esp-wrover-kit
lib_deps =
${common.lib_deps}
Expand Down Expand Up @@ -169,11 +169,11 @@ upload_speed = 2000000
# export PLATFORMIO_UPLOAD_FLAGS="-p 3232"


[env:openevse_esp-wrover-kit_latest]
extends = env:openevse_esp-wrover-kit
[env:espressif_esp-wrover-kit_latest]
extends = env:espressif_esp-wrover-kit
platform = espressif32

[env:openevse_huzzah32_dev]
[env:adafruit_huzzah32_dev]
board = featheresp32
build_flags =
${common.build_flags}
Expand All @@ -186,7 +186,7 @@ build_flags =
-D RAPI_PORT=Serial
-D DEBUG_PORT=Serial2

[env:openevse_huzzah32]
[env:adafruit_huzzah32]
board = featheresp32
build_flags =
${common.build_flags}
Expand All @@ -198,7 +198,7 @@ build_flags =
-D RAPI_PORT=Serial
-D DEBUG_PORT=Serial2

[env:openevse_featheresp32]
[env:adafruit_featheresp32]
board = featheresp32
build_flags =
${common.build_flags}
Expand Down Expand Up @@ -233,7 +233,7 @@ build_flags =
-D TX1=16
upload_command = curl -F firmware=@$SOURCE http://$UPLOAD_PORT/update --progress-bar | cat

[env:openevse_esp32-gateway-old]
[env:olimex_esp32-gateway-old]
# For hardware older than RevE
board = esp32-gateway
build_flags =
Expand All @@ -248,7 +248,7 @@ build_flags =
-D ENABLE_WIRED_ETHERNET
# https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/ETH_LAN8720/ETH_LAN8720.ino

[env:openevse_esp32-gateway-f]
[env:olimex_esp32-gateway-f]
# For hardware RevF and RevG
# https://github.com/OpenEVSE/ESP32_WiFi_V3.x/blob/master/docs/wired-ethernet.md
board = esp32-gateway
Expand All @@ -268,31 +268,31 @@ build_flags =
board_build.extra_flags = "-DARDUINO_ESP32_GATEWAY=\'F\'"
upload_speed = 921600

[env:openevse_esp32-gateway-e]
[env:olimex_esp32-gateway-e]
# For hardware RevE
# https://github.com/OpenEVSE/ESP32_WiFi_V3.x/blob/master/docs/wired-ethernet.md
extends = env:openevse_esp32-gateway-f
extends = env:olimex_esp32-gateway-f
build_flags =
${env:openevse_esp32-gateway-f.build_flags}
${env:olimex_esp32-gateway-f.build_flags}
board_build.extra_flags = "-DARDUINO_ESP32_GATEWAY=\'E\'"

[env:openevse_esp32-gateway-e_dev]
extends = env:openevse_esp32-gateway-e
[env:olimex_esp32-gateway-e_dev]
extends = env:olimex_esp32-gateway-e
build_flags =
${env:openevse_esp32-gateway-e.build_flags}
${env:olimex_esp32-gateway-e.build_flags}
${common.debug_flags}
build_type = debug
board_build.partitions = ${common.build_partitions_debug}

[env:openevse_esp32-gateway-f_dev]
extends = env:openevse_esp32-gateway-f
[env:olimex_esp32-gateway-f_dev]
extends = env:olimex_esp32-gateway-f
build_flags =
${env:openevse_esp32-gateway-f.build_flags}
${env:olimex_esp32-gateway-f.build_flags}
${common.debug_flags}
build_type = debug
board_build.partitions = ${common.build_partitions_debug}

[env:openevse_esp32-poe-iso]
[env:olimex_esp32-poe-iso]
# Tested against Rev C board
board = esp32-poe-iso
build_flags =
Expand All @@ -306,7 +306,7 @@ build_flags =
-D RESET_ETH_PHY_ON_BOOT=1
upload_speed = 921600

[env:openevse_esp32-heltec-wifi-lora-v2]
[env:heltec_esp32-wifi-lora-v2]
board = heltec_wifi_lora_32_V2
build_flags =
${common.build_flags}
Expand Down
10 changes: 5 additions & 5 deletions prepare-release.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/bin/bash

# Script to compile all released enviroments and copy build artifacts to project root for easy upload to github releases.
# Script to compile all released enviroments and copy build artifacts to project root for easy upload to github releases.

pio run -e openevse_wifi_v1
cp .pio/build/openevse_wifi_v1/firmware.bin firmware.bin

pio run -e openevse_huzzah32
cp .pio/build/openevse_wifi_v1/firmware.bin openevse_huzzah32.bin
pio run -e adafruit_huzzah32
cp .pio/build/openevse_wifi_v1/firmware.bin adafruit_huzzah32.bin

pio run -e openevse_esp32-gateway-e
pio run -e olimex_esp32-gateway-e
cp .pio/build/openevse_wifi_v1/firmware.bin esp32-gateway-e.bin

echo "Done"
echo "Done"



2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OpenEVSE WiFi ESP32 Gateway v4
# OpenEVSE WiFi for ESP32

> **_NOTE:_** Breaking change! This release reccomends a minimum of [7.1.3](https://github.com/OpenEVSE/open_evse/releases) of the OpenEVSE firmware, features including Solar Divert and push button menus may not behave as expected on older firmware.
Expand Down
2 changes: 2 additions & 0 deletions src/emonesp.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,6 @@ extern String serial;

void restart_system();

uint64_t uptimeMillis();

#endif // _EMONESP_H
12 changes: 12 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ void
loop() {
Profile_Start(loop);

uptimeMillis();

Profile_Start(Mongoose);
Mongoose.poll(0);
Profile_End(Mongoose, 10);
Expand Down Expand Up @@ -340,3 +342,13 @@ void handle_serial()
}
}
}

// inspired from https://www.snad.cz/en/2018/12/21/uptime-and-esp8266/
uint64_t uptimeMillis()
{
static uint32_t low32, high32;
uint32_t new_low32 = millis();
if (new_low32 < low32) high32++;
low32 = new_low32;
return (uint64_t) high32 << 32 | low32;
}
19 changes: 19 additions & 0 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ void mqttmsg_callback(MongooseString topic, MongooseString payload) {
}
}

else if (topic_string == mqtt_topic + "/config/set") {
const size_t capacity = JSON_OBJECT_SIZE(128) + 1024;
DynamicJsonDocument doc(capacity);
DeserializationError error = deserializeJson(doc, payload_str);
if(!error)
{
bool config_modified = config_deserialize(doc);
if(config_modified)
{
config_commit(false);
DBUGLN("Config updated");
}
}
}

// Restart
else if (topic_string == mqtt_topic + "/restart") {
mqtt_restart_device(payload_str);
Expand Down Expand Up @@ -386,6 +401,10 @@ mqtt_connect()
mqttclient.subscribe(mqtt_sub_topic);
yield();

mqtt_sub_topic = mqtt_topic + "/config/set";
mqttclient.subscribe(mqtt_sub_topic);
yield();

// ask for a system restart
mqtt_sub_topic = mqtt_topic + "/restart";
mqttclient.subscribe(mqtt_sub_topic);
Expand Down
1 change: 1 addition & 0 deletions src/time_man.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,5 @@ void TimeManager::serialise(JsonDocument &doc)
doc["time"] = time;
doc["local_time"] = local_time;
doc["offset"] = offset;
doc["uptime"] = uptimeMillis() / 1000;
}
Loading

0 comments on commit d636dd7

Please sign in to comment.