Compare commits
11 commits
matrix-ses
...
main
Author | SHA1 | Date | |
---|---|---|---|
b6f51299f7 | |||
795836e81b | |||
677d5ea9ab | |||
a2dd1f77ac | |||
4f5b878606 | |||
853da3974c | |||
871020ca55 | |||
148190a768 | |||
af3d7c316a | |||
d1a6a16a08 | |||
7dc750d68b |
5 changed files with 108 additions and 70 deletions
78
Cargo.lock
generated
78
Cargo.lock
generated
|
@ -11,7 +11,7 @@ dependencies = [
|
|||
"macroific",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -129,9 +129,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.89"
|
||||
version = "1.0.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6"
|
||||
checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8"
|
||||
|
||||
[[package]]
|
||||
name = "anymap2"
|
||||
|
@ -150,7 +150,7 @@ dependencies = [
|
|||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -211,7 +211,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -222,7 +222,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -658,7 +658,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -762,7 +762,7 @@ dependencies = [
|
|||
"macroific",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -786,7 +786,7 @@ checksum = "8034092389675178f570469e6c3b0465d3d30b4505c294a6550db47f3c17ad18"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -809,7 +809,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -995,7 +995,7 @@ dependencies = [
|
|||
"macroific",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1130,7 +1130,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1708,7 +1708,7 @@ dependencies = [
|
|||
"cfg-if",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1719,7 +1719,7 @@ checksum = "13198c120864097a565ccb3ff947672d969932b7975ebd4085732c9f09435e55"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1732,7 +1732,7 @@ dependencies = [
|
|||
"macroific_core",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1776,7 +1776,7 @@ dependencies = [
|
|||
"proc-macro-error2",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2297,7 +2297,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2621,7 +2621,7 @@ dependencies = [
|
|||
"itertools 0.12.1",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2989,7 +2989,7 @@ dependencies = [
|
|||
"quote",
|
||||
"ruma-identifiers-validation",
|
||||
"serde",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
"toml",
|
||||
]
|
||||
|
||||
|
@ -3105,9 +3105,9 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.210"
|
||||
version = "1.0.213"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a"
|
||||
checksum = "3ea7893ff5e2466df8d720bb615088341b295f849602c6956047f8f80f0e9bc1"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
@ -3146,13 +3146,13 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.210"
|
||||
version = "1.0.213"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
|
||||
checksum = "7e85ad2009c50b58e87caa8cd6dac16bdf511bbfb7af6c33df902396aa480fa5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -3170,9 +3170,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.128"
|
||||
version = "1.0.129"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8"
|
||||
checksum = "6dbcf9b78a125ee667ae19388837dd12294b858d101fdd393cb9d5501ef09eb2"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
|
@ -3558,9 +3558,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.79"
|
||||
version = "2.0.82"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590"
|
||||
checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -3624,7 +3624,7 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -3654,9 +3654,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
|||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.40.0"
|
||||
version = "1.41.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998"
|
||||
checksum = "145f3413504347a2be84393cc8a7d2fb4d863b375909ea59f2158261aa258bbb"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"bytes",
|
||||
|
@ -3678,7 +3678,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -3811,7 +3811,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -4060,7 +4060,7 @@ dependencies = [
|
|||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
|
@ -4094,7 +4094,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
@ -4227,7 +4227,7 @@ checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -4238,7 +4238,7 @@ checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -4473,7 +4473,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -4493,5 +4493,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.79",
|
||||
"syn 2.0.82",
|
||||
]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
FROM library/rust:1.81 AS build
|
||||
FROM library/rust:1.82 AS build
|
||||
# not clear what this is used for
|
||||
RUN apt-get update && apt-get install -y libdbus-1-dev pkg-config
|
||||
COPY . /src
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use matrix_sdk::config::SyncSettings;
|
||||
use meshtastic::api::StreamApi;
|
||||
use meshtastic::utils;
|
||||
use tokio::sync::mpsc::UnboundedReceiver;
|
||||
|
||||
use crate::{config, db, matrix};
|
||||
|
@ -22,13 +23,8 @@ impl Bridge {
|
|||
|
||||
// setup meshtastic connection
|
||||
let stream_api = StreamApi::new();
|
||||
let serial_stream = meshtastic::utils::stream::build_serial_stream(
|
||||
config.meshtastic.device,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)?;
|
||||
let (meshtastic_listener, meshtastic_stream_api) = stream_api.connect(serial_stream).await;
|
||||
let tcp_stream = utils::stream::build_tcp_stream(config.meshtastic.address).await?;
|
||||
let (meshtastic_listener, meshtastic_stream_api) = stream_api.connect(tcp_stream).await;
|
||||
|
||||
// setup matrix client
|
||||
let matrix_client = matrix::build(config.matrix)
|
||||
|
|
|
@ -11,6 +11,7 @@ pub(crate) struct Config {
|
|||
#[derive(serde::Deserialize, Debug)]
|
||||
pub(crate) struct MatrixConfig {
|
||||
pub(crate) username: String,
|
||||
#[serde(default = "get_matrix_password")]
|
||||
pub(crate) password: String,
|
||||
#[serde(default = "get_device_name")]
|
||||
pub(crate) device_name: String,
|
||||
|
@ -19,7 +20,8 @@ pub(crate) struct MatrixConfig {
|
|||
|
||||
#[derive(serde::Deserialize, Debug)]
|
||||
pub(crate) struct MeshtasticConfig {
|
||||
pub(crate) device: String,
|
||||
#[serde(default = "get_meshtastic_address")]
|
||||
pub(crate) address: String, // expected format is host:port
|
||||
}
|
||||
|
||||
fn get_device_name() -> String {
|
||||
|
@ -30,6 +32,20 @@ fn get_db_uri() -> String {
|
|||
"sqlite://matrix-meshtastic-bridge.db".to_string()
|
||||
}
|
||||
|
||||
fn get_matrix_password() -> String {
|
||||
match std::env::var("MATRIX_PASSWORD") {
|
||||
Ok(p) => p,
|
||||
Err(_) => "".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_meshtastic_address() -> String {
|
||||
match std::env::var("MESHTASTIC_ADDRESS") {
|
||||
Ok(p) => p,
|
||||
Err(_) => "meshtastic.local".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn read_config() -> Config {
|
||||
let filename = match std::env::var("CONFIG_PATH") {
|
||||
Ok(value) => value,
|
||||
|
|
|
@ -18,8 +18,9 @@ pub(crate) async fn build(
|
|||
config: config::MeshtasticConfig,
|
||||
) -> Result<MeshtasticClient, Box<dyn std::error::Error>> {
|
||||
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.address).await?;
|
||||
let (decoded_listener, stream_api) = stream_api.connect(tcp_stream).await;
|
||||
|
||||
log::info!("connected to meshtastic device");
|
||||
|
||||
|
@ -56,7 +57,7 @@ impl MeshtasticClient {
|
|||
|
||||
match payload_variant {
|
||||
PayloadVariant::Packet(packet) => {
|
||||
let payload_variant = match packet.payload_variant {
|
||||
let payload_variant = match &packet.payload_variant {
|
||||
Some(payload_variant) => payload_variant,
|
||||
None => {
|
||||
log::debug!(
|
||||
|
@ -68,7 +69,7 @@ impl MeshtasticClient {
|
|||
|
||||
match payload_variant {
|
||||
mesh_packet::PayloadVariant::Decoded(decoded) => {
|
||||
handle_decoded_packet(&matrix_sender, decoded).await?;
|
||||
handle_decoded_packet(&matrix_sender, &packet, decoded).await?;
|
||||
}
|
||||
mesh_packet::PayloadVariant::Encrypted(encrypted) => {
|
||||
log::debug!(
|
||||
|
@ -97,13 +98,33 @@ impl MeshtasticClient {
|
|||
PayloadVariant::Channel(channel) => {
|
||||
log::debug!("Channel: {:?}", channel);
|
||||
}
|
||||
// PayloadVariant::NodeInfo(node_info) => {
|
||||
// upsert_remote_node(db, node_info).await?
|
||||
// }
|
||||
// PayloadVariant::Decoded(decoded) => {
|
||||
// debug_message(&matrix_sender, format!("Decoded: {:?}", decoded))
|
||||
// }
|
||||
_ => log::debug!("dropping unknown packet"),
|
||||
PayloadVariant::Config(config) => {
|
||||
log::debug!("config: {:?}", config);
|
||||
}
|
||||
PayloadVariant::ConfigCompleteId(config_complete_id) => {
|
||||
log::debug!("config complete ID: {:?}", config_complete_id);
|
||||
}
|
||||
PayloadVariant::NodeInfo(node_info) => {
|
||||
log::debug!("node info: {:?}", node_info);
|
||||
}
|
||||
PayloadVariant::Rebooted(rebooted) => {
|
||||
log::debug!("rebooted: {:?}", rebooted);
|
||||
}
|
||||
PayloadVariant::ModuleConfig(module_config) => {
|
||||
log::debug!("module config: {:?}", module_config);
|
||||
}
|
||||
PayloadVariant::QueueStatus(queue_status) => {
|
||||
log::debug!("queue status: {:?}", queue_status);
|
||||
}
|
||||
PayloadVariant::XmodemPacket(xmodem_packet) => {
|
||||
log::debug!("xmodem packet: {:?}", xmodem_packet);
|
||||
}
|
||||
PayloadVariant::Metadata(metadata) => {
|
||||
log::debug!("metadata message: {:?}", metadata);
|
||||
}
|
||||
PayloadVariant::MqttClientProxyMessage(mqtt_client_proxy_message) => {
|
||||
log::debug!("mqtt client proxy message: {:?}", mqtt_client_proxy_message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,20 +134,25 @@ impl MeshtasticClient {
|
|||
|
||||
async fn handle_decoded_packet(
|
||||
matrix_sender: &Sender<RoomMessageEventContent>,
|
||||
// packet: MeshPacket,
|
||||
decoded: Data,
|
||||
packet: &meshtastic::protobufs::MeshPacket,
|
||||
decoded: &Data,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
match decoded.portnum() {
|
||||
meshtastic::protobufs::PortNum::TextMessageApp => {
|
||||
debug_message(
|
||||
&matrix_sender,
|
||||
format!(
|
||||
"Text from {:?}: {}",
|
||||
decoded.source,
|
||||
std::str::from_utf8(&decoded.payload)?
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
log::debug!("posting packet to matrix: {:?}", packet);
|
||||
log::debug!("decoded: {:?}", decoded);
|
||||
|
||||
let message = format!(
|
||||
"text from {:02x}: {} (snr: {}, rssi: {}, hop limit: {}, hop start: {})",
|
||||
packet.from,
|
||||
std::str::from_utf8(&decoded.payload)?,
|
||||
packet.rx_snr,
|
||||
packet.rx_rssi,
|
||||
packet.hop_limit,
|
||||
packet.hop_start
|
||||
);
|
||||
|
||||
debug_message(&matrix_sender, message).await?;
|
||||
}
|
||||
_ => log::debug!(
|
||||
"dropping packet we havent implemented support for ({})",
|
||||
|
|
Loading…
Reference in a new issue