Skip to content

Commit

Permalink
Add wifi manager and .bin flash howto
Browse files Browse the repository at this point in the history
  • Loading branch information
Bettapro committed Oct 27, 2021
1 parent bfe4ae8 commit b3d0c33
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

# Visual Studio Code.pio
.vscode

#build folder
binFiles
41 changes: 3 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ What you got with v3:
3. automatic **time sync** between the ESP and the controller on each boot, using NTP time
4. **platformio** support
5. **ESP32** support
6. possibility for future expansion (more solar charge controllers with different communication protocol/channel)

6. **Configuration over wifi**, no needs to compile the code (if you don't want to)
7. ready for future expansion (more solar charge controllers with different communication protocol/channel)

Feel free to make pull requests if you wish to help improving.
There is also a support forum on the Blynk community forums: http://community.blynk.cc/t/epsolar-tracer-2210a-charge-controller-blynk-epic-solar-monitor/10596

You are welcome for suggestions, bugreports, and of course any further improvements of this code.

## Solar Controller Supported

Expand All @@ -32,36 +33,13 @@ There is also a support forum on the Blynk community forums: http://community.bl
![Tracer-AN](images/tracer-a.png)
![Tracer-BN](images/tracer-b.png)


## Sample screenshot

## V3
![Realtime data screen v3](images/screenshot-blynk_v3_realtime.png)
![Battery data screen v3](images/screenshot-blynk_v3_battery.png)
![PV data screen v3](images/screenshot-blynk_v3_pv.png)
![Settings screen v3](images/screenshot-blynk_v3_settings.png)

## V2
![Live data on Blynk on Android screenshot](images/screenshot-blynk.png)


## Software required

* [Blynk](http://www.blynk.cc/) Mobile App ([iOS](https://itunes.apple.com/us/app/blynk-iot-for-arduino-rpi/id808760481?mt=8) & [Android](https://play.google.com/store/apps/details?id=cc.blynk&hl=en))
* Arduino IDE 1.6.9+ or Platformio (visual studio code)
* This project

## Setup

### Libraries [Arduino IDE only]

Follow links to get them.

* [Blynk Library](https://github.com/blynkkk/blynk-library)
* [ArduinoOTA](https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA)
* [SimpleTimer](https://github.com/schinken/SimpleTimer)
* [ModbusMaster](https://github.com/4-20ma/ModbusMaster) - requires my ModbusMaster fork, available [here](https://github.com/Bettapro/ModbusMaster)

## Tutorial

Refer to [Sw_getting_started.md](docs/Sw_getting_started.md)
Expand All @@ -70,19 +48,6 @@ Some details:
- ESP8266 + MAX485 + EPEVER Solar Tracer [HOW TO](docs/Esp8266_max485_epever_rj45.md)
- ESP32 + MAX485 + EPEVER Solar Tracer [HOW TO](docs/Esp32_max485_epever_rj45.md)


## Reference

* [Tracer A/B Series MPPT Solar Controller - Modbus Protocol](images/1733_modbus_protocol.pdf)

## Developing further

> I plan to add a default configs to make the setup easier
> I'd make the values optional (you can choose the values to monitor)
> I'd use external current sensor to measure high current absorption
You are welcome for suggestions, bugreports, and of course any further improvements of this code.

## Credits

- `@jaminNZx:`
Expand Down
89 changes: 77 additions & 12 deletions docs/Sw_getting_started.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,62 @@
# SW getting started

## 1. Prepare your IDE
## 1a. Flash a pre-built firmware
Download the most recent version of the firmware https://github.com/Bettapro/Solar-Tracer-Blynk-V3/releases .

Download the correct bif file dependeing on the board you're gonna use:
- SolarTracerBlynk_3.x.x_esp32dev_FULL.bin - full bin file to use on a ESP32 (it includes all the bin needed eg: bootloader, firmware ...), use it on the very first setup.
- SolarTracerBlynk_3.x.x_esp8266.bin - bin file to use on a ESP8266.

Download [esp_flash_download_tool](https://www.espressif.com/en/support/download/other-tools).

Start esp_flash_download_tool and select the correct board

![esp_tool_board_select](../images/esp_tool_board_select.png)

Load the bin downloaded, set the address to 0x0000, and press START.

![esp_tool_board_select](../images/esp_tool_bin_flash_new.png)

**You board is ready!**

## 1b. Build manually
Download the most recent version of this project https://github.com/Bettapro/Solar-Tracer-Blynk-V3/releases

Open you favorite IDE:
- Arduino IDE: open *SolarTracerBlynk* folder, then open *SolarTracerBlynk.ino* .
- Platformio: import the project using *platformio.ini* .

### Libraries to include in Arduino IDE


* [Blynk Library](https://github.com/blynkkk/blynk-library)
* [ArduinoOTA](https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA)
* [SimpleTimer](https://github.com/schinken/SimpleTimer)
* [ModbusMaster_obj](https://github.com/Bettapro/ModbusMaster)
* [WiFiManager](https://github.com/tzapu/WiFiManager)
* [ArduinoJson](https://github.com/bblanchon/ArduinoJson)

### Edit `config.h` library
Open `SolarTracerBlynk\config.h`

* Enter your WiFi credentials in `WIFI_SSID` and `WIFI_PASS`.
* Send yourself the generated auth code from the mobile app
* Paste your auth code into `BLYNK_AUTH`

You can customize further more modifying config.h (eg. status LED, ntp time sync, blynk serve ...), each option is documented on the config.h file.
Please refer to the notes written on it.

### Upload firmware

Upload the sketch to your ESP8266 / ESP32, if you are using platformio you should edit `default_envs` accordingly (eg: *esp8266* to use a esp8266, *esp8266_ota* to update ESP8266 via OTA, *esp32dev* to use and ESP32, .... )

**You board is ready!**

## 2. Mobile App

Open the Blynk mobile app and create a new project by scanning the following QR code
Get the Mobile App ([iOS](https://itunes.apple.com/us/app/blynk-iot-for-arduino-rpi/id808760481?mt=8) & [Android](https://play.google.com/store/apps/details?id=cc.blynk&hl=en))

Open the Blynk mobile app and create a new project by scanning the following QR code

### Legacy app (v3) - SUGGESTED
Current version of the app, complete overview of the solar charge controller.
Expand All @@ -23,18 +68,38 @@ Original version of the mobile app, shows a small set of data.

![Project QR Code](../images/blynk-app-qr-code.png)

## 3. Edit `config.h` library
Open `SolarTracerBlynk\config.h`
Click PLAY on you mobile app, you should start receiving updates from your solar tracer!.

* Enter your WiFi credentials in `WIFI_SSID` and `WIFI_PASS`.
* Send yourself the generated auth code from the mobile app
* Paste your auth code into `BLYNK_AUTH`
## 3. Wifi Configuration (SETUP MODE)

You can customize further more modifying config.h (eg. status LED, ntp time sync, blynk serve ...), each option is documented on the config.h file.
Please refer to the notes written on it.
You can configure your board via a web interface.

Device will try to connect to your wifi network, if the connection fails, it will turn to AP mode and create a new wifi network.
You can trigger the setup mode by putting in HIGH status (3.3v) pin 19 for few seconds(default value, check your config.h) just after you pressed the reset button.

## 4. Edit `config.h` library
Upload the sketch to your ESP8266 / ESP32, if you are using platformio you should edit `default_envs` accordingly (eg: *esp8266* to use a esp8266, *esp8266_ota* to update ESP8266 via OTA, *esp32dev* to use and ESP32, .... )
**NOTE:** ESP32 could switch to this mode using the hall sensor, just press the reset button and keep a magnet close to the board (please make sure this feature is enabled in your firmware)

Default values:
- WIFI SSID: SolarTracerAP
- WIFI PASSWORD: admin1234

Connect to this Wifi network, then oper a browser and go to http://192.168.4.1 .

![wifimanager_home](../images/wifi_manager_home.png)

Click on Configure and fill the form with your data.

![wifimanager_config](../images/wifi_manager_config.png)


## 4.Update
You can update your board just by compiling and flashing the new firmware as explained in point **1b** .

Otherwise, you should trigger the setup mode manually and you the UPDATE button.

Download the most recent version of the firmware https://github.com/Bettapro/Solar-Tracer-Blynk-V3/releases .
- SolarTracerBlynk_3.x.x_esp32dev.bin - ESP32 only
- SolarTracerBlynk_3.x.x_esp8266.bin - ESP8266 only

Load the bin file into the form shown and press update.

Click PLAY on you mobile app, you should start receiving updates from your solar tracer!.
Binary file added images/esp_tool_bin_flash_new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/esp_tool_board_select.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/wifi_manager_config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/wifi_manager_home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions script/binDeploy.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@echo off

RMDIR "binFiles" /S /Q

set VERSION_number="3.0.2"

set CURRENT_ENV=esp32dev
pio run -e %CURRENT_ENV%
echo F| xcopy ".pio\build\%CURRENT_ENV%\firmware.bin" "binFiles\%CURRENT_ENV%\firmware.bin" /v /f /y
echo F| xcopy ".pio\build\%CURRENT_ENV%\partitions.bin" "binFiles\%CURRENT_ENV%\partitions.bin" /v /f /y
echo F| xcopy "%userprofile%\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\bin\bootloader_dio_40m.bin" "binFiles\%CURRENT_ENV%\bootloader.bin" /v /f /y
echo F| xcopy "%userprofile%\.platformio\packages\framework-arduinoespressif32\tools\partitions\boot_app0.bin" "binFiles\%CURRENT_ENV%\boot_app0.bin" /v /f /y
python script\esp32_binary_merger\merge_bin_esp.py --output_folder binFiles\ --output_name "SolarTracerBlynk_%VERSION_NUMBER%_%CURRENT_ENV%_FULL.bin" --bin_path "binFiles\%CURRENT_ENV%\bootloader.bin" "binFiles\%CURRENT_ENV%\partitions.bin" "binFiles\%CURRENT_ENV%\boot_app0.bin" "binFiles\%CURRENT_ENV%\firmware.bin" --bin_address 0x1000 0x8000 0xe000 0x10000
echo F| xcopy "binFiles\%CURRENT_ENV%\firmware.bin" "binFiles\SolarTracerBlynk_%VERSION_NUMBER%_%CURRENT_ENV%.bin" /v /f /y

set CURRENT_ENV=esp8266
pio run -e %CURRENT_ENV%
rem 0x0 .pio\build\esp8266\firmware.bin
echo F| xcopy ".pio\build\%CURRENT_ENV%\firmware.bin" "binFiles\SolarTracerBlynk_%VERSION_NUMBER%_%CURRENT_ENV%.bin" /v /f /y

21 changes: 21 additions & 0 deletions script/esp32_binary_merger/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Tony Martinet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
85 changes: 85 additions & 0 deletions script/esp32_binary_merger/merge_bin_esp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import os
import argparse

class bin():
def __init__(self, file_path, addr):
self.file_path = file_path
self.file_name = os.path.basename(file_path)
self.addr = addr
self.size = self.get_size()

def get_size(self):
return int(os.path.getsize(self.file_path))

class multiple_bin():
def __init__(self, name, output_folder):
self.name = name
self.output_folder = output_folder
try:
os.makedirs(os.path.realpath(self.output_folder))
except:
pass
self.output_path = os.path.realpath(os.path.join(self.output_folder,self.name))
self.bin_array = []

def add_bin(self, file_path, addr):
self.bin_array.append(bin(file_path, addr))

def sort_bin(self):
swapped = True
while swapped:
swapped = False
for i in range(len(self.bin_array) - 1):
if self.bin_array[i].addr > self.bin_array[i + 1].addr:
self.bin_array[i], self.bin_array[i + 1] = self.bin_array[i + 1], self.bin_array[i]
swapped = True

def add_bin_to_other_bin(self, previous, binary):
with open(self.output_path, "ab") as output_file:
output_file.write( b'\xff' * (binary.addr-previous))
print ("Add %s from 0x%x to 0x%x (0x%x)"%(binary.file_name, binary.addr, binary.addr+binary.size, binary.size))
with open(self.output_path, "ab") as output_file, open(binary.file_path, "rb") as bin_file:
output_file.write(bin_file.read())
return binary.addr+binary.size

def create_bin(self):
new_start = 0
open(self.output_path, "wb").close
for b in self.bin_array:
new_start = self.add_bin_to_other_bin(new_start, b)

def check_if_possible(self):
for i in range(1, len(self.bin_array)):
if(self.bin_array[i].addr < (self.bin_array[i-1].addr+self.bin_array[i-1].size)):
print (self.bin_array[i].addr, (self.bin_array[i-1].addr+self.bin_array[i-1].size))
raise Exception("Not possible to create this bin, overlapping between %s and %s"%(self.bin_array[i].file_name, self.bin_array[i-1].file_name))

def main():
parser = argparse.ArgumentParser(description='Script to merge *.bin file at different position')
parser.add_argument(
'--output_name',
help = 'Output file name', default = "output.bin")
parser.add_argument(
'--output_folder', default = "output",
help = 'Output folder path')
parser.add_argument(
'--input_folder', default = "",
help = 'Input folder path')
parser.add_argument(
'--bin_path',nargs='+',required=True,
help = 'List of bin path, same order as bin_address (space seperated)')
parser.add_argument(
'--bin_address',nargs='+',type=lambda x: int(x,0),required=True,
help = 'List of addr, same order as bin_path (space seperated)')
parser.add_argument
args = parser.parse_args()
mb = multiple_bin(args.output_name, args.output_folder)
for path,address in zip(args.bin_path, args.bin_address):
mb.add_bin(os.path.join(args.input_folder, path), address)
mb.sort_bin()
mb.check_if_possible()
mb.create_bin()
print ("%s generated with success ! (size %u)"%(args.output_name, int(os.path.getsize(mb.output_path))))

if __name__ == "__main__":
exit(main())

0 comments on commit b3d0c33

Please sign in to comment.