Skip to content

Commit

Permalink
#31 Build
Browse files Browse the repository at this point in the history
  • Loading branch information
Peyton-McKee committed Jan 24, 2024
1 parent 3f39c74 commit 696b5bc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ edition = "2021"
socketcan = "1.7.0"
paho-mqtt = "0.12.3"
protobuf-codegen = "3.3.0"
protobuf = "3.3.0"
11 changes: 5 additions & 6 deletions src/mqtt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extern crate paho_mqtt as mqtt;
use mqtt::ServerResponse;
use protobuf::Message;
use std::time::Duration;
use std::{process, thread};

Expand Down Expand Up @@ -27,17 +28,15 @@ impl Client for MqttClient {
*/
fn publish(&mut self, data: &Data) {
let topic = data.topic.to_string();
let payload = serverdata::ServerData::new()
.set_value(data.value.to_string())
.set_unit(data.unit.to_string())
.write_to_bytes()
.unwrap();
let mut payload = serverdata::ServerData::new();
payload.unit = data.unit.to_string();
payload.value = data.value.to_string();

/* If the client is initialized, publish the data. */
if let Some(client) = &self.client {
let msg = mqtt::MessageBuilder::new()
.topic(topic)
.payload(payload)
.payload(payload.write_to_bytes().unwrap())
.finalize();

match { client.publish(msg) } {
Expand Down

0 comments on commit 696b5bc

Please sign in to comment.