Skip to content

Commit

Permalink
Remove the test.mosquitto.org URL in the MQTT settings #829
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Dec 23, 2022
1 parent 3c91ac2 commit ca871f6
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG_LATEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
- Add more bus-ids [#673](https://github.com/emsesp/EMS-ESP32/issues/673)
- Use HA connectivity device class for Status, added boot time [#751](https://github.com/emsesp/EMS-ESP32/issues/751)
- Add commands for analog sensors outputs
- Support for multiple EMS-ESPs with MQTT and HA [[#759](https://github.com/emsesp/EMS-ESP32/issues/759)]
- Settings for heatpump silent mode and additional heater [[#802](https://github.com/emsesp/EMS-ESP32/issues/802)] [[#803](https://github.com/emsesp/EMS-ESP32/issues/803)]
- Support for multiple EMS-ESPs with MQTT and HA [#759](https://github.com/emsesp/EMS-ESP32/issues/759)
- Settings for heatpump silent mode and additional heater [#802](https://github.com/emsesp/EMS-ESP32/issues/802)] [[#803](https://github.com/emsesp/EMS-ESP32/issues/803)
- Default MQTT hostname is blank [#829](https://github.com/emsesp/EMS-ESP32/issues/829)

## Fixed

Expand Down
6 changes: 3 additions & 3 deletions factory_settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ build_flags =

; Access point settings
-D FACTORY_AP_PROVISION_MODE=AP_MODE_DISCONNECTED
-D FACTORY_AP_SSID=\"ems-esp\" ; 1-64 characters
-D FACTORY_AP_PASSWORD=\"ems-esp-neo\" ; 8-64 characters
-D FACTORY_AP_SSID=\"ems-esp\"
-D FACTORY_AP_PASSWORD=\"ems-esp-neo\"
-D FACTORY_AP_LOCAL_IP=\"192.168.4.1\"
-D FACTORY_AP_GATEWAY_IP=\"192.168.4.1\"
-D FACTORY_AP_SUBNET_MASK=\"255.255.255.0\"
Expand All @@ -32,7 +32,7 @@ build_flags =

; MQTT settings
-D FACTORY_MQTT_ENABLED=false
-D FACTORY_MQTT_HOST=\"test.mosquitto.org\"
-D FACTORY_MQTT_HOST=\"\"
-D FACTORY_MQTT_PORT=1883
-D FACTORY_MQTT_USERNAME=\"\"
-D FACTORY_MQTT_PASSWORD=\"\"
Expand Down
4 changes: 2 additions & 2 deletions interface/src/framework/mqtt/MqttSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ValidateFieldsError } from 'async-validator';
import { Button, Checkbox, MenuItem, Grid, Typography, InputAdornment } from '@mui/material';
import SaveIcon from '@mui/icons-material/Save';

import { MQTT_SETTINGS_VALIDATOR, validate } from '../../validators';
import { createMqttSettingsValidator, validate } from '../../validators';
import {
BlockFormControlLabel,
ButtonRow,
Expand Down Expand Up @@ -39,7 +39,7 @@ const MqttSettingsForm: FC = () => {
const validateAndSubmit = async () => {
try {
setFieldErrors(undefined);
await validate(MQTT_SETTINGS_VALIDATOR, data);
await validate(createMqttSettingsValidator(data), data);
saveData();
} catch (errors: any) {
setFieldErrors(errors);
Expand Down
36 changes: 20 additions & 16 deletions interface/src/validators/mqtt.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import Schema from 'async-validator';
import { MqttSettings } from '../types';
import { IP_OR_HOSTNAME_VALIDATOR } from './shared';

export const MQTT_SETTINGS_VALIDATOR = new Schema({
host: [{ required: true, message: 'Host is required' }, IP_OR_HOSTNAME_VALIDATOR],
base: { required: true, message: 'Base is required' },
port: [
{ required: true, message: 'Port is required' },
{ type: 'number', min: 0, max: 65535, message: 'Invalid Port' }
],
keep_alive: [
{ required: true, message: 'Keep alive is required' },
{ type: 'number', min: 1, max: 86400, message: 'Keep alive must be between 1 and 86400' }
],
publish_time_heartbeat: [
{ required: true, message: 'Heartbeat is required' },
{ type: 'number', min: 10, max: 86400, message: 'Heartbeat must be between 10 and 86400' }
]
});
export const createMqttSettingsValidator = (mqttSettings: MqttSettings) =>
new Schema({
...(mqttSettings.enabled && {
host: [{ required: true, message: 'Host is required' }, IP_OR_HOSTNAME_VALIDATOR],
base: { required: true, message: 'Base is required' },
port: [
{ required: true, message: 'Port is required' },
{ type: 'number', min: 0, max: 65535, message: 'Invalid Port' }
],
keep_alive: [
{ required: true, message: 'Keep alive is required' },
{ type: 'number', min: 1, max: 86400, message: 'Keep alive must be between 1 and 86400' }
],
publish_time_heartbeat: [
{ required: true, message: 'Heartbeat is required' },
{ type: 'number', min: 10, max: 86400, message: 'Heartbeat must be between 10 and 86400' }
]
})
});
6 changes: 3 additions & 3 deletions lib/framework/MqttSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ void MqttSettingsService::configureMqtt() {
// disconnect if connected
_mqttClient.disconnect();
// only connect if WiFi is connected and MQTT is enabled
if (_state.enabled && emsesp::EMSESP::system_.network_connected()) {
// emsesp::EMSESP::logger().info("Configuring Mqtt client");
if (_state.enabled && emsesp::EMSESP::system_.network_connected() && !_state.host.isEmpty()) {
// emsesp::EMSESP::logger().info("Configuring MQTT client");
_mqttClient.setServer(retainCstr(_state.host.c_str(), &_retainedHost), _state.port);
if (_state.username.length() > 0) {
_mqttClient.setCredentials(retainCstr(_state.username.c_str(), &_retainedUsername),
Expand All @@ -140,7 +140,7 @@ void MqttSettingsService::configureMqtt() {
_mqttClient.setMaxTopicLength(FACTORY_MQTT_MAX_TOPIC_LENGTH); // hardcode. We don't take this from the settings anymore.
_mqttClient.connect();
// } else {
// emsesp::EMSESP::logger().info("Error configuring Mqtt client");
// emsesp::EMSESP::logger().info("Error configuring MQTT client");
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/framework/MqttSettingsService.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#endif

#ifndef FACTORY_MQTT_HOST
#define FACTORY_MQTT_HOST "test.mosquitto.org"
#define FACTORY_MQTT_HOST "" // is blank
#endif

#ifndef FACTORY_MQTT_PORT
Expand Down

0 comments on commit ca871f6

Please sign in to comment.