Speichern von Holding und Coils ging nicht mehr
This commit is contained in:
parent
e6c60d0707
commit
58f5522442
@ -8,6 +8,7 @@ mqtt:
|
||||
password: 97sm3pHNSMZ4M5qUj0x8
|
||||
path: heizung/paradigma
|
||||
leitsystem_path: heizung/leitsystem2
|
||||
set_write_interval_ms: 2000
|
||||
influxdb:
|
||||
bucket: Paradigma
|
||||
org: skaville
|
||||
|
||||
37
src/main.rs
37
src/main.rs
@ -127,18 +127,10 @@ async fn settings_page(data: web::Data<AppState>) -> Result<HttpResponse> {
|
||||
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
#[serde(untagged)]
|
||||
enum SaveTableRows {
|
||||
InputRegister(Vec<HashMap<String, ModbusInputRegisterConfig>>),
|
||||
HoldingRegister(Vec<HashMap<String, ModbusHoldingRegisterConfig>>),
|
||||
Coils(Vec<HashMap<String, ModbusCoilsConfig>>),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct SaveTableRequest {
|
||||
table_id: String,
|
||||
rows: SaveTableRows,
|
||||
rows: serde_json::Value,
|
||||
}
|
||||
|
||||
async fn save_table(
|
||||
@ -149,25 +141,28 @@ async fn save_table(
|
||||
let conf_path = "paramod.yaml";
|
||||
match req.table_id.as_str() {
|
||||
"modbus_input_register" => {
|
||||
if let SaveTableRows::InputRegister(rows) = req.rows.clone() {
|
||||
let rows: Vec<HashMap<String, ModbusInputRegisterConfig>> =
|
||||
match serde_json::from_value(req.rows.clone()) {
|
||||
Ok(v) => v,
|
||||
Err(e) => return Ok(HttpResponse::BadRequest().body(format!("Falscher Typ für input_register: {}", e))),
|
||||
};
|
||||
config.modbus_input_register = Some(rows);
|
||||
} else {
|
||||
return Ok(HttpResponse::BadRequest().body("Falscher Typ für input_register"));
|
||||
}
|
||||
}
|
||||
"modbus_holding_register" => {
|
||||
if let SaveTableRows::HoldingRegister(rows) = req.rows.clone() {
|
||||
let rows: Vec<HashMap<String, ModbusHoldingRegisterConfig>> =
|
||||
match serde_json::from_value(req.rows.clone()) {
|
||||
Ok(v) => v,
|
||||
Err(e) => return Ok(HttpResponse::BadRequest().body(format!("Falscher Typ für holding_register: {}", e))),
|
||||
};
|
||||
config.modbus_holding_register = Some(rows);
|
||||
} else {
|
||||
return Ok(HttpResponse::BadRequest().body("Falscher Typ für holding_register"));
|
||||
}
|
||||
}
|
||||
"modbus_coils" => {
|
||||
if let SaveTableRows::Coils(rows) = req.rows.clone() {
|
||||
let rows: Vec<HashMap<String, ModbusCoilsConfig>> =
|
||||
match serde_json::from_value(req.rows.clone()) {
|
||||
Ok(v) => v,
|
||||
Err(e) => return Ok(HttpResponse::BadRequest().body(format!("Falscher Typ für coils: {}", e))),
|
||||
};
|
||||
config.modbus_coils = Some(rows);
|
||||
} else {
|
||||
return Ok(HttpResponse::BadRequest().body("Falscher Typ für coils"));
|
||||
}
|
||||
}
|
||||
_ => return Ok(HttpResponse::BadRequest().body("Invalid table_id")),
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ function addRow() {
|
||||
<button class="delete-btn" onclick="deleteRow(this)">🗑️</button>
|
||||
</td>
|
||||
`;
|
||||
} else if (typeof tableId !== 'undefined' && tableId === 'modbus_holding_registers') {
|
||||
} else if (typeof tableId !== 'undefined' && tableId === 'modbus_holding_register') {
|
||||
newRow.innerHTML = `
|
||||
<td><input type='text' class='text-input' data-field='bezeichnung' value='' /></td>
|
||||
<td><input type='text' class='text-input' data-field='adresse' value='' /></td>
|
||||
@ -147,14 +147,14 @@ async function saveTable() {
|
||||
influxdb: influxdb,
|
||||
comment: comment
|
||||
};
|
||||
} else if (typeof tableId !== 'undefined' && tableId === 'modbus_holding_registers') {
|
||||
} else if (typeof tableId !== 'undefined' && tableId === 'modbus_holding_register') {
|
||||
const write = row.querySelector("input[data-field='write']")?.checked || false;
|
||||
const rtype = row.querySelector("input[data-field='type']")?.value || null;
|
||||
const type = row.querySelector("input[data-field='type']")?.value || null;
|
||||
const factor = parseFloat(row.querySelector("input[data-field='factor']")?.value || row.querySelector("input[data-field='faktor']")?.value || '1.0');
|
||||
const comment = row.querySelector("input[data-field='comment']")?.value || null;
|
||||
value = {
|
||||
addr: addr,
|
||||
rtype: rtype,
|
||||
type: type,
|
||||
factor: factor,
|
||||
write: write,
|
||||
mqtt: mqtt,
|
||||
@ -162,12 +162,12 @@ async function saveTable() {
|
||||
comment: comment
|
||||
};
|
||||
} else {
|
||||
const rtype = row.querySelector("input[data-field='type']")?.value || null;
|
||||
const type = row.querySelector("input[data-field='type']")?.value || null;
|
||||
const factor = parseFloat(row.querySelector("input[data-field='factor']")?.value || row.querySelector("input[data-field='faktor']")?.value || '1.0');
|
||||
const comment = row.querySelector("input[data-field='comment']")?.value || null;
|
||||
value = {
|
||||
addr: addr,
|
||||
rtype: rtype,
|
||||
type: type,
|
||||
factor: factor,
|
||||
mqtt: mqtt,
|
||||
influxdb: influxdb,
|
||||
@ -196,8 +196,9 @@ async function saveTable() {
|
||||
messageDiv.className = 'message success';
|
||||
messageDiv.textContent = '✓ Erfolgreich gespeichert!';
|
||||
} else {
|
||||
const errorText = (await response.text()) || 'Unbekannter Fehler';
|
||||
messageDiv.className = 'message error';
|
||||
messageDiv.textContent = '✗ Fehler beim Speichern!';
|
||||
messageDiv.textContent = `✗ Fehler beim Speichern: ${errorText}`;
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user