Skip to content

Commit

Permalink
adding configuration element in settings -> network settings to enabl…
Browse files Browse the repository at this point in the history
…e / disable smartmeter simulation
  • Loading branch information
Alois Klingler committed Nov 20, 2023
1 parent b95041e commit 1f77c38
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 6 deletions.
2 changes: 2 additions & 0 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ struct CONFIG_T {

bool Mdns_Enabled;

bool Fronius_SM_Simulation_Enabled;

char Ntp_Server[NTP_MAX_SERVER_STRLEN + 1];
char Ntp_Timezone[NTP_MAX_TIMEZONE_STRLEN + 1];
char Ntp_TimezoneDescr[NTP_MAX_TIMEZONEDESCR_STRLEN + 1];
Expand Down
2 changes: 2 additions & 0 deletions include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#define MDNS_ENABLED false

#define FRONIUS_SM_SIMULATION_ENABLED false

#define NTP_SERVER "pool.ntp.org"
#define NTP_TIMEZONE "CET-1CEST,M3.5.0,M10.5.0/3"
#define NTP_TIMEZONEDESCR "Europe/Berlin"
Expand Down
6 changes: 6 additions & 0 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ bool ConfigurationClass::write()
JsonObject mdns = doc.createNestedObject("mdns");
mdns["enabled"] = config.Mdns_Enabled;

JsonObject modbus = doc.createNestedObject("modbus");
modbus["enabled"] = config.Fronius_SM_Simulation_Enabled;

JsonObject ntp = doc.createNestedObject("ntp");
ntp["server"] = config.Ntp_Server;
ntp["timezone"] = config.Ntp_Timezone;
Expand Down Expand Up @@ -197,6 +200,9 @@ bool ConfigurationClass::read()
JsonObject mdns = doc["mdns"];
config.Mdns_Enabled = mdns["enabled"] | MDNS_ENABLED;

JsonObject modbus = doc["modbus"];
config.Fronius_SM_Simulation_Enabled = modbus["enabled"] | FRONIUS_SM_SIMULATION_ENABLED;

JsonObject ntp = doc["ntp"];
strlcpy(config.Ntp_Server, ntp["server"] | NTP_SERVER, sizeof(config.Ntp_Server));
strlcpy(config.Ntp_Timezone, ntp["timezone"] | NTP_TIMEZONE, sizeof(config.Ntp_Timezone));
Expand Down
5 changes: 2 additions & 3 deletions src/ModbusDtu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ ModbusDtuClass ModbusDtu;
void ModbusDtuClass::init()
{
mb.server();
//const CONFIG_T& config = Configuration.get();
mb.addHreg(0x9c40, 21365); //40000
mb.addHreg(0x9c41, 28243);
mb.addHreg(0x9c42, 1);
Expand Down Expand Up @@ -56,15 +55,15 @@ void ModbusDtuClass::init()

void ModbusDtuClass::loop()
{
if (!(Configuration.get().Fronius_SM_Simulation_Enabled)) return;
if (!_isstarted) {
if (Datastore.getIsAllEnabledReachable() && Datastore.getTotalAcYieldTotalEnabled() != 0) {
ModbusDtu.init();
yield();
} else return;
}

const CONFIG_T& config = Configuration.get();
if (millis() - _lastPublish > (config.Dtu_PollInterval * 1000) && Hoymiles.isAllRadioIdle()) {
if (millis() - _lastPublish > ((Configuration.get().Dtu_PollInterval) * 1000) && Hoymiles.isAllRadioIdle()) {
float value;
uint16_t *hexbytes = (uint16_t *)&value;
value = (Datastore.getTotalAcPowerEnabled()*-1);
Expand Down
2 changes: 2 additions & 0 deletions src/WebApi_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void WebApiNetworkClass::onNetworkAdminGet(AsyncWebServerRequest* request)
root["password"] = config.WiFi_Password;
root["aptimeout"] = config.WiFi_ApTimeout;
root["mdnsenabled"] = config.Mdns_Enabled;
root["froniussmmodbusenabled"] = config.Fronius_SM_Simulation_Enabled;

response->setLength();
request->send(response);
Expand Down Expand Up @@ -238,6 +239,7 @@ void WebApiNetworkClass::onNetworkAdminPost(AsyncWebServerRequest* request)
}
config.WiFi_ApTimeout = root["aptimeout"].as<uint>();
config.Mdns_Enabled = root["mdnsenabled"].as<bool>();
config.Fronius_SM_Simulation_Enabled = root["froniussmmodbusenabled"].as<bool>();
Configuration.write();

retMsg["type"] = "success";
Expand Down
4 changes: 3 additions & 1 deletion webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,9 @@
"Minutes": "Minuten",
"Save": "@:dtuadmin.Save",
"EnableMdns": "mDNS aktivieren",
"MdnsSettings": "mDNS-Einstellungen"
"MdnsSettings": "mDNS-Einstellungen",
"ModbusSettings": "Modbus-Einstellungen",
"EnableFroniusSM": "Fronius SmartMeter Simulation aktivieren"
},
"mqttadmin": {
"MqttSettings": "MQTT-Einstellungen",
Expand Down
4 changes: 3 additions & 1 deletion webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,9 @@
"Minutes": "minutes",
"Save": "@:dtuadmin.Save",
"EnableMdns": "Enable mDNS",
"MdnsSettings": "mDNS Settings"
"MdnsSettings": "mDNS Settings",
"ModbusSettings": "Modbus Settings",
"EnableFroniusSM": "Enable Fronius SmartMeter simulation"
},
"mqttadmin": {
"MqttSettings": "MQTT Settings",
Expand Down
5 changes: 4 additions & 1 deletion webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,10 @@
"Minutes": "minutes",
"Save": "@:dtuadmin.Save",
"EnableMdns": "Activer mDNS",
"MdnsSettings": "mDNS Settings"
"MdnsSettings": "mDNS Settings",
"ModbusSettings": "Modbus Settings",
"EnableFroniusSM": "Activer Fronius SmartMeter simulation"

},
"mqttadmin": {
"MqttSettings": "Paramètres MQTT",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/types/NetworkConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface NetworkConfig {
dns2: string;
aptimeout: number;
mdnsenabled: boolean;
froniussmmodbusenabled: boolean;
}
6 changes: 6 additions & 0 deletions webapp/src/views/NetworkAdminView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
type="checkbox"/>
</CardElement>

<CardElement :text="$t('networkadmin.ModbusSettings')" textVariant="text-bg-primary" add-space>
<InputElement :label="$t('networkadmin.EnableFroniusSM')"
v-model="networkConfigList.froniussmmodbusenabled"
type="checkbox"/>
</CardElement>

<CardElement :text="$t('networkadmin.AdminAp')" textVariant="text-bg-primary" add-space>
<InputElement :label="$t('networkadmin.ApTimeout')"
v-model="networkConfigList.aptimeout"
Expand Down
Binary file modified webapp_dist/js/app.js.gz
Binary file not shown.

0 comments on commit 1f77c38

Please sign in to comment.