Started to rewrite vrmgrabber in rust.

This commit is contained in:
Kim Baumgartner 2023-07-27 16:52:40 +02:00
parent 21a0603309
commit 3ab4383eab
4 changed files with 2204 additions and 1 deletions

View File

@ -1,4 +1,4 @@
// && \ // dotnet publish BmsTunnel.csproj -c Release -r linux-arm -p:PublishSingleFile=true --self-contained true && \
// rsync -av bin/Release/net6.0/linux-arm/publish/ root@10.2.1.6:/home/root/tunnel && clear && \ // rsync -av bin/Release/net6.0/linux-arm/publish/ root@10.2.1.6:/home/root/tunnel && clear && \
// ssh root@10.2.1.6 /home/root/tunnel/BmsTunnel // ssh root@10.2.1.6 /home/root/tunnel/BmsTunnel

2020
rust/VrmGrabberOxidised/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
[package]
name = "VrmGrabberOxidised"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rocket = "=0.5.0-rc.3"
reqwest = "0.11.18"
openssl = { version = "0.10", features = ["vendored"]}
serde = {version = "1.0.173", features = ["derive"]}
serde_json = "1.0.103"
handlebars = "5.0.0-beta.1"
urlencoding = "2.1.2"

View File

@ -0,0 +1,168 @@
use rocket::serde;
use handlebars::Handlebars;
// use rocket::serde::__private::de::TagContentOtherField::Content;
use urlencoding::encode;
mod installation;
mod vrm_account;
struct InstallationToHtmlInterface<'a> {
Name: &'a str,
Ip: i64,
Vrm: &'a str,
Identifier: &'a str,
Serial: &'a str,
EscapedName: &'a str,
Online: &'a str,
LastSeen: &'a str,
NumBatteries: &'a str,
BatteryVersion: &'a str,
ServerIp : &'a str,
FirmwareVersion: &'a str,
}
// impl Default for InstallationToHtmlInterface{
// fn default() -> Self {
// Self{
// Name: "",
// Ip: 0,
// Vrm: "",
// Identifier: "",
// Serial: "",
// EscapedName: "",
// Online: "",
// LastSeen: "",
// NumBatteries: "",
// BatteryVersion: "",
// ServerIp : "10.2.0.1",
// FirmwareVersion: "AF09",
// }
// }
// }
#[macro_use] extern crate rocket;
#[get("/")]
async fn index() -> String{
let res = vrm_account::all_installations_request().await;
let json = rocket::serde::Deserialize(res.unwrap().text().await.unwrap());
let source = "<head>
<style>
tbody {
background-color: #e4f0f5;
}
tbody tr:nth-child(odd) {
background-color: #ECE9E9;
}
th, td { /* cell */
padding: 0.75rem;
font-size: 0.9375rem;
}
th { /* header cell */
font-weight: 700;
text-align: left;
color: #272838;
border-bottom: 2px solid #EB9486;
position: sticky;
top: 0;
background-color: #F9F8F8;
}
table {
border-collapse: collapse;
width: 100%;
border: 2px solid rgb(200, 200, 200);
letter-spacing: 1px;
font-family: sans-serif;
font-size: 0.8rem;
position: absolute; top: 0; bottom: 0; left: 0; right: 0;
}
thead th {
border: 1px solid rgb(190, 190, 190);
padding: 5px 10px;
position: sticky;
position: -webkit-sticky;
top: 0px;
background: white;
z-index: 999;
}
td {
text-align: left;
}
#managerTable {
overflow: hidden;
}</style></head>
<div id='managerTable'>
<table>
<tbody>
<tr>
<th>Name</th>
<th>Gui</th>
<th>VRM</th>
<th>Grafana</th>
<th>Identifier</th>
<th>Last Seen</th>
<th>Serial</th>
<th>#Batteries</th>
<th>Firmware-Version</th>
<th>Update</th>
</tr>
{{#inst}}
{{> installations}}
{{/inst}}
</tbody>
</table>
<div id='managerTable'>";
let partialSource= "<tr><td>{{Name}}</td>
<td><a target='_blank' href=http://{{Ip}}>{{online}} {{Ip}}</a></td>
<td><a target='_blank' href=https://vrm.victronenergy.com/installation/{{Vrm}}/dashboard>VRM</a></td>
<td><a target='_blank' href='https://salidomo.innovenergy.ch/d/ENkNRQXmk/installation?refresh=5s&orgId=1&var-Installation={{EscapedName}}&kiosk=tv'>Grafana</a></td>
<td>{{Identifier}}</td>
<td>{{LastSeen}}</td>
<td>{{Serial}}</td>
<td>{{NumBatteries}}</td>
<td>{{BatteryVersion}}</td>
<td><a target='_blank' href=https://{{ServerIp}}/UpdateBatteryFirmware/{{Ip}}/{{NumBatteries}}>⬆️{{FirmwareVersion}}</a></td>
</tr>";
let mut handlebars = Handlebars::new();
handlebars.register_template_string("installations", partialSource);
let mut installsForHtml = Vec::<InstallationToHtmlInterface>::new();
for inst in json["records"] {
let mut installation = InstallationToHtmlInterface {
Name: inst["name"],
Ip: 0, // TODO
Vrm: inst["idSite"].parse::<i64>(),
Identifier: inst["identifier"],
Serial: "", //Todo Grab and parse Details
EscapedName: &encode(inst["name"]).to_string(),
Online: "",
LastSeen: "",
NumBatteries: "",
BatteryVersion: "",
ServerIp : "10.2.0.1",
FirmwareVersion: "AF09",
};
installsForHtml.push(installation)
}
let mut data = installsForHtml;
let result = handlebars.render(source, &data);
return result.unwrap();
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![index])
}