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