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

[DEVICE_ADD] ANENJI ModBus #174

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 4 additions & 21 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
platform = [email protected]
framework = arduino
monitor_speed = 115200
custom_prog_version = 1.2.0-Pre4A6
custom_prog_version = 1.2.0-Anj
build_flags =
-DVERSION=${this.custom_prog_version}
-DPIO_SRC_NAM="Solar2MQTT"
-DESP8266 -DATOMIC_FS_UPDATE
-DESP8266 -DATOMIC_FS_UPDATE -Wno-unused-function

extra_scripts = pre:tools/mini_html.py
pre:tools/pre_compile.py
Expand All @@ -25,7 +25,7 @@ lib_deps =
;bblanchon/ArduinoJson @ ^6.21.2
bblanchon/ArduinoJson @ ^7.2.0
esphome/ESPAsyncTCP-esphome @ 2.0.0
mathieucarbou/ESPAsyncWebServer @ ^3.3.16
mathieucarbou/ESPAsyncWebServer @ 3.3.22
mathieucarbou/WebSerialLite@^6.2.0
alanswx/ESPAsyncWiFiManager @ ^0.31.0
plerup/EspSoftwareSerial @ ^8.2.0
Expand All @@ -41,21 +41,4 @@ board_build.ldscript = eagle.flash.4m.ld
build_flags = ${env.build_flags}
custom_hardwareserial = false
monitor_filters = esp8266_exception_decoder, default, time, printable, colorize
upload_speed = 921600

[env:WiFi-Dongle]
board = esp12e
board_build.ldscript = eagle.flash.4m.ld
custom_hardwareserial = true
build_flags = ${env.build_flags}
custom_prog_version = ${env.custom_prog_version}
monitor_filters = esp8266_exception_decoder, default, time, printable, colorize
upload_speed = 921600

[env:esp01_1m]
board = esp01_1m
board_build.ldscript = eagle.flash.1m.ld
custom_hardwareserial = true
build_flags = ${env.build_flags}
custom_prog_version = ${env.custom_prog_version}
monitor_filters = esp8266_exception_decoder, default, time, printable, colorize
upload_speed = 921600
6 changes: 2 additions & 4 deletions src/PI_Serial/PI_Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ void PI_Serial::autoDetect() // function for autodetect the inverter type
{
modbus = new MODBUS(this->my_serialIntf);
modbus->Init();
if (modbus->autoDetect()){
protocol = MODBUS_MUST;
}
protocol = modbus->autoDetect();
}
writeLog("----------------- End Autodetect -----------------");
}
Expand Down Expand Up @@ -400,7 +398,7 @@ char *PI_Serial::getModeDesc(char mode) // get the char from QMOD and make reada

bool PI_Serial::isModbus()
{
return protocol == MODBUS_MUST;
return protocol == MODBUS_MUST || protocol == MODBUS_DEYE;
}

bool PI_Serial::checkQFLAG(const String& flags, char symbol) {
Expand Down
15 changes: 5 additions & 10 deletions src/PI_Serial/PI_Serial.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#include "SoftwareSerial.h"
#ifndef PI_SERIAL_H
#define PI_SERIAL_H
#include "vector"
#include "SoftwareSerial.h"
#include <ArduinoJson.h>
#include <modbus/modbus.h>

extern JsonObject deviceJson;
extern JsonObject staticData;
extern JsonObject liveData;

class PI_Serial
{
public:
const char *startChar = "(";
const char *delimiter = " ";
bool requestStaticData = true;
byte protocol = NoD;
protocol_type_t protocol = NoD;
bool connection = false;

struct
Expand Down Expand Up @@ -88,13 +89,7 @@ class PI_Serial
void callback(std::function<void()> func);
std::function<void()> requestCallback;

enum protocolType
{
NoD,
PI18,
PI30,
MODBUS_MUST
};


private:
unsigned int serialIntfBaud;
Expand Down
16 changes: 8 additions & 8 deletions src/PI_Serial/QMOD.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bool PI_Serial::PIXX_QMOD()
}
if (commandAnswer.length() == 1)
{
liveData["Inverter_Operation_Mode"] = getModeDesc((char)commandAnswer.charAt(0));
liveData[DESCR_LIVE_INVERTER_OPERATION_MODE] = getModeDesc((char)commandAnswer.charAt(0));
}
return true;
}
Expand All @@ -35,25 +35,25 @@ bool PI_Serial::PIXX_QMOD()
switch (commandAnswer.toInt())
{
case 0:
liveData["Inverter_Operation_Mode"] = "Power on";
liveData[DESCR_LIVE_INVERTER_OPERATION_MODE] = "Power on";
break;
case 1:
liveData["Inverter_Operation_Mode"] = "Standby";
liveData[DESCR_LIVE_INVERTER_OPERATION_MODE] = "Standby";
break;
case 2:
liveData["Inverter_Operation_Mode"] = "Bypass";
liveData[DESCR_LIVE_INVERTER_OPERATION_MODE] = "Bypass";
break;
case 3:
liveData["Inverter_Operation_Mode"] = "Battery";
liveData[DESCR_LIVE_INVERTER_OPERATION_MODE] = "Battery";
break;
case 4:
liveData["Inverter_Operation_Mode"] = "Fault";
liveData[DESCR_LIVE_INVERTER_OPERATION_MODE] = "Fault";
break;
case 5:
liveData["Inverter_Operation_Mode"] = "Hybrid";
liveData[DESCR_LIVE_INVERTER_OPERATION_MODE] = "Hybrid";
break;
default:
liveData["Inverter_Operation_Mode"] = "No data";
liveData[DESCR_LIVE_INVERTER_OPERATION_MODE] = "No data";
break;
}

Expand Down
20 changes: 10 additions & 10 deletions src/PI_Serial/QPIGS.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ static const char *const qpigsList[][24] = {
"Battery_Charge_Current", // KKK
"Battery_Percent", // OOO
"Inverter_Bus_Temperature", // TTTT
"PV_Input_Current", // EE.E
"PV_Input_Voltage", // UUU.U
DESCR_LIVE_PV_INPUT_CURRENT, // EE.E
DESCR_LIVE_PV_INPUT_VOLTAGE, // UUU.U
"Battery_SCC_Volt", // WW.WW
"Battery_Discharge_Current", // PPPP
"Status_Flag", // b0-b7
"Battery_voltage_offset_fans_on", // QQ
"EEPROM_Version", // VV
"PV_Charging_Power", // MMMM
DESCR_LIVE_PV_CHARGING_POWER, // MMMM
"Device_Status", // b8-b10
"Solar_feed_to_Grid_status", // Y
"Country", // ZZ
Expand Down Expand Up @@ -63,9 +63,9 @@ static const char *const qallList[] = {
"Battery_Percent", // III
"Battery_Charge_Current", // JJJ
"Battery_Discharge_Current", // KKK
"PV_Input_Voltage", // LLL
"PV_Input_Current", // MM.M
"PV_Charging_Power", // NNNN
DESCR_LIVE_PV_INPUT_VOLTAGE, // LLL
DESCR_LIVE_PV_INPUT_CURRENT, // MM.M
DESCR_LIVE_PV_CHARGING_POWER, // NNNN
"PV_generation_day", // OOOOOO
"PV_generation_sum", // PPPPPP
"Inverter_Operation_Mode", // Q
Expand Down Expand Up @@ -163,7 +163,7 @@ bool PI_Serial::PIXX_QPIGS()
}
// make some things pretty
liveData["Battery_Load"] = (liveData["Battery_Charge_Current"].as<unsigned short>() - liveData["Battery_Discharge_Current"].as<unsigned short>());
liveData["PV_Input_Power"] = (liveData["PV_Input_Voltage"].as<unsigned short>() * liveData["PV_Input_Current"].as<unsigned short>());
liveData[DESCR_LIVE_PV_INPUT_POWER] = (liveData[DESCR_LIVE_PV_INPUT_VOLTAGE].as<unsigned short>() * liveData[DESCR_LIVE_PV_INPUT_CURRENT].as<unsigned short>());
}

if (get.raw.qall.length() > 10 /*get.raw.qall != "NAK" || get.raw.qall != "ERCRC" || get.raw.qall != ""*/)
Expand Down Expand Up @@ -248,9 +248,9 @@ bool PI_Serial::PIXX_QPIGS()
}
// make some things pretty

liveData["PV_Input_Voltage"] = (liveData["PV1_Input_Voltage"].as<unsigned short>() + liveData["PV2_Input_Voltage"].as<unsigned short>());
liveData["PV_Charging_Power"] = (liveData["PV1_Input_Power"].as<unsigned short>() + liveData["PV2_Input_Power"].as<unsigned short>());
liveData["PV_Input_Current"] = (int)((liveData["PV_Charging_Power"].as<unsigned short>() / (liveData["PV_Input_Voltage"].as<unsigned short>()+0.5)) * 100) / 100.0;
liveData[DESCR_LIVE_PV_INPUT_VOLTAGE] = (liveData["PV1_Input_Voltage"].as<unsigned short>() + liveData["PV2_Input_Voltage"].as<unsigned short>());
liveData[DESCR_LIVE_PV_CHARGING_POWER] = (liveData["PV1_Input_Power"].as<unsigned short>() + liveData["PV2_Input_Power"].as<unsigned short>());
liveData["PV_Input_Current"] = (int)((liveData[DESCR_LIVE_PV_CHARGING_POWER].as<unsigned short>() / (liveData[DESCR_LIVE_PV_INPUT_VOLTAGE].as<unsigned short>()+0.5)) * 100) / 100.0;
liveData["Battery_Load"] = (liveData["Battery_Charge_Current"].as<unsigned short>() - liveData["Battery_Discharge_Current"].as<unsigned short>());
}
return true;
Expand Down
92 changes: 92 additions & 0 deletions src/descriptors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#ifndef DESCRIPTORS_H
#define DESCRIPTORS_H

static const char *const DESCR_STAT_AC_IN_RATING_CURRENT = "AC_in_rating_current";
static const char *const DESCR_STAT_AC_IN_RATING_VOLTAGE = "AC_in_rating_voltage";
static const char *const DESCR_STAT_AC_OUT_RATING_ACTIVE_POWER = "AC_out_rating_active_power";
static const char *const DESCR_STAT_AC_OUT_RATING_APPARENT_POWER = "AC_out_rating_apparent_power";
static const char *const DESCR_STAT_AC_OUT_RATING_CURRENT = "AC_out_rating_current";
static const char *const DESCR_STAT_AC_OUT_RATING_FREQUENCY = "AC_out_rating_frequency";
static const char *const DESCR_STAT_AC_OUT_RATING_VOLTAGE = "AC_out_rating_voltage";
static const char *const DESCR_STAT_BATTERY_BULK_VOLTAGE = "Battery_bulk_voltage";
static const char *const DESCR_STAT_BATTERY_FLOAT_VOLTAGE = "Battery_float_voltage";
static const char *const DESCR_STAT_BATTERY_RATING_VOLTAGE = "Battery_rating_voltage";
static const char *const DESCR_STAT_BATTERY_RE_CHARGE_VOLTAGE = "Battery_re-charge_voltage";
static const char *const DESCR_STAT_BATTERY_RE_DISCHARGE_VOLTAGE = "Battery_re-discharge_voltage";
static const char *const DESCR_STAT_BATTERY_TYPE = "Battery_type";
static const char *const DESCR_STAT_BATTERY_UNDER_VOLTAGE = "Battery_under_voltage";
static const char *const DESCR_STAT_CHARGER_SOURCE_PRIORITY = "Charger_source_priority";
static const char *const DESCR_STAT_CURRENT_MAX_AC_CHARGING_CURRENT = "Current_max_AC_charging_current";
static const char *const DESCR_STAT_CURRENT_MAX_CHARGING_CURRENT = "Current_max_charging_current";
static const char *const DESCR_STAT_DEVICE_MODEL = "Device_Model";
static const char *const DESCR_STAT_INPUT_VOLTAGE_RANGE = "Input_voltage_range";
static const char *const DESCR_STAT_MACHINE_TYPE = "Machine_type";
static const char *const DESCR_STAT_MAX_CHARGING_TIME_AT_CV_STAGE = "Max_charging_time_at_CV_stage";
static const char *const DESCR_STAT_MAX_DISCHARGING_CURRENT = "Max_discharging_current";
static const char *const DESCR_STAT_MPPT_STRING = "MPPT_string";
static const char *const DESCR_STAT_OPERATION_LOGIC = "Operation_Logic";
static const char *const DESCR_STAT_OUTPUT_MODE = "Output_mode";
static const char *const DESCR_STAT_OUTPUT_SOURCE_PRIORITY = "Output_source_priority";
static const char *const DESCR_STAT_PROTOCOL_ID = "Protocol_ID";
static const char *const DESCR_STAT_PV_POWER_BALANCE = "PV_power_balance";
static const char *const DESCR_STAT_SOLAR_POWER_PRIORITY = "Solar_power_priority";
static const char *const DESCR_STAT_TOPOLOGY = "Topology";

static const char *const DESCR_LIVE_AC_IN_FREQUENZ = "AC_in_Frequenz";
static const char *const DESCR_LIVE_AC_IN_GENERATION_DAY = "AC_in_generation_day";
static const char *const DESCR_LIVE_AC_IN_GENERATION_MONTH = "AC_in_generation_month";
static const char *const DESCR_LIVE_AC_IN_GENERATION_SUM = "AC_in_generation_sum";
static const char *const DESCR_LIVE_AC_IN_GENERATION_YEAR = "AC_in_generation_year";
static const char *const DESCR_LIVE_AC_IN_VOLTAGE = "AC_in_Voltage";
static const char *const DESCR_LIVE_AC_OUT_FREQUENZ = "AC_out_Frequenz";
static const char *const DESCR_LIVE_AC_OUT_PERCENT = "AC_out_percent";
static const char *const DESCR_LIVE_AC_OUT_VA = "AC_out_VA";
static const char *const DESCR_LIVE_AC_OUT_VOLTAGE = "AC_out_Voltage";
static const char *const DESCR_LIVE_AC_OUT_WATT = "AC_out_Watt";
static const char *const DESCR_LIVE_AC_OUTPUT_CURRENT = "AC_output_current";
static const char *const DESCR_LIVE_AC_OUTPUT_FREQUENCY = "AC_output_frequency";
static const char *const DESCR_LIVE_AC_OUTPUT_POWER = "AC_output_power";
static const char *const DESCR_LIVE_AC_OUTPUT_VOLTAGE = "AC_output_voltage";
static const char *const DESCR_LIVE_BATTERY_CAPACITY = "Battery_capacity";
static const char *const DESCR_LIVE_BATTERY_LOAD = "Battery_Load";
static const char *const DESCR_LIVE_BATTERY_PERCENT = "Battery_Percent";
static const char *const DESCR_LIVE_BATTERY_POWER_DIRECTION = "Battery_Power_Direction";
static const char *const DESCR_LIVE_BATTERY_TEMPERATURE = "Battery_temperature";
static const char *const DESCR_LIVE_BATTERY_VOLTAGE = "Battery_Voltage";
static const char *const DESCR_LIVE_GRID_FREQUENCY = "Grid_frequency";
static const char *const DESCR_LIVE_GRID_VOLTAGE = "Grid_voltage";
static const char *const DESCR_LIVE_INVERTER_BUS_TEMPERATURE = "Inverter_Bus_Temperature";
static const char *const DESCR_LIVE_INVERTER_BUS_VOLTAGE = "Inverter_Bus_Voltage";
static const char *const DESCR_LIVE_INVERTER_OPERATION_MODE = "Inverter_Operation_Mode";
static const char *const DESCR_LIVE_INVERTER_TEMPERATURE = "Inverter_temperature";
static const char *const DESCR_LIVE_LOCAL_PARALLEL_ID = "Local_Parallel_ID";
static const char *const DESCR_LIVE_MPPT1_CHARGER_TEMPERATURE = "MPPT1_Charger_Temperature";
static const char *const DESCR_LIVE_MPPT2_CHARGER_TEMPERATURE = "MPPT2_Charger_Temperature";
static const char *const DESCR_LIVE_NEGATIVE_BATTERY_VOLTAGE = "Negative_battery_voltage";
static const char *const DESCR_LIVE_OUTPUT_CURRENT = "Output_current";
static const char *const DESCR_LIVE_OUTPUT_LOAD_PERCENT = "Output_load_percent";
static const char *const DESCR_LIVE_OUTPUT_POWER = "Output_power";
static const char *const DESCR_LIVE_POSITIVE_BATTERY_VOLTAGE = "Positive_battery_voltage";
static const char *const DESCR_LIVE_PV_CHARGING_POWER = "PV_Charging_Power";
static const char *const DESCR_LIVE_PV_GENERATION_DAY = "PV_generation_day";
static const char *const DESCR_LIVE_PV_GENERATION_MONTH = "PV_generation_month";
static const char *const DESCR_LIVE_PV_GENERATION_SUM = "PV_generation_sum";
static const char *const DESCR_LIVE_PV_GENERATION_YEAR = "PV_generation_year";
static const char *const DESCR_LIVE_PV_INPUT_CURRENT = "PV_Input_Current";
static const char *const DESCR_LIVE_PV_INPUT_POWER = "PV_Input_Power";
static const char *const DESCR_LIVE_PV_INPUT_VOLTAGE = "PV_Input_Voltage";
static const char *const DESCR_LIVE_PV1_INPUT_POWER = "PV1_input_power";
static const char *const DESCR_LIVE_PV1_INPUT_VOLTAGE = "PV1_input_voltage";
static const char *const DESCR_LIVE_PV2_CHARGING_POWER = "PV2_Charging_Power";
static const char *const DESCR_LIVE_PV2_INPUT_CURRENT = "PV2_Input_Current";
static const char *const DESCR_LIVE_PV2_INPUT_POWER = "PV2_input_power";
static const char *const DESCR_LIVE_PV2_INPUT_VOLTAGE = "PV2_input_voltage";
static const char *const DESCR_LIVE_PV3_INPUT_POWER = "PV3_input_power";
static const char *const DESCR_LIVE_PV3_INPUT_VOLTAGE = "PV3_input_voltage";
static const char *const DESCR_LIVE_SOLAR_FEED_TO_GRID_POWER = "Solar_feed_to_grid_power";
static const char *const DESCR_LIVE_SOLAR_FEED_TO_GRID_STATUS = "Solar_feed_to_Grid_status";
static const char *const DESCR_LIVE_TRACKER_TEMPERATURE = "Tracker_temperature";
static const char *const DESCR_LIVE_TRANSFORMER_TEMPERATURE = "Transformer_temperature";
static const char *const DESCR_LIVE_WARNING_CODE = "Warning_Code";

#endif
Loading