Skip to content

Commit

Permalink
merge pr-16 with some improvements thanks to blenk92
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Lukas committed Jan 21, 2023
2 parents e5e7da9 + 787ad9e commit 7869998
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
16 changes: 15 additions & 1 deletion Bluetti_ESP32/BWifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <ESPAsyncWebServer.h> // https://github.com/me-no-dev/ESPAsyncWebServer/archive/master.zip
#include <AsyncTCP.h> // https://github.com/me-no-dev/AsyncTCP/archive/master.zip
#include <ESPmDNS.h>
#include <AsyncElegantOTA.h>

AsyncWebServer server(80);
AsyncEventSource events("/events");
Expand All @@ -31,6 +32,7 @@ ESPBluettiSettings wifiConfig;

ESPBluettiSettings get_esp32_bluetti_settings(){
return wifiConfig;
return wifiConfig;
}

void eeprom_read(){
Expand All @@ -57,6 +59,8 @@ void initBWifi(bool resetWifi){
WiFiManagerParameter custom_mqtt_port("port", "MQTT Server Port", mqtt_port, 6);
WiFiManagerParameter custom_mqtt_username("username", "MQTT Username", "", 40);
WiFiManagerParameter custom_mqtt_password("password", "MQTT Password", "", 40, "type=password");
WiFiManagerParameter custom_ota_username("ota_username", "OTA Username", "", 40);
WiFiManagerParameter custom_ota_password("ota_password", "OTA Password", "", 40, "type=password");
WiFiManagerParameter custom_bluetti_device("bluetti", "Bluetti Bluetooth ID", bluetti_device_id, 40);

WiFiManager wifiManager;
Expand All @@ -80,6 +84,8 @@ void initBWifi(bool resetWifi){
wifiManager.addParameter(&custom_mqtt_port);
wifiManager.addParameter(&custom_mqtt_username);
wifiManager.addParameter(&custom_mqtt_password);
wifiManager.addParameter(&custom_ota_username);
wifiManager.addParameter(&custom_ota_password);
wifiManager.addParameter(&custom_bluetti_device);

if (!wifiManager.autoConnect("Bluetti_ESP32")) {
Expand All @@ -91,6 +97,8 @@ void initBWifi(bool resetWifi){
strlcpy(wifiConfig.mqtt_port, custom_mqtt_port.getValue(), 6);
strlcpy(wifiConfig.mqtt_username, custom_mqtt_username.getValue(), 40);
strlcpy(wifiConfig.mqtt_password, custom_mqtt_password.getValue(), 40);
strlcpy(wifiConfig.ota_username, custom_ota_username.getValue(), 40);
strlcpy(wifiConfig.ota_password, custom_ota_password.getValue(), 40);
strlcpy(wifiConfig.bluetti_device_id, custom_bluetti_device.getValue(), 40);
eeprom_saveconfig();
}
Expand Down Expand Up @@ -133,7 +141,13 @@ void initBWifi(bool resetWifi){
client->send("hello my friend, I'm just your data feed!", NULL, millis(), 10000);
});
server.addHandler(&events);


if (!wifiConfig.ota_username) {
AsyncElegantOTA.begin(&server);
} else {
AsyncElegantOTA.begin(&server, wifiConfig.ota_username, wifiConfig.ota_password);
}

server.begin();
Serial.println(F("HTTP server started"));

Expand Down
2 changes: 2 additions & 0 deletions Bluetti_ESP32/BWifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ typedef struct{
char mqtt_username[40] = "";
char mqtt_password[40] = "";
char bluetti_device_id[40] = "Bluetti Blutetooth Id";
char ota_username[40] = "";
char ota_password[40] = "";
} ESPBluettiSettings;

extern ESPBluettiSettings get_esp32_bluetti_settings();
Expand Down
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Join the Discord Server https://discord.gg/6ukb8rnk
* easy configuration with WiFi manager
* mqtt support
* support for BLUETTI power stations
* AC300 (tested)
* AC300 (tested)
* AC200 (untested)
* EB3A (tested)
* EB3A (tested)
* EP500 (untested)
* EP500P (tested)
* supported BLUETTI functions
Expand Down Expand Up @@ -41,18 +41,19 @@ You will need to install a board support package for your ESP32. Additionally th

* https://github.com/tzapu/WiFiManager
* https://github.com/knolleary/pubsubclient
* https://github.com/ayushsharma82/ElegantOTA
* https://github.com/me-no-dev/ESPAsyncWebServer
* https://github.com/me-no-dev/AsyncTCP/archive

Change the partition scheme with Tools -> Partition Scheme to
Change the partition scheme with Tools -> Partition Scheme to

* Minimal SPIFFS (1.9 MB App with OTA/ 190KB SPIFFS)

![Wifi Manager start menu](doc/images/partition.png)

This setting is required because the Bluetooth stack already uses a lot of the ESP32 memory.
This setting is required because the Bluetooth stack already uses a lot of the ESP32 memory.

Optional: Do changes in config.h file. The device can be set by changing 'BLUETTI_TYPE'.
Optional: Do changes in config.h file. The device can be set by changing 'BLUETTI_TYPE'.

Finally upload the Sketch to your ESP32.

Expand All @@ -67,7 +68,7 @@ $ pio run

Flashing Factory Image
```
$ esptool.py write_flash 0x0 build/Bluetti_ESP32_Bridge.factory.bin
$ esptool.py write_flash 0x0 build/Bluetti_ESP32_Bridge.factory.bin
```

Updating only App (don't delete settings)
Expand All @@ -79,41 +80,42 @@ $ esptool.py write_flash 0x10000 build/Bluetti_ESP32_Bridge.ota.bin
$ esptool.py write_flash 0x1F0000 build/Bluetti_ESP32_Bridge.ota.bin
```

The configuration interface also offers OTA updates. You can flash also `build/Bluetti_ESP32_Bridge.ota.bin` there.
The configuration interface also offers OTA updates. You can flash also `build/Bluetti_ESP32_Bridge.ota.bin` there. If you already configured your device you can use `http://<ip_address/update` to update your firmware (no-reconfiguration needed)

### Usage

Just connect the ESP32 to a power supply or the power station itself. Connect your mobile phone or computer
to the Wifi mangaer of the ESP32 firmware, it should show up as "ESP32_Bluetti".

After the connection to the hotspot is established a wifi manager popup will appear. Otherwise
open 192.168.4.1 in your local webbrowser.
open 192.168.4.1 in your local webbrowser.

Select "Configure WiFi"

![Wifi Manager start menu](doc/images/wifi_manager.png)

Configure your WiFi and set the address of your MQTT server and enter the Bluetooth ID of your
Bluetti Device. You can use a mobile phone and/or the Bluetti APP for finding the correct Bluetooth ID of your device.
Configure your WiFi and set the address of your MQTT server and enter the Bluetooth ID of your
Bluetti Device. Optionally you can specify username and password to protect the web OTA interface.
You can use a mobile phone and/or the Bluetti APP for finding the correct Bluetooth ID of your device.

![Wifi Manager start menu](doc/images/wifi_setup.png)

Save the settings. The ESP32 starts sending messages to your MQTT server.
Save the settings. The ESP32 starts sending messages to your MQTT server.

Example ( ioBroker ):
![MQTT ioBroker](doc/images/iobroker.png)

### MQTT Topics

#### Commands
Commands are subscribed from
Commands are subscribed from

* /bluetti/<your_device_id>/command
* ac_output_on
* dc_output_on

#### State
States are published to
States are published to
* /bluetti/<your_device_id>/state
* ac_output_on
* dc_output_on
Expand All @@ -126,7 +128,7 @@ States are published to
* arm_version
* power_generation
* total_battery_percent


## TODO

Expand Down
Binary file modified doc/images/wifi_setup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ lib_deps =
https://github.com/tzapu/WiFiManager/archive/refs/tags/v2.0.15-rc.1.zip
PubSubClient@^2.8.0
https://github.com/me-no-dev/ESPAsyncWebServer/archive/master.zip
AsyncElegantOTA@^2.2.7

extra_scripts = post:scripts/post_esp32.py

[env:esp32dev]
Expand Down

0 comments on commit 7869998

Please sign in to comment.