mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
merge dallas from #494, add mqtt response for raw telegrams, add read to root, watch-command flexible
This commit is contained in:
@@ -184,6 +184,17 @@ function EMSESPSettingsControllerForm(props: EMSESPSettingsControllerFormProps)
|
||||
<Typography variant="h6" color="primary" >
|
||||
Syslog Settings
|
||||
</Typography>
|
||||
<TextValidator
|
||||
validators={['isIPOrHostname']}
|
||||
errorMessages={["Not a valid IP address or hostname"]}
|
||||
name="syslog_host"
|
||||
label="Syslog IP/Host"
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
value={data.syslog_host}
|
||||
onChange={handleValueChange('syslog_host')}
|
||||
margin="normal"
|
||||
/>
|
||||
<SelectValidator name="syslog_level"
|
||||
label="Syslog Log Level"
|
||||
value={data.syslog_level}
|
||||
@@ -196,33 +207,18 @@ function EMSESPSettingsControllerForm(props: EMSESPSettingsControllerFormProps)
|
||||
<MenuItem value={6}>INFO</MenuItem>
|
||||
<MenuItem value={7}>DEBUG</MenuItem>
|
||||
</SelectValidator>
|
||||
{data.syslog_level !== -1 &&
|
||||
<Fragment>
|
||||
<TextValidator
|
||||
validators={['isIPOrHostname']}
|
||||
errorMessages={["Not a valid IP address or hostname"]}
|
||||
name="syslog_host"
|
||||
label="Syslog IP/Host"
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
value={data.syslog_host}
|
||||
onChange={handleValueChange('syslog_host')}
|
||||
margin="normal"
|
||||
/>
|
||||
<TextValidator
|
||||
validators={['required', 'isNumber', 'minNumber:0', 'maxNumber:65535']}
|
||||
errorMessages={['Syslog Mark is required', "Must be a number", "Must be 0 or higher (0=off)", "Max value is 65535"]}
|
||||
name="syslog_mark_interval"
|
||||
label="Syslog Mark Interval (seconds, 0=off)"
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
value={data.syslog_mark_interval}
|
||||
type="number"
|
||||
onChange={handleValueChange('syslog_mark_interval')}
|
||||
margin="normal"
|
||||
/>
|
||||
</Fragment>
|
||||
}
|
||||
<TextValidator
|
||||
validators={['required', 'isNumber', 'minNumber:0', 'maxNumber:65535']}
|
||||
errorMessages={['Syslog Mark is required', "Must be a number", "Must be 0 or higher (0=off)", "Max value is 65535"]}
|
||||
name="syslog_mark_interval"
|
||||
label="Syslog Mark Interval (seconds, 0=off)"
|
||||
fullWidth
|
||||
variant="outlined"
|
||||
value={data.syslog_mark_interval}
|
||||
type="number"
|
||||
onChange={handleValueChange('syslog_mark_interval')}
|
||||
margin="normal"
|
||||
/>
|
||||
<FormActions>
|
||||
<FormButton startIcon={<SaveIcon />} variant="contained" color="primary" type="submit">
|
||||
Save
|
||||
|
||||
@@ -244,6 +244,17 @@ void EMSESPShell::add_console_commands() {
|
||||
});
|
||||
});
|
||||
|
||||
commands->add_command(ShellContext::MAIN,
|
||||
CommandFlags::ADMIN,
|
||||
flash_string_vector{F_(read)},
|
||||
flash_string_vector{F_(deviceid_mandatory) ,F_(typeid_mandatory)},
|
||||
[=](Shell & shell __attribute__((unused)), const std::vector<std::string> & arguments) {
|
||||
uint8_t device_id = Helpers::hextoint(arguments.front().c_str());
|
||||
uint16_t type_id = Helpers::hextoint(arguments.back().c_str());
|
||||
EMSESP::set_read_id(type_id);
|
||||
EMSESP::send_read_request(type_id, device_id);
|
||||
});
|
||||
|
||||
/*
|
||||
* add all the submenu contexts...
|
||||
*/
|
||||
@@ -397,7 +408,7 @@ void Console::load_standard_commands(unsigned int context) {
|
||||
flash_string_vector{F_(watch)},
|
||||
flash_string_vector{F_(watch_format_optional), F_(watchid_optional)},
|
||||
[](Shell & shell, const std::vector<std::string> & arguments) {
|
||||
uint16_t watch_id;
|
||||
uint16_t watch_id = WATCH_ID_NONE;
|
||||
|
||||
if (!arguments.empty()) {
|
||||
// get raw/pretty
|
||||
@@ -407,16 +418,16 @@ void Console::load_standard_commands(unsigned int context) {
|
||||
emsesp::EMSESP::watch(EMSESP::WATCH_ON); // on
|
||||
} else if (arguments[0] == read_flash_string(F_(off))) {
|
||||
emsesp::EMSESP::watch(EMSESP::WATCH_OFF); // off
|
||||
} else {
|
||||
} else if (emsesp::EMSESP::watch() == EMSESP::WATCH_OFF) {
|
||||
shell.printfln(F_(invalid_watch));
|
||||
return;
|
||||
} else {
|
||||
watch_id = Helpers::hextoint(arguments[0].c_str());
|
||||
}
|
||||
|
||||
if (arguments.size() == 2) {
|
||||
// get the watch_id if its set
|
||||
watch_id = Helpers::hextoint(arguments[1].c_str());
|
||||
} else {
|
||||
watch_id = WATCH_ID_NONE;
|
||||
}
|
||||
|
||||
emsesp::EMSESP::watch_id(watch_id);
|
||||
@@ -440,7 +451,9 @@ void Console::load_standard_commands(unsigned int context) {
|
||||
}
|
||||
|
||||
watch_id = emsesp::EMSESP::watch_id();
|
||||
if (watch_id != WATCH_ID_NONE) {
|
||||
if (watch_id > 0x80) {
|
||||
shell.printfln(F("Filtering only telegrams that match a telegram type of 0x%02X"), watch_id);
|
||||
} else if (watch_id != WATCH_ID_NONE) {
|
||||
shell.printfln(F("Filtering only telegrams that match a device ID or telegram type of 0x%02X"), watch_id);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -316,6 +316,25 @@ void EMSESP::publish_sensor_values(const bool force) {
|
||||
}
|
||||
}
|
||||
|
||||
void EMSESP::publish_response(std::shared_ptr<const Telegram> telegram) {
|
||||
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_SMALL> doc;
|
||||
char buffer[100];
|
||||
doc["src"] = Helpers::hextoa(buffer, telegram->src);
|
||||
doc["dest"] = Helpers::hextoa(buffer, telegram->dest);
|
||||
doc["type"] = Helpers::hextoa(buffer, telegram->type_id);
|
||||
doc["offset"] = Helpers::hextoa(buffer, telegram->offset);
|
||||
strcpy(buffer, Helpers::data_to_hex(telegram->message_data, telegram->message_length).c_str());
|
||||
doc["data"] = buffer;
|
||||
if (telegram->message_length <= 4) {
|
||||
uint32_t value = 0;
|
||||
for (uint8_t i = 0; i < telegram->message_length; i++) {
|
||||
value = (value << 8) + telegram->message_data[i];
|
||||
}
|
||||
doc["value"] = value;
|
||||
}
|
||||
Mqtt::publish("response", doc);
|
||||
}
|
||||
|
||||
// search for recognized device_ids : Me, All, otherwise print hex value
|
||||
std::string EMSESP::device_tostring(const uint8_t device_id) {
|
||||
if ((device_id & 0x7F) == rxservice_.ems_bus_id()) {
|
||||
@@ -484,6 +503,7 @@ bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
// if watching...
|
||||
if (telegram->type_id == read_id_) {
|
||||
LOG_NOTICE(pretty_telegram(telegram).c_str());
|
||||
publish_response(telegram);
|
||||
read_id_ = WATCH_ID_NONE;
|
||||
} else if (watch() == WATCH_ON) {
|
||||
if ((watch_id_ == WATCH_ID_NONE) || (telegram->type_id == watch_id_)
|
||||
|
||||
@@ -176,6 +176,7 @@ class EMSESP {
|
||||
|
||||
static void process_UBADevices(std::shared_ptr<const Telegram> telegram);
|
||||
static void process_version(std::shared_ptr<const Telegram> telegram);
|
||||
static void publish_response(std::shared_ptr<const Telegram> telegram);
|
||||
|
||||
static constexpr uint32_t EMS_FETCH_FREQUENCY = 60000; // check every minute
|
||||
static uint32_t last_fetch_;
|
||||
|
||||
@@ -67,7 +67,7 @@ void Sensors::loop() {
|
||||
if (state_ == State::IDLE) {
|
||||
if (time_now - last_activity_ >= READ_INTERVAL_MS) {
|
||||
// LOG_DEBUG(F("Read sensor temperature")); // uncomment for debug
|
||||
if (bus_.reset()) {
|
||||
if (bus_.reset() || parasite_) {
|
||||
YIELD;
|
||||
bus_.skip();
|
||||
bus_.write(CMD_CONVERT_TEMP, parasite_ ? 1 : 0);
|
||||
@@ -97,8 +97,9 @@ void Sensors::loop() {
|
||||
uint8_t addr[ADDR_LEN] = {0};
|
||||
|
||||
if (bus_.search(addr)) {
|
||||
bus_.depower();
|
||||
|
||||
if (!parasite_) {
|
||||
bus_.depower();
|
||||
}
|
||||
if (bus_.crc8(addr, ADDR_LEN - 1) == addr[ADDR_LEN - 1]) {
|
||||
switch (addr[0]) {
|
||||
case TYPE_DS18B20:
|
||||
@@ -125,7 +126,9 @@ void Sensors::loop() {
|
||||
LOG_ERROR(F("Invalid sensor %s"), Device(addr).to_string().c_str());
|
||||
}
|
||||
} else {
|
||||
bus_.depower();
|
||||
if (!parasite_) {
|
||||
bus_.depower();
|
||||
}
|
||||
if ((found_.size() >= devices_.size()) || (retrycnt_ > 5)) {
|
||||
if (found_.size() == devices_.size()) {
|
||||
for (uint8_t i = 0; i < devices_.size(); i++) {
|
||||
|
||||
@@ -95,7 +95,7 @@ std::string Telegram::to_string() const {
|
||||
data[2] = this->type_id;
|
||||
length = 5;
|
||||
}
|
||||
} else if (this->operation == Telegram::Operation::TX_WRITE) {
|
||||
} else {
|
||||
data[1] = this->dest;
|
||||
if (this->type_id > 0xFF) {
|
||||
data[2] = 0xFF;
|
||||
@@ -109,10 +109,6 @@ std::string Telegram::to_string() const {
|
||||
for (uint8_t i = 0; i < this->message_length; i++) {
|
||||
data[length++] = this->message_data[i];
|
||||
}
|
||||
} else {
|
||||
for (uint8_t i = 0; i < this->message_length; i++) {
|
||||
data[length++] = this->message_data[i];
|
||||
}
|
||||
}
|
||||
|
||||
return Helpers::data_to_hex(data, length);
|
||||
@@ -473,7 +469,9 @@ void TxService::add(uint8_t operation, const uint8_t * data, const uint8_t lengt
|
||||
operation = Telegram::Operation::TX_READ;
|
||||
} else {
|
||||
operation = Telegram::Operation::TX_WRITE;
|
||||
set_post_send_query(type_id);
|
||||
}
|
||||
EMSESP::set_read_id(type_id);
|
||||
}
|
||||
|
||||
auto telegram = std::make_shared<Telegram>(operation, src, dest, type_id, offset, message_data, message_length); // operation is TX_WRITE or TX_READ
|
||||
@@ -536,7 +534,7 @@ void TxService::send_raw(const char * telegram_data) {
|
||||
return; // nothing to send
|
||||
}
|
||||
|
||||
add(Telegram::Operation::TX_RAW, data, count + 1); // add to Tx queue
|
||||
add(Telegram::Operation::TX_RAW, data, count + 1, true); // add to front of Tx queue
|
||||
}
|
||||
|
||||
// add last Tx to tx queue and increment count
|
||||
|
||||
Reference in New Issue
Block a user