From afad1d7b95fedc72b635a60e6b49d9664308c128 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Thu, 13 Jul 2023 12:11:23 +0200 Subject: [PATCH] small updates --- .../src/framework/mqtt/MqttStatusForm.tsx | 4 +-- interface/src/project/validators.ts | 27 ++++++++++++++++++- interface/src/types/mqtt.ts | 6 ++--- lib/framework/UploadFileService.cpp | 7 +++-- src/analogsensor.cpp | 15 ++++++++--- src/shower.cpp | 4 +-- src/temperaturesensor.cpp | 4 +-- 7 files changed, 49 insertions(+), 18 deletions(-) diff --git a/interface/src/framework/mqtt/MqttStatusForm.tsx b/interface/src/framework/mqtt/MqttStatusForm.tsx index 65a97a67f..602787d23 100644 --- a/interface/src/framework/mqtt/MqttStatusForm.tsx +++ b/interface/src/framework/mqtt/MqttStatusForm.tsx @@ -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'; } diff --git a/interface/src/project/validators.ts b/interface/src/project/validators.ts index cb4d93160..246c22a7f 100644 --- a/interface/src/project/validators.ts +++ b/interface/src/project/validators.ts @@ -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: [ diff --git a/interface/src/types/mqtt.ts b/interface/src/types/mqtt.ts index 32eb5ea66..df9261f4a 100644 --- a/interface/src/types/mqtt.ts +++ b/interface/src/types/mqtt.ts @@ -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 { diff --git a/lib/framework/UploadFileService.cpp b/lib/framework/UploadFileService.cpp index a15821508..a96f67142 100644 --- a/lib/framework/UploadFileService.cpp +++ b/lib/framework/UploadFileService.cpp @@ -1,4 +1,5 @@ #include +#include 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 diff --git a/src/analogsensor.cpp b/src/analogsensor.cpp index f37c0947a..153ed5e36 100644 --- a/src/analogsensor.cpp +++ b/src/analogsensor.cpp @@ -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(), val_cond); - Mqtt::queue_ha(topic, config.as()); - - sensor.ha_registered = true; + sensor.ha_registered = Mqtt::queue_ha(topic, config.as()); } } } diff --git a/src/shower.cpp b/src/shower.cpp index 477230671..a2e01d9b1 100644 --- a/src/shower.cpp +++ b/src/shower.cpp @@ -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 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()); // publish the config payload with retain flag + ha_configdone_ = Mqtt::queue_ha(topic, doc.as()); // publish the config payload with retain flag } } diff --git a/src/temperaturesensor.cpp b/src/temperaturesensor.cpp index a13b848db..25d1f2c68 100644 --- a/src/temperaturesensor.cpp +++ b/src/temperaturesensor.cpp @@ -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()); - - sensor.ha_registered = true; + sensor.ha_registered = Mqtt::queue_ha(topic, config.as()); } } }