This commit is contained in:
parent
871020ca55
commit
853da3974c
3 changed files with 15 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
||||||
use matrix_sdk::config::SyncSettings;
|
use matrix_sdk::config::SyncSettings;
|
||||||
use meshtastic::api::StreamApi;
|
use meshtastic::api::StreamApi;
|
||||||
|
use meshtastic::utils;
|
||||||
use tokio::sync::mpsc::UnboundedReceiver;
|
use tokio::sync::mpsc::UnboundedReceiver;
|
||||||
|
|
||||||
use crate::{config, db, matrix};
|
use crate::{config, db, matrix};
|
||||||
|
@ -22,13 +23,8 @@ impl Bridge {
|
||||||
|
|
||||||
// setup meshtastic connection
|
// setup meshtastic connection
|
||||||
let stream_api = StreamApi::new();
|
let stream_api = StreamApi::new();
|
||||||
let serial_stream = meshtastic::utils::stream::build_serial_stream(
|
let tcp_stream = utils::stream::build_tcp_stream(config.meshtastic.hostname).await?;
|
||||||
config.meshtastic.device,
|
let (meshtastic_listener, meshtastic_stream_api) = stream_api.connect(tcp_stream).await;
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)?;
|
|
||||||
let (meshtastic_listener, meshtastic_stream_api) = stream_api.connect(serial_stream).await;
|
|
||||||
|
|
||||||
// setup matrix client
|
// setup matrix client
|
||||||
let matrix_client = matrix::build(config.matrix)
|
let matrix_client = matrix::build(config.matrix)
|
||||||
|
|
|
@ -20,7 +20,8 @@ pub(crate) struct MatrixConfig {
|
||||||
|
|
||||||
#[derive(serde::Deserialize, Debug)]
|
#[derive(serde::Deserialize, Debug)]
|
||||||
pub(crate) struct MeshtasticConfig {
|
pub(crate) struct MeshtasticConfig {
|
||||||
pub(crate) device: String,
|
#[serde(default = "get_meshtastic_hostname")]
|
||||||
|
pub(crate) hostname: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_device_name() -> String {
|
fn get_device_name() -> String {
|
||||||
|
@ -38,6 +39,13 @@ fn get_matrix_password() -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_meshtastic_hostname() -> String {
|
||||||
|
match std::env::var("MESHTASTIC_HOSTNAME") {
|
||||||
|
Ok(p) => p,
|
||||||
|
Err(_) => "meshtastic.local".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) async fn read_config() -> Config {
|
pub(crate) async fn read_config() -> Config {
|
||||||
let filename = match std::env::var("CONFIG_PATH") {
|
let filename = match std::env::var("CONFIG_PATH") {
|
||||||
Ok(value) => value,
|
Ok(value) => value,
|
||||||
|
|
|
@ -18,8 +18,9 @@ pub(crate) async fn build(
|
||||||
config: config::MeshtasticConfig,
|
config: config::MeshtasticConfig,
|
||||||
) -> Result<MeshtasticClient, Box<dyn std::error::Error>> {
|
) -> Result<MeshtasticClient, Box<dyn std::error::Error>> {
|
||||||
let stream_api = StreamApi::new();
|
let stream_api = StreamApi::new();
|
||||||
let serial_stream = utils::stream::build_serial_stream(config.device, None, None, None)?;
|
|
||||||
let (decoded_listener, stream_api) = stream_api.connect(serial_stream).await;
|
let tcp_stream = utils::stream::build_tcp_stream(config.hostname).await?;
|
||||||
|
let (decoded_listener, stream_api) = stream_api.connect(tcp_stream).await;
|
||||||
|
|
||||||
log::info!("connected to meshtastic device");
|
log::info!("connected to meshtastic device");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue