Skip to content

Commit

Permalink
fix: fixed gs not adding SN data when present.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefa168 committed Nov 26, 2023
1 parent a102576 commit 8e874ec
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ timescale-data
.idea/dataSources.xml
.idea/git_toolbox_prj.xml
.idea/remote-targets.xml
playground.sql

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
Expand Down
1 change: 1 addition & 0 deletions .idea/growatt_server.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ impl ConnectionHandler {

debug!("Message type: {:?}", &datamessage.data_type);

let r = sqlx::query!("INSERT INTO inverter_messages (raw, type, header, time) VALUES ($1, $2, $3, $4) returning id",
datamessage.raw, serde_json::to_string(&datamessage.data_type).unwrap(), datamessage.header, datamessage.time)
// First save the complete message
let r = sqlx::query!("INSERT INTO inverter_messages (raw, type, header, time, inverter_sn) VALUES ($1, $2, $3, $4, $5) returning id",
datamessage.raw, serde_json::to_string(&datamessage.data_type).unwrap(), datamessage.header, datamessage.time, datamessage.serial_number)
.fetch_one(&self.db_pool)
// todo handle unlikely scenarios
.await;
Expand All @@ -254,6 +255,7 @@ impl ConnectionHandler {

let id = r.unwrap().id;

// Then all the additional deserialized parts of the message (if present)
for (key, value) in datamessage.data {
sqlx::query!(
"INSERT INTO message_data (message_id, key, value) VALUES ($1, $2, $3)",
Expand Down

0 comments on commit 8e874ec

Please sign in to comment.