Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Releasing last improvements #9

Merged
merged 5 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"cmake.configureOnOpen": false
"cmake.configureOnOpen": false,
"files.associations": {
"ranges": "cpp"
}
}
119 changes: 119 additions & 0 deletions dtuConst.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// constants converted from python constant file: https://raw.githubusercontent.com/suaveolent/hoymiles-wifi/main/hoymiles_wifi/const.py
//
// """Constants for the Hoymiles WiFi integration."""
//
#define DTU_PORT 10081
//
// # App -> DTU start with 0xa3, responses start 0xa2
const byte CMD_HEADER[] = {};
const byte CMD_APP_INFO_DATA_RES_DTO[] = {0xa3,0x01};
const byte CMD_HB_RES_DTO[] = {0xa3,0x02};
const byte CMD_REAL_DATA_RES_DTO[] = {0xa3,0x03};
const byte CMD_W_INFO_RES_DTO[] = {0xa3,0x04};
const byte CMD_COMMAND_RES_DTO[] = {0xa3,0x05};
const byte CMD_COMMAND_STATUS_RES_DTO[] = {0xa3,0x06};
const byte CMD_DEV_CONFIG_FETCH_RES_DTO[] = {0xa3,0x07};
const byte CMD_DEV_CONFIG_PUT_RES_DTO[] = {0xa3,0x08};
const byte CMD_GET_CONFIG[] = {0xa3,0x09};
const byte CMD_SET_CONFIG[] = {0xa3,0x10};
const byte CMD_REAL_RES_DTO[] = {0xa3,0x11};
const byte CMD_GPST_RES_DTO[] = {0xa3,0x12};
const byte CMD_AUTO_SEARCH[] = {0xa3,0x13};
const byte CMD_NETWORK_INFO_RES[] = {0xa3,0x14};
const byte CMD_APP_GET_HIST_POWER_RES[] = {0xa3,0x15};
const byte CMD_APP_GET_HIST_ED_RES[] = {0xa3,0x16};
const byte CMD_HB_RES_DTO_ALT[] = {0x83,0x01};
const byte CMD_REGISTER_RES_DTO[] = {0x83,0x02};
const byte CMD_STORAGE_DATA_RES[] = {0x83,0x03};
const byte CMD_COMMAND_RES_DTO_2[] = {0x83,0x05};
const byte CMD_COMMAND_STATUS_RES_DTO_2[] = {0x83,0x06};
const byte CMD_DEV_CONFIG_FETCH_RES_DTO_2[] = {0x83,0x07};
const byte CMD_DEV_CONFIG_PUT_RES_DTO_2[] = {0x83,0x08};
const byte CMD_GET_CONFIG_RES[] = {0xdb,0x08};
const byte CMD_SET_CONFIG_RES[] = {0xdb,0x07};
//
const byte CMD_CLOUD_INFO_DATA_RES_DTO[] = {0x23,0x01};
const byte CMD_CLOUD_COMMAND_RES_DTO[] = {0x23,0x05};
//
#define CMD_ACTION_MICRO_DEFAULT 0
#define CMD_ACTION_DTU_REBOOT 1
#define CMD_ACTION_DTU_UPGRADE 2
#define CMD_ACTION_MI_REBOOT 3
#define CMD_ACTION_COLLECT_VERSION 4
#define CMD_ACTION_ANTI_THEFT_SETTING 5
#define CMD_ACTION_MI_START 6
#define CMD_ACTION_MI_SHUTDOWN 7
#define CMD_ACTION_LIMIT_POWER 8
#define CMD_ACTION_REFLUX_CONTROL 9
#define CMD_ACTION_CLEAN_GROUNDING_FAULT 10
#define CMD_ACTION_CT_SET 11
#define CMD_ACTION_MI_LOCK 12
#define CMD_ACTION_MI_UNLOCK 13
#define CMD_ACTION_SET_GRID_FILE 14
#define CMD_ACTION_UPGRADE_MI 15
#define CMD_ACTION_ID_NETWORKING 16
#define CMD_ACTION_REFLUX_NETWORKING 17
#define CMD_ACTION_STOP_CONTROLLER_CMD 18
#define CMD_ACTION_SET_WIFI_PASS 19
#define CMD_ACTION_SET_SVR_DNS_PORT 20
#define CMD_ACTION_SET_GPRS_APN 21
#define CMD_ACTION_ANTI_THEFT_CONTROL 22
#define CMD_ACTION_REPEATER_NETWORKING 0
#define CMD_ACTION_DTU_DEFAULT 0
#define CMD_ACTION_GATEWAY_DEFAULT 0
#define CMD_ACTION_METER_REVERSE 49
#define CMD_ACTION_GW_REBOOT 4096
#define CMD_ACTION_GW_RESET 4097
#define CMD_ACTION_GW_STOP_RUN 4098
#define CMD_ACTION_GW_COLLECT_REAL_DATA 4099
#define CMD_ACTION_GW_COLLECT_VER 4100
#define CMD_ACTION_GW_AUTO_NETWORKING 4101
#define CMD_ACTION_GW_UPGRADE 4102
#define CMD_ACTION_MICRO_MEMORY_SNAPSHOT 53
#define CMD_ACTION_MICRO_DATA_WAVE 54
#define CMD_ACTION_SET_485_PORT 36
#define CMD_ACTION_THREE_BALANCE_SET 37
#define CMD_ACTION_MI_GRID_PROTECT_SELF 38
#define CMD_ACTION_SUN_SPEC_CONFIG 39
#define CMD_ACTION_POWER_GENERATION_CORRECT 40
#define CMD_ACTION_GRID_FILE_READ 41
#define CMD_ACTION_CLEAN_WARN 42
#define CMD_ACTION_DRM_SETTING 43
#define CMD_ACTION_ES_CONFIG_MANAGER 0
#define CMD_ACTION_ES_USER_SETTING 0
#define CMD_ACTION_READ_MI_HU_WARN 46
#define CMD_ACTION_LIMIT_POWER_PF 47
#define CMD_ACTION_LIMIT_POWER_REACTIVE 48
#define CMD_ACTION_INV_BOOT_UP 8193
#define CMD_ACTION_INV_SHUTDOWN 8194
#define CMD_ACTION_INV_REBOOT 8195
#define CMD_ACTION_INV_RESET 8196
#define CMD_ACTION_INV_CLEAN_WARN 8197
#define CMD_ACTION_INV_CLEAN_HIS_DATA 8198
#define CMD_ACTION_INV_UPLOAD_REAL_DATA 8199
#define CMD_ACTION_INV_FIND_DEV 8200
#define CMD_ACTION_INV_BATTERY_MODE_CONFIG 0
#define CMD_ACTION_BMS_REBOOT 8224
#define CMD_ACTION_BMS_URGENT_CHARGING 8225
#define CMD_ACTION_BMS_BALANCE 8208
#define CMD_ACTION_INV_UPGRADE 4112
#define CMD_ACTION_BMS_UPGRADE 4112
//
//
#define DEV_DTU 1
#define DEV_REPEATER 2
#define DEV_MICRO 3
#define DEV_MODEL 4
#define DEV_METER 5
#define DEV_INV 6
#define DEV_RSD 7
#define DEV_OP 8
#define DEV_GATEWAY 9
#define DEV_BMS 10
//
// DTU_FIRMWARE_URL_00_01_11 = (
// "http://fwupdate.hoymiles.com/cfs/bin/2311/06/,1488725943932555264.bin"
// )
//
#define MAX_POWER_LIMIT 100
//
119 changes: 119 additions & 0 deletions include/dtuConst.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// constants converted from python constants file: https://raw.githubusercontent.com/suaveolent/hoymiles-wifi/main/hoymiles_wifi/const.py
//
// """Constants for the Hoymiles WiFi integration."""
//
#define DTU_PORT 10081
//
// # App -> DTU start with 0xa3, responses start 0xa2
const byte CMD_HEADER[] = {};
const byte CMD_APP_INFO_DATA_RES_DTO[] = {0xa3,0x01};
const byte CMD_HB_RES_DTO[] = {0xa3,0x02};
const byte CMD_REAL_DATA_RES_DTO[] = {0xa3,0x03};
const byte CMD_W_INFO_RES_DTO[] = {0xa3,0x04};
const byte CMD_COMMAND_RES_DTO[] = {0xa3,0x05};
const byte CMD_COMMAND_STATUS_RES_DTO[] = {0xa3,0x06};
const byte CMD_DEV_CONFIG_FETCH_RES_DTO[] = {0xa3,0x07};
const byte CMD_DEV_CONFIG_PUT_RES_DTO[] = {0xa3,0x08};
const byte CMD_GET_CONFIG[] = {0xa3,0x09};
const byte CMD_SET_CONFIG[] = {0xa3,0x10};
const byte CMD_REAL_RES_DTO[] = {0xa3,0x11};
const byte CMD_GPST_RES_DTO[] = {0xa3,0x12};
const byte CMD_AUTO_SEARCH[] = {0xa3,0x13};
const byte CMD_NETWORK_INFO_RES[] = {0xa3,0x14};
const byte CMD_APP_GET_HIST_POWER_RES[] = {0xa3,0x15};
const byte CMD_APP_GET_HIST_ED_RES[] = {0xa3,0x16};
const byte CMD_HB_RES_DTO_ALT[] = {0x83,0x01};
const byte CMD_REGISTER_RES_DTO[] = {0x83,0x02};
const byte CMD_STORAGE_DATA_RES[] = {0x83,0x03};
const byte CMD_COMMAND_RES_DTO_2[] = {0x83,0x05};
const byte CMD_COMMAND_STATUS_RES_DTO_2[] = {0x83,0x06};
const byte CMD_DEV_CONFIG_FETCH_RES_DTO_2[] = {0x83,0x07};
const byte CMD_DEV_CONFIG_PUT_RES_DTO_2[] = {0x83,0x08};
const byte CMD_GET_CONFIG_RES[] = {0xdb,0x08};
const byte CMD_SET_CONFIG_RES[] = {0xdb,0x07};
//
const byte CMD_CLOUD_INFO_DATA_RES_DTO[] = {0x23,0x01};
const byte CMD_CLOUD_COMMAND_RES_DTO[] = {0x23,0x05};
//
#define CMD_ACTION_MICRO_DEFAULT 0
#define CMD_ACTION_DTU_REBOOT 1
#define CMD_ACTION_DTU_UPGRADE 2
#define CMD_ACTION_MI_REBOOT 3
#define CMD_ACTION_COLLECT_VERSION 4
#define CMD_ACTION_ANTI_THEFT_SETTING 5
#define CMD_ACTION_MI_START 6
#define CMD_ACTION_MI_SHUTDOWN 7
#define CMD_ACTION_LIMIT_POWER 8
#define CMD_ACTION_REFLUX_CONTROL 9
#define CMD_ACTION_CLEAN_GROUNDING_FAULT 10
#define CMD_ACTION_CT_SET 11
#define CMD_ACTION_MI_LOCK 12
#define CMD_ACTION_MI_UNLOCK 13
#define CMD_ACTION_SET_GRID_FILE 14
#define CMD_ACTION_UPGRADE_MI 15
#define CMD_ACTION_ID_NETWORKING 16
#define CMD_ACTION_REFLUX_NETWORKING 17
#define CMD_ACTION_STOP_CONTROLLER_CMD 18
#define CMD_ACTION_SET_WIFI_PASS 19
#define CMD_ACTION_SET_SVR_DNS_PORT 20
#define CMD_ACTION_SET_GPRS_APN 21
#define CMD_ACTION_ANTI_THEFT_CONTROL 22
#define CMD_ACTION_REPEATER_NETWORKING 0
#define CMD_ACTION_DTU_DEFAULT 0
#define CMD_ACTION_GATEWAY_DEFAULT 0
#define CMD_ACTION_METER_REVERSE 49
#define CMD_ACTION_GW_REBOOT 4096
#define CMD_ACTION_GW_RESET 4097
#define CMD_ACTION_GW_STOP_RUN 4098
#define CMD_ACTION_GW_COLLECT_REAL_DATA 4099
#define CMD_ACTION_GW_COLLECT_VER 4100
#define CMD_ACTION_GW_AUTO_NETWORKING 4101
#define CMD_ACTION_GW_UPGRADE 4102
#define CMD_ACTION_MICRO_MEMORY_SNAPSHOT 53
#define CMD_ACTION_MICRO_DATA_WAVE 54
#define CMD_ACTION_SET_485_PORT 36
#define CMD_ACTION_THREE_BALANCE_SET 37
#define CMD_ACTION_MI_GRID_PROTECT_SELF 38
#define CMD_ACTION_SUN_SPEC_CONFIG 39
#define CMD_ACTION_POWER_GENERATION_CORRECT 40
#define CMD_ACTION_GRID_FILE_READ 41
#define CMD_ACTION_CLEAN_WARN 42
#define CMD_ACTION_DRM_SETTING 43
#define CMD_ACTION_ES_CONFIG_MANAGER 0
#define CMD_ACTION_ES_USER_SETTING 0
#define CMD_ACTION_READ_MI_HU_WARN 46
#define CMD_ACTION_LIMIT_POWER_PF 47
#define CMD_ACTION_LIMIT_POWER_REACTIVE 48
#define CMD_ACTION_INV_BOOT_UP 8193
#define CMD_ACTION_INV_SHUTDOWN 8194
#define CMD_ACTION_INV_REBOOT 8195
#define CMD_ACTION_INV_RESET 8196
#define CMD_ACTION_INV_CLEAN_WARN 8197
#define CMD_ACTION_INV_CLEAN_HIS_DATA 8198
#define CMD_ACTION_INV_UPLOAD_REAL_DATA 8199
#define CMD_ACTION_INV_FIND_DEV 8200
#define CMD_ACTION_INV_BATTERY_MODE_CONFIG 0
#define CMD_ACTION_BMS_REBOOT 8224
#define CMD_ACTION_BMS_URGENT_CHARGING 8225
#define CMD_ACTION_BMS_BALANCE 8208
#define CMD_ACTION_INV_UPGRADE 4112
#define CMD_ACTION_BMS_UPGRADE 4112
//
//
#define DEV_DTU 1
#define DEV_REPEATER 2
#define DEV_MICRO 3
#define DEV_MODEL 4
#define DEV_METER 5
#define DEV_INV 6
#define DEV_RSD 7
#define DEV_OP 8
#define DEV_GATEWAY 9
#define DEV_BMS 10
//
// DTU_FIRMWARE_URL_00_01_11 = (
// "http://fwupdate.hoymiles.com/cfs/bin/2311/06/,1488725943932555264.bin"
// )
//
#define MAX_POWER_LIMIT 100
//
16 changes: 14 additions & 2 deletions include/dtuInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Arduino.h>
#include <UnixTime.h>
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>

#include "pb_encode.h"
#include "pb_decode.h"
Expand All @@ -24,6 +25,7 @@ const uint16_t dtuPort = 10081;
#define DTU_STATE_CONNECTED 1
#define DTU_STATE_CLOUD_PAUSE 2
#define DTU_STATE_TRY_RECONNECT 3
#define DTU_STATE_DTU_REBOOT 4

#define DTU_ERROR_NO_ERROR 0
#define DTU_ERROR_NO_TIME 1
Expand Down Expand Up @@ -65,21 +67,29 @@ struct inverterData
uint32_t respTimestamp = 1704063600; // init with start time stamp > 0
uint32_t lastRespTimestamp = 1704063600; // init with start time stamp > 0
boolean uptodate = false;
int dtuResetRequested = 0;
};

extern inverterData globalData;

extern CRC16 crc;
void dtuConnectionEstablish(WiFiClient *localDtuClient, char localDtuHostIp[16], uint16_t localDtuPort = 10081);
void dtuConnectionStop(WiFiClient *localDtuClient, uint8_t tgtState);
void dtuConnectionHandleError(WiFiClient *localDtuClient, unsigned long locTimeSec, uint8_t errorState = DTU_ERROR_NO_ERROR);

unsigned long getDtuRemoteTimeAndDataUpdate(WiFiClient *localDtuClient, unsigned long locTimeSec);
void printDataAsTextToSerial();
void printDataAsJsonToSerial();

void initializeCRC();
float calcValue(int32_t value, int32_t divider = 10);
String getTimeStringByTimestamp(unsigned long timestamp);
boolean preventCloudErrorTask(unsigned long locTimeSec);
boolean dtuCloudPauseActiveControl(unsigned long locTimeSec);

void readRespAppGetHistPower(WiFiClient *localDtuClient);
void writeReqAppGetHistPower(WiFiClient *localDtuClient, unsigned long locTimeSec);

void readRespRealDataNew(WiFiClient *localDtuClient);
void readRespRealDataNew(WiFiClient *localDtuClient, unsigned long locTimeSec);
void writeReqRealDataNew(WiFiClient *localDtuClient, unsigned long locTimeSec);

void readRespGetConfig(WiFiClient *localDtuClient);
Expand All @@ -88,5 +98,7 @@ void writeReqGetConfig(WiFiClient *localDtuClient, unsigned long locTimeSec);
boolean readRespCommand(WiFiClient *localDtuClient);
boolean writeReqCommand(WiFiClient *localDtuClient, uint8_t setPercent, unsigned long locTimeSec);

boolean readRespCommandRestartDevice(WiFiClient *localDtuClient);
boolean writeCommandRestartDevice(WiFiClient *localDtuClient, unsigned long locTimeSec);

#endif // DTUINTERFACE_H
19 changes: 14 additions & 5 deletions include/index_html.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ const char INDEX_HTML[] PROGMEM = R"=====(
<small class="panelHead">DTU state</small>
<b id="dtu_error_state" class="panelValueSmall valueText"> ok </b>
</div>
<div class="panelValueBoxDetail">
<small class="panelHead">DTU reboots</small>
<b id="dtu_reboots_no" class="panelValueSmall valueText"> 0 </b>
</div>
<div class="panelValueBoxDetail">
<small class="panelHead">temperature</small>
<b id="inverterTemp" class="panelValueSmall valueText">--.- &deg;C</b>
Expand Down Expand Up @@ -496,8 +500,11 @@ const char INDEX_HTML[] PROGMEM = R"=====(
case 3:
dtuConnect = "try reconnect";
break;
case 4:
dtuConnect = "dtu rebooting";
break;
default:
dtuConnect = "no_info";
dtuConnect = "not known";
}
checkValueUpdate('#dtu_connect_state', dtuConnect);
var dtuState = "";
Expand Down Expand Up @@ -538,7 +545,9 @@ const char INDEX_HTML[] PROGMEM = R"=====(

// setting timer value according to user setting
waitTime = data.dtuConnection.dtuDataCycle * 1000;


checkValueUpdate('#dtu_reboots_no', data.dtuConnection.dtuResetRequested );

return true;
}

Expand Down Expand Up @@ -577,7 +586,7 @@ const char INDEX_HTML[] PROGMEM = R"=====(
// get networkdata
$('#dtuHostIp').val(dtuData.dtuHostIp);
$('#dtuDataCycle').val(dtuData.dtuDataCycle);
if(dtuData.dtuCloudPause) {
if (dtuData.dtuCloudPause) {
$('#dtuCloudPause').prop("checked", true);
} else {
$('#dtuCloudPause').prop("checked", false);
Expand Down Expand Up @@ -660,15 +669,15 @@ const char INDEX_HTML[] PROGMEM = R"=====(
function changeDtuData() {
var dtuHostIpSend = $('#dtuHostIp').val();
var dtuDataCycleSend = $('#dtuDataCycle').val();
if($("#dtuCloudPause").is(':checked')) {
if ($("#dtuCloudPause").is(':checked')) {
dtuCloudPauseSend = 1;
} else {
dtuCloudPauseSend = 0;
}

var dtuSsidSend = $('#dtuSsid').val();
var dtuPasswordSend = $('#dtuPassword').val();

var data = {};
data["dtuHostIpSend"] = dtuHostIpSend;
data["dtuDataCycleSend"] = dtuDataCycleSend;
Expand Down
1 change: 1 addition & 0 deletions include/style_css.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ hr {

.panelHead {
padding-bottom: 2px;
font-size: x-small;
}

/* animated change of color if value chnaged */
Expand Down
6 changes: 3 additions & 3 deletions include/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define VERSION "1.3.0"
#define BUILDTIME "10.03.2024 - 09:23:07"
#define BUILDTIMESTAMP "1710058987"
#define VERSION "1.4.0"
#define BUILDTIME "24.03.2024 - 15:28:25"
#define BUILDTIMESTAMP "1711290505"
8 changes: 4 additions & 4 deletions include/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "1.3.0",
"versiondate": "10.03.2024 - 09:23:07",
"linksnapshot": "https://github.com/ohAnd/dtuGateway/releases/download/snapshot/dtuGateway_snapshot_1.3.0.bin",
"link": "https://github.com/ohAnd/dtuGateway//releases/latest/download/dtuGateway_release_1.3.0.bin"
"version": "1.4.0",
"versiondate": "24.03.2024 - 15:28:25",
"linksnapshot": "https://github.com/ohAnd/dtuGateway/releases/download/snapshot/dtuGateway_snapshot_1.4.0.bin",
"link": "https://github.com/ohAnd/dtuGateway//releases/latest/download/dtuGateway_release_1.4.0.bin"
}
Loading
Loading