Skip to content

Commit

Permalink
Merge branch 'main' into asyncWeb
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan123t authored Aug 10, 2022
2 parents b76f257 + 6276957 commit f4f2faf
Show file tree
Hide file tree
Showing 14 changed files with 433 additions and 270 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/compile_esp8266.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:
- name: Run PlatformIO
run: pio run -d tools/esp8266
- name: rename
working-directory: tools/esp8266/helpers
working-directory: tools/esp8266/scripts
run: python getVersion.py
- uses: actions/upload-artifact@v3
with:
name: esp8266
path: tools/esp8266/.pio/build/d1_mini/out
name: esp8266_ahoy
path: tools/esp8266/.pio/build/out/*.bin
246 changes: 154 additions & 92 deletions tools/esp8266/app.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tools/esp8266/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class app : public Main {
void showLiveData(AsyncWebServerRequest *request);
void showJSON(AsyncWebServerRequest *request);
void devControl(AsyncWebServerRequest *request);
void webapi(AsyncWebServerRequest *request);


void saveValues(AsyncWebServerRequest *request, bool webSend);
Expand Down
173 changes: 104 additions & 69 deletions tools/esp8266/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 5
#define VERSION_PATCH 2
#define VERSION_PATCH 5


//-------------------------------------
Expand All @@ -30,6 +30,41 @@ typedef struct {
uint8_t packet[MAX_RF_PAYLOAD_SIZE];
} packet_t;

typedef enum {
InverterDevInform_Simple = 0, // 0x00
InverterDevInform_All = 1, // 0x01
//GridOnProFilePara = 2, // 0x02
//HardWareConfig = 3, // 0x03
//SimpleCalibrationPara = 4, // 0x04
//SystemConfigPara = 5, // 0x05
RealTimeRunData_Debug = 11, // 0x0b
//RealTimeRunData_Reality = 12, // 0x0c
//RealTimeRunData_A_Phase = 13, // 0x0d
//RealTimeRunData_B_Phase = 14, // 0x0e
//RealTimeRunData_C_Phase = 15, // 0x0f
AlarmData = 17, // 0x11, Alarm data - all unsent alarms
AlarmUpdate = 18, // 0x12, Alarm data - all pending alarms
//RecordData = 19, // 0x13
//InternalData = 20, // 0x14
GetLossRate = 21, // 0x15
//GetSelfCheckState = 30, // 0x1e
//InitDataState = 0xff
} InfoCmdType;

typedef enum {
TurnOn = 0, // 0x00
TurnOff = 1, // 0x01
Restart = 2, // 0x02
Lock = 3, // 0x03
Unlock = 4, // 0x04
ActivePowerContr = 11, // 0x0b
ReactivePowerContr = 12, // 0x0c
PFSet = 13, // 0x0d
CleanState_LockAndAlarm = 20, // 0x14
SelfInspection = 40, // 0x28, self-inspection of grid-connected protection files
Init = 0xff
} DevControlCmdType;

// minimum serial interval
#define MIN_SERIAL_INTERVAL 5

Expand All @@ -42,76 +77,76 @@ typedef struct {
//-------------------------------------
// EEPROM
//-------------------------------------
#define SSID_LEN 32
#define PWD_LEN 64
#define DEVNAME_LEN 16
#define CRC_LEN 2 // uint16_t

#define INV_ADDR_LEN MAX_NUM_INVERTERS * 8 // uint64_t
#define INV_NAME_LEN MAX_NUM_INVERTERS * MAX_NAME_LENGTH // char[]
#define INV_CH_CH_PWR_LEN MAX_NUM_INVERTERS * 2 * 4 // uint16_t (4 channels)
#define INV_CH_CH_NAME_LEN MAX_NUM_INVERTERS * MAX_NAME_LENGTH * 4 // (4 channels)
#define INV_INTERVAL_LEN 2 // uint16_t
#define INV_MAX_RTRY_LEN 1 // uint8_t
#define INV_PWR_LIM_LEN MAX_NUM_INVERTERS * 2 // uint16_t

#define PINOUT_LEN 3 // 3 pins: CS, CE, IRQ

#define RF24_AMP_PWR_LEN 1

#define NTP_ADDR_LEN 32 // DNS Name
#define NTP_PORT_LEN 2 // uint16_t

#define MQTT_ADDR_LEN 32 // DNS Name
#define MQTT_USER_LEN 16
#define MQTT_PWD_LEN 32
#define MQTT_TOPIC_LEN 32
#define MQTT_INTERVAL_LEN 2 // uint16_t
#define MQTT_PORT_LEN 2 // uint16_t
#define MQTT_DISCOVERY_PREFIX "homeassistant"
#define MQTT_MAX_PACKET_SIZE 384

#define SER_ENABLE_LEN 1 // uint8_t
#define SER_DEBUG_LEN 1 // uint8_t
#define SER_INTERVAL_LEN 2 // uint16_t


#define ADDR_START 0
#define ADDR_SSID ADDR_START
#define ADDR_PWD ADDR_SSID + SSID_LEN
#define ADDR_DEVNAME ADDR_PWD + PWD_LEN
#define ADDR_WIFI_CRC ADDR_DEVNAME + DEVNAME_LEN
#define ADDR_START_SETTINGS ADDR_WIFI_CRC + CRC_LEN

#define ADDR_PINOUT ADDR_START_SETTINGS

#define ADDR_RF24_AMP_PWR ADDR_PINOUT + PINOUT_LEN

#define ADDR_INV_ADDR ADDR_RF24_AMP_PWR + RF24_AMP_PWR_LEN
#define ADDR_INV_NAME ADDR_INV_ADDR + INV_ADDR_LEN
#define ADDR_INV_CH_PWR ADDR_INV_NAME + INV_NAME_LEN
#define ADDR_INV_CH_NAME ADDR_INV_CH_PWR + INV_CH_CH_PWR_LEN
#define ADDR_INV_INTERVAL ADDR_INV_CH_NAME + INV_CH_CH_NAME_LEN
#define ADDR_INV_MAX_RTRY ADDR_INV_INTERVAL + INV_INTERVAL_LEN
#define ADDR_INV_PWR_LIM ADDR_INV_MAX_RTRY + INV_MAX_RTRY_LEN

#define ADDR_NTP_ADDR ADDR_INV_PWR_LIM + INV_PWR_LIM_LEN //Bugfix #125
#define ADDR_NTP_PORT ADDR_NTP_ADDR + NTP_ADDR_LEN

#define ADDR_MQTT_ADDR ADDR_NTP_PORT + NTP_PORT_LEN
#define ADDR_MQTT_USER ADDR_MQTT_ADDR + MQTT_ADDR_LEN
#define ADDR_MQTT_PWD ADDR_MQTT_USER + MQTT_USER_LEN
#define ADDR_MQTT_TOPIC ADDR_MQTT_PWD + MQTT_PWD_LEN
#define ADDR_MQTT_INTERVAL ADDR_MQTT_TOPIC + MQTT_TOPIC_LEN
#define ADDR_MQTT_PORT ADDR_MQTT_INTERVAL + MQTT_INTERVAL_LEN

#define ADDR_SER_ENABLE ADDR_MQTT_PORT + MQTT_PORT_LEN
#define ADDR_SER_DEBUG ADDR_SER_ENABLE + SER_ENABLE_LEN
#define ADDR_SER_INTERVAL ADDR_SER_DEBUG + SER_DEBUG_LEN
#define ADDR_NEXT ADDR_SER_INTERVAL + SER_INTERVAL_LEN
#define SSID_LEN 32
#define PWD_LEN 64
#define DEVNAME_LEN 16
#define CRC_LEN 2 // uint16_t

#define INV_ADDR_LEN MAX_NUM_INVERTERS * 8 // uint64_t
#define INV_NAME_LEN MAX_NUM_INVERTERS * MAX_NAME_LENGTH // char[]
#define INV_CH_CH_PWR_LEN MAX_NUM_INVERTERS * 2 * 4 // uint16_t (4 channels)
#define INV_CH_CH_NAME_LEN MAX_NUM_INVERTERS * MAX_NAME_LENGTH * 4 // (4 channels)
#define INV_INTERVAL_LEN 2 // uint16_t
#define INV_MAX_RTRY_LEN 1 // uint8_t
#define INV_PWR_LIM_LEN MAX_NUM_INVERTERS * 2 // uint16_t

#define PINOUT_LEN 3 // 3 pins: CS, CE, IRQ

#define RF24_AMP_PWR_LEN 1

#define NTP_ADDR_LEN 32 // DNS Name
#define NTP_PORT_LEN 2 // uint16_t

#define MQTT_ADDR_LEN 32 // DNS Name
#define MQTT_USER_LEN 16
#define MQTT_PWD_LEN 32
#define MQTT_TOPIC_LEN 32
#define MQTT_INTERVAL_LEN 2 // uint16_t
#define MQTT_PORT_LEN 2 // uint16_t
#define MQTT_DISCOVERY_PREFIX "homeassistant"
#define MQTT_MAX_PACKET_SIZE 384

#define SER_ENABLE_LEN 1 // uint8_t
#define SER_DEBUG_LEN 1 // uint8_t
#define SER_INTERVAL_LEN 2 // uint16_t


#define ADDR_START 0
#define ADDR_SSID ADDR_START
#define ADDR_PWD ADDR_SSID + SSID_LEN
#define ADDR_DEVNAME ADDR_PWD + PWD_LEN
#define ADDR_WIFI_CRC ADDR_DEVNAME + DEVNAME_LEN
#define ADDR_START_SETTINGS ADDR_WIFI_CRC + CRC_LEN

#define ADDR_PINOUT ADDR_START_SETTINGS

#define ADDR_RF24_AMP_PWR ADDR_PINOUT + PINOUT_LEN

#define ADDR_INV_ADDR ADDR_RF24_AMP_PWR + RF24_AMP_PWR_LEN
#define ADDR_INV_NAME ADDR_INV_ADDR + INV_ADDR_LEN
#define ADDR_INV_CH_PWR ADDR_INV_NAME + INV_NAME_LEN
#define ADDR_INV_CH_NAME ADDR_INV_CH_PWR + INV_CH_CH_PWR_LEN
#define ADDR_INV_INTERVAL ADDR_INV_CH_NAME + INV_CH_CH_NAME_LEN
#define ADDR_INV_MAX_RTRY ADDR_INV_INTERVAL + INV_INTERVAL_LEN
#define ADDR_INV_PWR_LIM ADDR_INV_MAX_RTRY + INV_MAX_RTRY_LEN

#define ADDR_NTP_ADDR ADDR_INV_PWR_LIM + INV_PWR_LIM_LEN //Bugfix #125
#define ADDR_NTP_PORT ADDR_NTP_ADDR + NTP_ADDR_LEN

#define ADDR_MQTT_ADDR ADDR_NTP_PORT + NTP_PORT_LEN
#define ADDR_MQTT_USER ADDR_MQTT_ADDR + MQTT_ADDR_LEN
#define ADDR_MQTT_PWD ADDR_MQTT_USER + MQTT_USER_LEN
#define ADDR_MQTT_TOPIC ADDR_MQTT_PWD + MQTT_PWD_LEN
#define ADDR_MQTT_INTERVAL ADDR_MQTT_TOPIC + MQTT_TOPIC_LEN
#define ADDR_MQTT_PORT ADDR_MQTT_INTERVAL + MQTT_INTERVAL_LEN

#define ADDR_SER_ENABLE ADDR_MQTT_PORT + MQTT_PORT_LEN
#define ADDR_SER_DEBUG ADDR_SER_ENABLE + SER_ENABLE_LEN
#define ADDR_SER_INTERVAL ADDR_SER_DEBUG + SER_DEBUG_LEN
#define ADDR_NEXT ADDR_SER_INTERVAL + SER_INTERVAL_LEN

// #define ADDR_SETTINGS_CRC 950
#define ADDR_SETTINGS_CRC ADDR_NEXT + 2
#define ADDR_SETTINGS_CRC ADDR_NEXT + 2

#if(ADDR_SETTINGS_CRC <= ADDR_NEXT)
#pragma error "address overlap! (ADDR_SETTINGS_CRC="+ ADDR_SETTINGS_CRC +", ADDR_NEXT="+ ADDR_NEXT +")"
Expand Down
14 changes: 10 additions & 4 deletions tools/esp8266/hmDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ union serial_u {


// units
enum {UNIT_V = 0, UNIT_A, UNIT_W, UNIT_WH, UNIT_KWH, UNIT_HZ, UNIT_C, UNIT_PCT};
const char* const units[] = {"V", "A", "W", "Wh", "kWh", "Hz", "°C", "%"};
enum {UNIT_V = 0, UNIT_A, UNIT_W, UNIT_WH, UNIT_KWH, UNIT_HZ, UNIT_C, UNIT_PCT, UNIT_VA, UNIT_ALARM_MES_ID};
const char* const units[] = {"V", "A", "W", "Wh", "kWh", "Hz", "°C", "%","VAr",""};


// field types
enum {FLD_UDC = 0, FLD_IDC, FLD_PDC, FLD_YD, FLD_YW, FLD_YT,
FLD_UAC, FLD_IAC, FLD_PAC, FLD_F, FLD_T, FLD_PCT, FLD_EFF, FLD_IRR};
FLD_UAC, FLD_IAC, FLD_PAC, FLD_F, FLD_T, FLD_PCT, FLD_EFF, FLD_IRR, FLD_PRA,FLD_ALARM_MES_ID};
const char* const fields[] = {"U_DC", "I_DC", "P_DC", "YieldDay", "YieldWeek", "YieldTotal",
"U_AC", "I_AC", "P_AC", "Freq", "Temp", "Pct", "Efficiency", "Irradiation"};
"U_AC", "I_AC", "P_AC", "Freq", "Temp", "Pct", "Efficiency", "Irradiation","P_ACr","ALARM_MES_ID"};

// mqtt discovery device classes
enum {DEVICE_CLS_NONE = 0, DEVICE_CLS_CURRENT, DEVICE_CLS_ENERGY, DEVICE_CLS_PWR, DEVICE_CLS_VOLTAGE, DEVICE_CLS_FREQ, DEVICE_CLS_TEMP};
Expand Down Expand Up @@ -95,8 +95,10 @@ const byteAssign_t hm1chAssignment[] = {
{ FLD_UAC, UNIT_V, CH0, 14, 2, 10 },
{ FLD_IAC, UNIT_A, CH0, 22, 2, 100 },
{ FLD_PAC, UNIT_W, CH0, 18, 2, 10 },
{ FLD_PRA, UNIT_VA, CH0, 20, 2, 10 },
{ FLD_F, UNIT_HZ, CH0, 16, 2, 100 },
{ FLD_T, UNIT_C, CH0, 26, 2, 10 },
{ FLD_ALARM_MES_ID, UNIT_ALARM_MES_ID, CH0, 28, 2, 1 },
{ FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC },
{ FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC }
};
Expand Down Expand Up @@ -124,8 +126,10 @@ const byteAssign_t hm2chAssignment[] = {
{ FLD_UAC, UNIT_V, CH0, 26, 2, 10 },
{ FLD_IAC, UNIT_A, CH0, 34, 2, 100 },
{ FLD_PAC, UNIT_W, CH0, 30, 2, 10 },
{ FLD_PRA, UNIT_VA, CH0, 32, 2, 10 },
{ FLD_F, UNIT_HZ, CH0, 28, 2, 100 },
{ FLD_T, UNIT_C, CH0, 38, 2, 10 },
{ FLD_ALARM_MES_ID, UNIT_ALARM_MES_ID, CH0, 40, 2, 1 },
{ FLD_YD, UNIT_WH, CH0, CALC_YD_CH0, 0, CMD_CALC },
{ FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC },
{ FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC },
Expand Down Expand Up @@ -170,9 +174,11 @@ const byteAssign_t hm4chAssignment[] = {
{ FLD_UAC, UNIT_V, CH0, 46, 2, 10 },
{ FLD_IAC, UNIT_A, CH0, 54, 2, 100 },
{ FLD_PAC, UNIT_W, CH0, 50, 2, 10 },
{ FLD_PRA, UNIT_VA, CH0, 52, 2, 10 },
{ FLD_F, UNIT_HZ, CH0, 48, 2, 100 },
{ FLD_PCT, UNIT_PCT, CH0, 56, 2, 10 },
{ FLD_T, UNIT_C, CH0, 58, 2, 10 },
{ FLD_ALARM_MES_ID, UNIT_ALARM_MES_ID, CH0, 60, 2, 1 },
{ FLD_YD, UNIT_WH, CH0, CALC_YD_CH0, 0, CMD_CALC },
{ FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC },
{ FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC },
Expand Down
11 changes: 8 additions & 3 deletions tools/esp8266/hmInverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class Inverter {
uint8_t type; // integer which refers to inverter type
byteAssign_t* assign; // type of inverter
uint8_t listLen; // length of assignments
uint16_t powerLimit; // limit power output
uint16_t alarmMesIndex; // Last recorded Alarm Message Index
uint16_t powerLimit[2]; // limit power output
uint8_t devControlCmd; // carries the requested cmd
bool devControlRequest; // true if change needed
serial_u serial; // serial number as on barcode
Expand All @@ -82,7 +83,8 @@ class Inverter {

Inverter() {
ts = 0;
powerLimit = -1; // 65535 W Limit -> unlimited
powerLimit[0] = -1; // 65535 W Limit -> unlimited
powerLimit[1] = 0x0100; // 0x0000 --> set temporary , 0x0100 --> set persistent
devControlRequest = false;
devControlCmd = 0xff;
}
Expand Down Expand Up @@ -131,7 +133,6 @@ class Inverter {
uint8_t ptr = assign[pos].start;
uint8_t end = ptr + assign[pos].num;
uint16_t div = assign[pos].div;

if(CMD_CALC != div) {
uint32_t val = 0;
do {
Expand All @@ -141,6 +142,10 @@ class Inverter {

record[pos] = (RECORDTYPE)(val) / (RECORDTYPE)(div);
}
// get last alarm message index and save it in the inverter instance
if (getPosByChFld(0, FLD_ALARM_MES_ID) == pos){
alarmMesIndex = record[pos];
}
}

RECORDTYPE getValue(uint8_t pos) {
Expand Down
Loading

0 comments on commit f4f2faf

Please sign in to comment.