Skip to content

Commit

Permalink
Merge remote-tracking branch 'tbnobody/OpenDTU/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
helgeerbe committed Sep 6, 2022
2 parents 41eb94e + 83ca402 commit 5a25ce5
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 297 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,16 @@ This can be achieved by editing the 'platformio.ini' file and add/change one or
* After the initial flashing of the microcontroller, an Access Point called "OpenDTU-*" is opened. The default password is "openDTU42".
* Use a web browser to open the address [http://192.168.4.1](http://192.168.4.1)
* Navigate to Settings --> Network Settings and enter your WiFi credentials
* Currently you have to look at your router to determine the IP of the newly connected device
* OpenDTU then simultaneously connects to your WiFi AP with this credentials. Navigate to Info --> Network and look into section "Network Interface (Station)" for the IP address received via DHCP.
* When OpenDTU is connected to a configured WiFI AP, the "OpenDTU-*" Access Point is closed after 3 minutes.
* OpenDTU needs access to a working NTP server to get the current date & time. Both are sent to the inverter with each request. Default NTP server is pool.ntp.org. If your network has different requirements please change accordingly (Settings --> NTP Settings).
* Add your inverter in the inverter settings (Settings --> Inverter Settings)

## Flashing an Update using "Over The Air" OTA Update
Once you have your OpenDTU running and connected to WLAN, you can do further updates through the web interface.
Navigate to Settings --> Firmware upgrade and press the browse button. Select the firmware file from your local computer.

You'll find the firmware file (after a successfull build process) under `.pio/build/generic/firmware.elf`.
You'll find the firmware file (after a successfull build process) under `.pio/build/generic/firmware.bin`.

After the successful upload, the OpenDTU immediately restarts into the new firmware.

Expand Down
4 changes: 3 additions & 1 deletion include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <Arduino.h>

#define CONFIG_FILENAME "/config.bin"
#define CONFIG_VERSION 0x00011400 // 0.1.20 // make sure to clean all after change
#define CONFIG_VERSION 0x00011500 // 0.1.21 // make sure to clean all after change

#define WIFI_MAX_SSID_STRLEN 31
#define WIFI_MAX_PASSWORD_STRLEN 64
Expand Down Expand Up @@ -80,6 +80,8 @@ struct CONFIG_T {
uint32_t Vedirect_PollInterval;

char Mqtt_Hostname[MQTT_MAX_HOSTNAME_STRLEN + 1];

bool Mqtt_Hass_Expire;
};

class ConfigurationClass {
Expand Down
1 change: 1 addition & 0 deletions include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#define DTU_PA_LEVEL 0

#define MQTT_HASS_ENABLED false
#define MQTT_HASS_EXPIRE true
#define MQTT_HASS_RETAIN true
#define MQTT_HASS_TOPIC "homeassistant/"
#define MQTT_HASS_INDIVIDUALPANELS false
Expand Down
5 changes: 5 additions & 0 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void ConfigurationClass::init()
config.Dtu_PaLevel = DTU_PA_LEVEL;

config.Mqtt_Hass_Enabled = MQTT_HASS_ENABLED;
config.Mqtt_Hass_Expire = MQTT_HASS_EXPIRE;
config.Mqtt_Hass_Retain = MQTT_HASS_RETAIN;
strlcpy(config.Mqtt_Hass_Topic, MQTT_HASS_TOPIC, sizeof(config.Mqtt_Hass_Topic));
config.Mqtt_Hass_IndividualPanels = MQTT_HASS_INDIVIDUALPANELS;
Expand Down Expand Up @@ -158,6 +159,10 @@ void ConfigurationClass::migrate()
strlcpy(config.Mqtt_Hostname, config.Mqtt_Hostname_Short, sizeof(config.Mqtt_Hostname_Short));
}

if (config.Cfg_Version < 0x00011500) {
config.Mqtt_Hass_Expire = MQTT_HASS_EXPIRE;
}

config.Cfg_Version = CONFIG_VERSION;
write();
}
Expand Down
4 changes: 3 additions & 1 deletion src/MqttHassPublishing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ void MqttHassPublishingClass::publishField(std::shared_ptr<InverterAbstract> inv
root[F("unit_of_meas")] = inv->Statistics()->getChannelFieldUnit(channel, fieldType.fieldId);
root[F("uniq_id")] = String(serial) + "_ch" + String(channel) + "_" + fieldName;
root[F("dev")] = deviceObj;
root[F("exp_aft")] = Hoymiles.getNumInverters() * Configuration.get().Mqtt_PublishInterval * 2;
if (Configuration.get().Mqtt_Hass_Expire) {
root[F("exp_aft")] = Hoymiles.getNumInverters() * Configuration.get().Mqtt_PublishInterval * 2;
}
if (devCls != 0) {
root[F("dev_cla")] = devCls;
}
Expand Down
21 changes: 20 additions & 1 deletion src/WebApi_mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void WebApiMqttClass::onMqttStatus(AsyncWebServerRequest* request)
root[F("mqtt_lwt_topic")] = String(config.Mqtt_Topic) + config.Mqtt_LwtTopic;
root[F("mqtt_publish_interval")] = config.Mqtt_PublishInterval;
root[F("mqtt_hass_enabled")] = config.Mqtt_Hass_Enabled;
root[F("mqtt_hass_expire")] = config.Mqtt_Hass_Expire;
root[F("mqtt_hass_retain")] = config.Mqtt_Hass_Retain;
root[F("mqtt_hass_topic")] = config.Mqtt_Hass_Topic;
root[F("mqtt_hass_individualpanels")] = config.Mqtt_Hass_IndividualPanels;
Expand Down Expand Up @@ -71,6 +72,7 @@ void WebApiMqttClass::onMqttAdminGet(AsyncWebServerRequest* request)
root[F("mqtt_lwt_offline")] = config.Mqtt_LwtValue_Offline;
root[F("mqtt_publish_interval")] = config.Mqtt_PublishInterval;
root[F("mqtt_hass_enabled")] = config.Mqtt_Hass_Enabled;
root[F("mqtt_hass_expire")] = config.Mqtt_Hass_Expire;
root[F("mqtt_hass_retain")] = config.Mqtt_Hass_Retain;
root[F("mqtt_hass_topic")] = config.Mqtt_Hass_Topic;
root[F("mqtt_hass_individualpanels")] = config.Mqtt_Hass_IndividualPanels;
Expand Down Expand Up @@ -111,7 +113,23 @@ void WebApiMqttClass::onMqttAdminPost(AsyncWebServerRequest* request)
return;
}

if (!(root.containsKey("mqtt_enabled") && root.containsKey("mqtt_hostname") && root.containsKey("mqtt_port") && root.containsKey("mqtt_username") && root.containsKey("mqtt_password") && root.containsKey("mqtt_topic") && root.containsKey("mqtt_retain") && root.containsKey("mqtt_tls") && root.containsKey("mqtt_lwt_topic") && root.containsKey("mqtt_lwt_online") && root.containsKey("mqtt_lwt_offline") && root.containsKey("mqtt_publish_interval") && root.containsKey("mqtt_hass_enabled") && root.containsKey("mqtt_hass_retain") && root.containsKey("mqtt_hass_topic") && root.containsKey("mqtt_hass_individualpanels"))) {
if (!(root.containsKey("mqtt_enabled")
&& root.containsKey("mqtt_hostname")
&& root.containsKey("mqtt_port")
&& root.containsKey("mqtt_username")
&& root.containsKey("mqtt_password")
&& root.containsKey("mqtt_topic")
&& root.containsKey("mqtt_retain")
&& root.containsKey("mqtt_tls")
&& root.containsKey("mqtt_lwt_topic")
&& root.containsKey("mqtt_lwt_online")
&& root.containsKey("mqtt_lwt_offline")
&& root.containsKey("mqtt_publish_interval")
&& root.containsKey("mqtt_hass_enabled")
&& root.containsKey("mqtt_hass_expire")
&& root.containsKey("mqtt_hass_retain")
&& root.containsKey("mqtt_hass_topic")
&& root.containsKey("mqtt_hass_individualpanels"))) {
retMsg[F("message")] = F("Values are missing!");
response->setLength();
request->send(response);
Expand Down Expand Up @@ -233,6 +251,7 @@ void WebApiMqttClass::onMqttAdminPost(AsyncWebServerRequest* request)
strcpy(config.Mqtt_LwtValue_Offline, root[F("mqtt_lwt_offline")].as<String>().c_str());
config.Mqtt_PublishInterval = root[F("mqtt_publish_interval")].as<uint32_t>();
config.Mqtt_Hass_Enabled = root[F("mqtt_hass_enabled")].as<bool>();
config.Mqtt_Hass_Expire = root[F("mqtt_hass_expire")].as<bool>();
config.Mqtt_Hass_Retain = root[F("mqtt_hass_retain")].as<bool>();
config.Mqtt_Hass_IndividualPanels = root[F("mqtt_hass_individualpanels")].as<bool>();
strcpy(config.Mqtt_Hass_Topic, root[F("mqtt_hass_topic")].as<String>().c_str());
Expand Down
8 changes: 4 additions & 4 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
"bootstrap-icons-vue": "^1.8.1",
"core-js": "^3.25.0",
"spark-md5": "^3.0.2",
"vue": "^3.2.27",
"vue": "^3.2.38",
"vue-class-component": "^8.0.0-0",
"vue-router": "^4.1.5"
},
"devDependencies": {
"@babel/core": "^7.18.13",
"@babel/eslint-parser": "^7.18.9",
"@types/bootstrap": "^5.2.2",
"@types/node": "^18.7.9",
"@types/node": "^18.7.15",
"@types/spark-md5": "^3.0.2",
"@typescript-eslint/parser": "^5.33.1",
"@typescript-eslint/parser": "^5.36.1",
"@vue/cli-plugin-babel": "~5.0.8",
"@vue/cli-plugin-eslint": "~5.0.8",
"@vue/cli-plugin-router": "^5.0.6",
Expand All @@ -33,7 +33,7 @@
"eslint": "^8.23.0",
"eslint-plugin-vue": "^9.4.0",
"typescript": "^4.8.2",
"vue-cli-plugin-compression": "~1.2.0"
"vue-cli-plugin-compression": "~2.0.0"
},
"eslintConfig": {
"root": true,
Expand Down
11 changes: 11 additions & 0 deletions webapp/src/components/MqttAdminView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@
</div>
</div>

<div class="row mb-3">
<label class="col-sm-2 form-check-label" for="inputHassExpire">Enable Expiration</label>
<div class="col-sm-10">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="inputHassExpire"
v-model="mqttConfigList.mqtt_hass_expire" />
</div>
</div>
</div>

<div class="row mb-3">
<label class="col-sm-2 form-check-label" for="inputIndividualPanels">Individual
Panels:</label>
Expand Down Expand Up @@ -241,6 +251,7 @@ export default defineComponent({
mqtt_lwt_online: "",
mqtt_lwt_offline: "",
mqtt_hass_enabled: false,
mqtt_hass_expire: false,
mqtt_hass_retain: false,
mqtt_hass_topic: "",
mqtt_hass_individualpanels: false
Expand Down
10 changes: 10 additions & 0 deletions webapp/src/components/MqttInfoView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@
<span v-else>disabled</span>
</td>
</tr>
<tr>
<th>Expire</th>
<td class="badge" :class="{
'bg-danger': !mqttDataList.mqtt_hass_expire,
'bg-success': mqttDataList.mqtt_hass_expire,
}">
<span v-if="mqttDataList.mqtt_hass_expire">enabled</span>
<span v-else>disabled</span>
</td>
</tr>
<tr>
<th>Individual Panels</th>
<td class="badge" :class="{
Expand Down
Loading

0 comments on commit 5a25ce5

Please sign in to comment.