small updates

This commit is contained in:
MichaelDvP
2023-07-13 12:11:23 +02:00
parent 17b4964b01
commit afad1d7b95
7 changed files with 49 additions and 18 deletions

View File

@@ -68,10 +68,8 @@ const MqttStatusForm: FC = () => {
return 'Malformed credentials';
case MqttDisconnectReason.MQTT_NOT_AUTHORIZED:
return 'Not authorized';
case MqttDisconnectReason.ESP8266_NOT_ENOUGH_SPACE:
return 'Device out of memory';
case MqttDisconnectReason.TLS_BAD_FINGERPRINT:
return 'Server fingerprint invalid';
return 'TSL fingerprint invalid';
default:
return 'Unknown';
}

View File

@@ -8,7 +8,7 @@ export const GPIO_VALIDATOR = {
if (
value &&
(value === 1 ||
(value >= 10 && value <= 12) ||
(value >= 6 && value <= 12) ||
(value >= 14 && value <= 15) ||
value === 20 ||
value === 24 ||
@@ -43,6 +43,23 @@ export const GPIO_VALIDATORS2 = {
}
};
export const GPIO_VALIDATORS3 = {
validator(rule: InternalRuleItem, value: number, callback: (error?: string) => void) {
if (
value &&
((value >= 19 && value <= 20) ||
(value >= 22 && value <= 37) ||
(value >= 39 && value <= 42) ||
value > 48 ||
value < 0)
) {
callback('Must be an valid GPIO port');
} else {
callback();
}
}
};
export const createSettingsValidator = (settings: Settings) =>
new Schema({
...(settings.board_profile === 'CUSTOM' &&
@@ -69,6 +86,14 @@ export const createSettingsValidator = (settings: Settings) =>
tx_gpio: [{ required: true, message: 'Tx GPIO is required' }, GPIO_VALIDATORS2],
rx_gpio: [{ required: true, message: 'Rx GPIO is required' }, GPIO_VALIDATORS2]
}),
...(settings.board_profile === 'CUSTOM' &&
settings.platform === 'ESP32-S3' && {
led_gpio: [{ required: true, message: 'LED GPIO is required' }, GPIO_VALIDATORS3],
dallas_gpio: [{ required: true, message: 'GPIO is required' }, GPIO_VALIDATORS3],
pbutton_gpio: [{ required: true, message: 'Button GPIO is required' }, GPIO_VALIDATORS3],
tx_gpio: [{ required: true, message: 'Tx GPIO is required' }, GPIO_VALIDATORS3],
rx_gpio: [{ required: true, message: 'Rx GPIO is required' }, GPIO_VALIDATORS3]
}),
...(settings.syslog_enabled && {
syslog_host: [{ required: true, message: 'Host is required' }, IP_OR_HOSTNAME_VALIDATOR],
syslog_port: [

View File

@@ -1,12 +1,12 @@
export enum MqttDisconnectReason {
TCP_DISCONNECTED = 0,
USER_OK = 0,
MQTT_UNACCEPTABLE_PROTOCOL_VERSION = 1,
MQTT_IDENTIFIER_REJECTED = 2,
MQTT_SERVER_UNAVAILABLE = 3,
MQTT_MALFORMED_CREDENTIALS = 4,
MQTT_NOT_AUTHORIZED = 5,
ESP8266_NOT_ENOUGH_SPACE = 6,
TLS_BAD_FINGERPRINT = 7
TLS_BAD_FINGERPRINT = 6,
TCP_DISCONNECTED = 7
}
export interface MqttStatus {

View File

@@ -1,4 +1,5 @@
#include <UploadFileService.h>
#include <esp_ota_ops.h>
using namespace std::placeholders; // for `_1` etc
@@ -70,7 +71,7 @@ void UploadFileService::handleUpload(AsyncWebServerRequest * request, const Stri
}
#endif
// it's firmware - initialize the ArduinoOTA updater
if (Update.begin()) {
if (Update.begin(fsize - sizeof(esp_image_header_t))) {
if (strlen(md5) == 32) {
Update.setMD5(md5);
md5[0] = '\0';
@@ -88,7 +89,9 @@ void UploadFileService::handleUpload(AsyncWebServerRequest * request, const Stri
if (!is_firmware) {
if (len) {
request->_tempFile.write(data, len); // stream the incoming chunk to the opened file
if (len != request->_tempFile.write(data, len)) { // stream the incoming chunk to the opened file
handleError(request, 507); // 507-Insufficient Storage
}
}
} else {
// if we haven't delt with an error, continue with the firmware update

View File

@@ -563,6 +563,17 @@ void AnalogSensor::publish_values(const bool force) {
// config["step"] = sensor.factor();
} else if (sensor.type() == AnalogType::DIGITAL_IN) {
snprintf(topic, sizeof(topic), "binary_sensor/%s/analogsensor_%02d/config", Mqtt::basename().c_str(), sensor.gpio());
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
config["pl_on"] = true;
config["pl_off"] = false;
} else if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
config["pl_on"] = 1;
config["pl_off"] = 0;
} else {
char result[12];
config["pl_on"] = Helpers::render_boolean(result, true);
config["pl_off"] = Helpers::render_boolean(result, false);
}
} else {
snprintf(topic, sizeof(topic), "sensor/%s/analogsensor_%02d/config", Mqtt::basename().c_str(), sensor.gpio());
config["stat_cla"] = "measurement";
@@ -575,9 +586,7 @@ void AnalogSensor::publish_values(const bool force) {
// add "availability" section
Mqtt::add_avty_to_doc(stat_t, config.as<JsonObject>(), val_cond);
Mqtt::queue_ha(topic, config.as<JsonObject>());
sensor.ha_registered = true;
sensor.ha_registered = Mqtt::queue_ha(topic, config.as<JsonObject>());
}
}
}

View File

@@ -148,8 +148,6 @@ void Shower::set_shower_state(bool state, bool force) {
// send out HA MQTT Discovery config topic
if ((Mqtt::ha_enabled()) && (!ha_configdone_ || force)) {
ha_configdone_ = true;
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE> doc;
doc["name"] = "Shower Active";
@@ -189,7 +187,7 @@ void Shower::set_shower_state(bool state, bool force) {
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
snprintf(topic, sizeof(topic), "binary_sensor/%s/shower_active/config", Mqtt::basename().c_str());
Mqtt::queue_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
ha_configdone_ = Mqtt::queue_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
}
}

View File

@@ -555,9 +555,7 @@ void TemperatureSensor::publish_values(const bool force) {
snprintf(topic, sizeof(topic), "sensor/%s/temperaturesensor_%s/config", Mqtt::basename().c_str(), sensorid.c_str());
Mqtt::queue_ha(topic, config.as<JsonObject>());
sensor.ha_registered = true;
sensor.ha_registered = Mqtt::queue_ha(topic, config.as<JsonObject>());
}
}
}