Merge branch 'dalathegreat:main' into main

This commit is contained in:
amarofarinha 2024-05-29 20:27:53 +01:00 committed by GitHub
commit a961a5d8d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 197 additions and 188 deletions

View file

@ -39,12 +39,12 @@ For more examples showing wiring, see each battery types own Wiki page. For inst
1. Download the Arduino IDE: https://www.arduino.cc/en/software
2. When the Arduino IDE has been started;
Click "File" in the upper left corner -> Preferences -> Additional Development >Board Manager URL -> Enter the URL in the input box https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
3. Go to "Boards Manager", and install the ESP32 package by Espressif Systems. **The latest confirmed compatible version is 2.0.11**
3. Go to "Boards Manager", and install the ESP32 package by Espressif Systems. **NOTE: The version depends on which release of Battery-Emulator you are running!**
⚠️ Make sure to use a 2.x.x version - preferably 2.0.11 - and not a 3.x.x version, as it is not yet supported by the libraries we include with the SW!
![image](https://github.com/dalathegreat/Battery-Emulator/assets/81711263/79602ef1-1a23-4670-a638-b896b7f6cdf6)
- ⚠️ Make sure to use a 2.x.x version if you are on a release **older** than 6.0.0 (For instance ESP32 v2.0.11 when using Battery-Emulator v5.4.0)
- ⚠️ Make sure to use a 3.x.x version if you are on a release **newer** than 6.0.0 (For instance ESP32 v3.0.0 when using Battery-Emulator v6.0.0)
For future migration, see this link: https://docs.espressif.com/projects/arduino-esp32/en/latest/migration_guides/2.x_to_3.0.html
![bild](https://github.com/dalathegreat/Battery-Emulator/assets/26695010/6a2414b1-f2ca-4746-8e8d-9afd78bd9252)
4. The arduino settings should be set to "ESP32 Dev Module" with the following settings;
![alt text](https://github.com/Xinyuan-LilyGO/T-CAN485/blob/main/img/arduino_setting.png)

View file

@ -33,7 +33,7 @@
Preferences settings; // Store user settings
// The current software version, shown on webserver
const char* version_number = "5.11.dev";
const char* version_number = "6.0.RC";
// Interval settings
uint16_t intervalUpdateValues = INTERVAL_5_S; // Interval at which to update inverter values / Modbus registers

View file

@ -16,6 +16,7 @@ static unsigned long previousMillis10s = 0; // will store last time a 1s CAN Me
static uint8_t mprun10r = 0; //counter 0-20 for 0x1F2 message
static uint8_t mprun10 = 0; //counter 0-3
static uint8_t mprun100 = 0; //counter 0-3
static bool can_bus_alive = false;
CAN_frame_t LEAF_1F2 = {.FIR = {.B =
{
@ -337,6 +338,7 @@ void update_values_battery() { /* This function maps all the values fetched via
void receive_can_battery(CAN_frame_t rx_frame) {
switch (rx_frame.MsgID) {
case 0x1DB:
can_bus_alive = true;
if (is_message_corrupt(rx_frame)) {
datalayer.battery.status.CAN_error_counter++;
break; //Message content malformed, abort reading data from it
@ -585,6 +587,8 @@ void receive_can_battery(CAN_frame_t rx_frame) {
}
}
void send_can_battery() {
if (can_bus_alive) {
unsigned long currentMillis = millis();
//Send 10ms message
@ -770,6 +774,7 @@ void send_can_battery() {
stop_battery_query = false;
}
}
}
}
bool is_message_corrupt(CAN_frame_t rx_frame) {

View file

@ -50,7 +50,7 @@ void handle_static_data_modbus_byd() {
}
void handle_update_data_modbusp201_byd() {
mbPV[202] = std::min(datalayer.battery.info.total_capacity_Wh, 60000u); //Cap capacity to 60kWh if needed
mbPV[202] = std::min(datalayer.battery.info.total_capacity_Wh, static_cast<uint32_t>(60000u)); //Cap to 60kWh
mbPV[205] = (datalayer.battery.info.max_design_voltage_dV); // Max Voltage, if higher Gen24 forces discharge
mbPV[206] = (datalayer.battery.info.min_design_voltage_dV); // Min Voltage, if lower Gen24 disables battery
}
@ -83,10 +83,10 @@ void handle_update_data_modbusp301_byd() {
mbPV[300] = datalayer.battery.status.bms_status;
mbPV[302] = 128 + bms_char_dis_status;
mbPV[303] = datalayer.battery.status.reported_soc;
mbPV[304] = std::min(datalayer.battery.info.total_capacity_Wh, 60000u); //Cap capacity to 60kWh if needed
mbPV[305] = std::min(datalayer.battery.status.remaining_capacity_Wh, 60000u); //Cap capacity to 60kWh if needed
mbPV[306] = std::min(max_discharge_W, 30000u); //Cap to 30000 if exceeding
mbPV[307] = std::min(max_charge_W, 30000u); //Cap to 30000 if exceeding
mbPV[304] = std::min(datalayer.battery.info.total_capacity_Wh, static_cast<uint32_t>(60000u)); //Cap to 60kWh
mbPV[305] = std::min(datalayer.battery.status.remaining_capacity_Wh, static_cast<uint32_t>(60000u)); //Cap to 60kWh
mbPV[306] = std::min(max_discharge_W, static_cast<uint32_t>(30000u)); //Cap to 30000 if exceeding
mbPV[307] = std::min(max_charge_W, static_cast<uint32_t>(30000u)); //Cap to 30000 if exceeding
mbPV[310] = datalayer.battery.status.voltage_dV;
mbPV[312] = datalayer.battery.status.temperature_min_dC;
mbPV[313] = datalayer.battery.status.temperature_max_dC;

View file

@ -185,7 +185,7 @@ void AsyncEventSourceClient::_queueMessage(AsyncEventSourceMessage *dataMessage)
return;
}
if(_messageQueue.length() >= SSE_MAX_QUEUED_MESSAGES){
ets_printf("ERROR: Too many messages queued\n");
//ets_printf("ERROR: Too many messages queued\n");
delete dataMessage;
} else {
_messageQueue.add(dataMessage);

View file

@ -548,7 +548,7 @@ void AsyncWebSocketClient::_queueMessage(AsyncWebSocketMessage *dataMessage){
return;
}
if(_messageQueue.length() >= WS_MAX_QUEUED_MESSAGES){
ets_printf("ERROR: Too many messages queued\n");
//ets_printf("ERROR: Too many messages queued\n");
delete dataMessage;
} else {
_messageQueue.add(dataMessage);
@ -829,7 +829,7 @@ void AsyncWebSocketClient::binary(AsyncWebSocketMessageBuffer * buffer)
IPAddress AsyncWebSocketClient::remoteIP() {
if(!_client) {
return IPAddress(0U);
return IPAddress(static_cast<uint32_t>(0U));
}
return _client->remoteIP();
}
@ -1259,9 +1259,9 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket
(String&)key += WS_STR_UUID;
mbedtls_sha1_context ctx;
mbedtls_sha1_init(&ctx);
mbedtls_sha1_starts_ret(&ctx);
mbedtls_sha1_update_ret(&ctx, (const unsigned char*)key.c_str(), key.length());
mbedtls_sha1_finish_ret(&ctx, hash);
mbedtls_sha1_starts(&ctx);
mbedtls_sha1_update(&ctx, (const unsigned char*)key.c_str(), key.length());
mbedtls_sha1_finish(&ctx, hash);
mbedtls_sha1_free(&ctx);
#endif
base64_encodestate _state;

View file

@ -71,9 +71,9 @@ static bool getMD5(uint8_t * data, uint16_t len, char * output){//33 bytes or mo
memset(_buf, 0x00, 16);
#ifdef ESP32
mbedtls_md5_init(&_ctx);
mbedtls_md5_starts_ret(&_ctx);
mbedtls_md5_update_ret(&_ctx, data, len);
mbedtls_md5_finish_ret(&_ctx, _buf);
mbedtls_md5_starts(&_ctx);
mbedtls_md5_update(&_ctx, data, len);
mbedtls_md5_finish(&_ctx, _buf);
#else
MD5Init(&_ctx);
MD5Update(&_ctx, data, len);

View file

@ -34,7 +34,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "esp_intr.h"
#include "esp_intr_alloc.h" // Renamed when migrating ESP32 2.x -> 3.x
#include "soc/dport_reg.h"
#include <math.h>
@ -43,6 +43,10 @@
#include "can_regdef.h"
#include "CAN_config.h"
#define TWAI_TX_IDX 123 // TODO: Are these OK?
// not sure what file is needed now, maybe "soc/gpio_sig_map.h" but using hard coded values for now
#define TWAI_RX_IDX 94 // TODO: Are these OK?
// CAN Filter - no acceptance filter
static CAN_filter_t __filter = { Dual_Mode, 0, 0, 0, 0, 0Xff, 0Xff, 0Xff, 0Xff };
@ -177,12 +181,12 @@ int CAN_init() {
// configure TX pin
gpio_set_level(CAN_cfg.tx_pin_id, 1);
gpio_set_direction(CAN_cfg.tx_pin_id, GPIO_MODE_OUTPUT);
gpio_matrix_out(CAN_cfg.tx_pin_id, CAN_TX_IDX, 0, 0);
gpio_matrix_out(CAN_cfg.tx_pin_id, TWAI_TX_IDX, 0, 0);
gpio_pad_select_gpio(CAN_cfg.tx_pin_id);
// configure RX pin
gpio_set_direction(CAN_cfg.rx_pin_id, GPIO_MODE_INPUT);
gpio_matrix_in(CAN_cfg.rx_pin_id, CAN_RX_IDX, 0);
gpio_matrix_in(CAN_cfg.rx_pin_id, TWAI_RX_IDX, 0);
gpio_pad_select_gpio(CAN_cfg.rx_pin_id);
// set to PELICAN mode