mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
small updates
This commit is contained in:
@@ -68,10 +68,8 @@ const MqttStatusForm: FC = () => {
|
|||||||
return 'Malformed credentials';
|
return 'Malformed credentials';
|
||||||
case MqttDisconnectReason.MQTT_NOT_AUTHORIZED:
|
case MqttDisconnectReason.MQTT_NOT_AUTHORIZED:
|
||||||
return 'Not authorized';
|
return 'Not authorized';
|
||||||
case MqttDisconnectReason.ESP8266_NOT_ENOUGH_SPACE:
|
|
||||||
return 'Device out of memory';
|
|
||||||
case MqttDisconnectReason.TLS_BAD_FINGERPRINT:
|
case MqttDisconnectReason.TLS_BAD_FINGERPRINT:
|
||||||
return 'Server fingerprint invalid';
|
return 'TSL fingerprint invalid';
|
||||||
default:
|
default:
|
||||||
return 'Unknown';
|
return 'Unknown';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export const GPIO_VALIDATOR = {
|
|||||||
if (
|
if (
|
||||||
value &&
|
value &&
|
||||||
(value === 1 ||
|
(value === 1 ||
|
||||||
(value >= 10 && value <= 12) ||
|
(value >= 6 && value <= 12) ||
|
||||||
(value >= 14 && value <= 15) ||
|
(value >= 14 && value <= 15) ||
|
||||||
value === 20 ||
|
value === 20 ||
|
||||||
value === 24 ||
|
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) =>
|
export const createSettingsValidator = (settings: Settings) =>
|
||||||
new Schema({
|
new Schema({
|
||||||
...(settings.board_profile === 'CUSTOM' &&
|
...(settings.board_profile === 'CUSTOM' &&
|
||||||
@@ -69,6 +86,14 @@ export const createSettingsValidator = (settings: Settings) =>
|
|||||||
tx_gpio: [{ required: true, message: 'Tx GPIO is required' }, GPIO_VALIDATORS2],
|
tx_gpio: [{ required: true, message: 'Tx GPIO is required' }, GPIO_VALIDATORS2],
|
||||||
rx_gpio: [{ required: true, message: 'Rx 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 && {
|
...(settings.syslog_enabled && {
|
||||||
syslog_host: [{ required: true, message: 'Host is required' }, IP_OR_HOSTNAME_VALIDATOR],
|
syslog_host: [{ required: true, message: 'Host is required' }, IP_OR_HOSTNAME_VALIDATOR],
|
||||||
syslog_port: [
|
syslog_port: [
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
export enum MqttDisconnectReason {
|
export enum MqttDisconnectReason {
|
||||||
TCP_DISCONNECTED = 0,
|
USER_OK = 0,
|
||||||
MQTT_UNACCEPTABLE_PROTOCOL_VERSION = 1,
|
MQTT_UNACCEPTABLE_PROTOCOL_VERSION = 1,
|
||||||
MQTT_IDENTIFIER_REJECTED = 2,
|
MQTT_IDENTIFIER_REJECTED = 2,
|
||||||
MQTT_SERVER_UNAVAILABLE = 3,
|
MQTT_SERVER_UNAVAILABLE = 3,
|
||||||
MQTT_MALFORMED_CREDENTIALS = 4,
|
MQTT_MALFORMED_CREDENTIALS = 4,
|
||||||
MQTT_NOT_AUTHORIZED = 5,
|
MQTT_NOT_AUTHORIZED = 5,
|
||||||
ESP8266_NOT_ENOUGH_SPACE = 6,
|
TLS_BAD_FINGERPRINT = 6,
|
||||||
TLS_BAD_FINGERPRINT = 7
|
TCP_DISCONNECTED = 7
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MqttStatus {
|
export interface MqttStatus {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <UploadFileService.h>
|
#include <UploadFileService.h>
|
||||||
|
#include <esp_ota_ops.h>
|
||||||
|
|
||||||
using namespace std::placeholders; // for `_1` etc
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
@@ -70,7 +71,7 @@ void UploadFileService::handleUpload(AsyncWebServerRequest * request, const Stri
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// it's firmware - initialize the ArduinoOTA updater
|
// it's firmware - initialize the ArduinoOTA updater
|
||||||
if (Update.begin()) {
|
if (Update.begin(fsize - sizeof(esp_image_header_t))) {
|
||||||
if (strlen(md5) == 32) {
|
if (strlen(md5) == 32) {
|
||||||
Update.setMD5(md5);
|
Update.setMD5(md5);
|
||||||
md5[0] = '\0';
|
md5[0] = '\0';
|
||||||
@@ -88,7 +89,9 @@ void UploadFileService::handleUpload(AsyncWebServerRequest * request, const Stri
|
|||||||
|
|
||||||
if (!is_firmware) {
|
if (!is_firmware) {
|
||||||
if (len) {
|
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 {
|
} else {
|
||||||
// if we haven't delt with an error, continue with the firmware update
|
// if we haven't delt with an error, continue with the firmware update
|
||||||
|
|||||||
@@ -563,6 +563,17 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
// config["step"] = sensor.factor();
|
// config["step"] = sensor.factor();
|
||||||
} else if (sensor.type() == AnalogType::DIGITAL_IN) {
|
} else if (sensor.type() == AnalogType::DIGITAL_IN) {
|
||||||
snprintf(topic, sizeof(topic), "binary_sensor/%s/analogsensor_%02d/config", Mqtt::basename().c_str(), sensor.gpio());
|
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 {
|
} else {
|
||||||
snprintf(topic, sizeof(topic), "sensor/%s/analogsensor_%02d/config", Mqtt::basename().c_str(), sensor.gpio());
|
snprintf(topic, sizeof(topic), "sensor/%s/analogsensor_%02d/config", Mqtt::basename().c_str(), sensor.gpio());
|
||||||
config["stat_cla"] = "measurement";
|
config["stat_cla"] = "measurement";
|
||||||
@@ -575,9 +586,7 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
// add "availability" section
|
// add "availability" section
|
||||||
Mqtt::add_avty_to_doc(stat_t, config.as<JsonObject>(), val_cond);
|
Mqtt::add_avty_to_doc(stat_t, config.as<JsonObject>(), val_cond);
|
||||||
|
|
||||||
Mqtt::queue_ha(topic, config.as<JsonObject>());
|
sensor.ha_registered = Mqtt::queue_ha(topic, config.as<JsonObject>());
|
||||||
|
|
||||||
sensor.ha_registered = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,8 +148,6 @@ void Shower::set_shower_state(bool state, bool force) {
|
|||||||
|
|
||||||
// send out HA MQTT Discovery config topic
|
// send out HA MQTT Discovery config topic
|
||||||
if ((Mqtt::ha_enabled()) && (!ha_configdone_ || force)) {
|
if ((Mqtt::ha_enabled()) && (!ha_configdone_ || force)) {
|
||||||
ha_configdone_ = true;
|
|
||||||
|
|
||||||
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE> doc;
|
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE> doc;
|
||||||
|
|
||||||
doc["name"] = "Shower Active";
|
doc["name"] = "Shower Active";
|
||||||
@@ -189,7 +187,7 @@ void Shower::set_shower_state(bool state, bool force) {
|
|||||||
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||||
snprintf(topic, sizeof(topic), "binary_sensor/%s/shower_active/config", Mqtt::basename().c_str());
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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());
|
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 = Mqtt::queue_ha(topic, config.as<JsonObject>());
|
||||||
|
|
||||||
sensor.ha_registered = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user