solve reconnections

This commit is contained in:
irriden
2023-06-06 03:10:33 +00:00
parent 11a5bff5f1
commit 099fd3fe11
3 changed files with 16 additions and 2 deletions

1
sphinx-key/Cargo.lock generated
View File

@@ -2013,6 +2013,7 @@ dependencies = [
"hex",
"log",
"lss-connector",
"rand",
"rmp-serde",
"serde",
"serde_json",

View File

@@ -37,6 +37,7 @@ serde = { version = "1.0.137", default-features = false }
serde_json = { version = "1.0.81", default-features = false }
hex = "0.4.3"
rmp-serde = "1.1.0"
rand = "0.8.5"
[build-dependencies]
embuild = "0.29"

View File

@@ -24,6 +24,9 @@ use esp_idf_svc::nvs::*;
use sphinx_signer::lightning_signer::bitcoin::Network;
use sphinx_signer::sphinx_glyph::control::{Config, ControlPersist, Policy};
use rand::distributions::Alphanumeric;
use rand::Rng;
#[cfg(not(feature = "pingpong"))]
const CLIENT_ID: &str = "sphinx-1";
@@ -151,7 +154,8 @@ fn make_and_launch_client(
let token = ctrlr.make_auth_token().expect("couldnt make auth token");
log::info!("PUBKEY {} TOKEN {}", &pubkey, &token);
let mqtt_client = conn::mqtt::make_client(&config.broker, CLIENT_ID, &pubkey, &token, tx)?;
let client_id = random_word(8);
let mqtt_client = conn::mqtt::make_client(&config.broker, &client_id, &pubkey, &token, tx)?;
// let mqtt_client = conn::mqtt::start_listening(mqtt, connection, tx)?;
// this blocks forever... the "main thread"
@@ -170,7 +174,15 @@ fn make_and_launch_client(
seed,
policy,
ctrlr,
CLIENT_ID,
&client_id,
)?;
Ok(())
}
pub fn random_word(n: usize) -> String {
rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(n)
.map(char::from)
.collect()
}