diff options
author | initard <alex.solomes@softwareag.com> | 2022-01-27 17:51:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 17:51:29 +0100 |
commit | cd15f10bb6f893a18e63c54ad41a677a1e5ec1bb (patch) | |
tree | e8e2a571417837519ff4270214642a8c9c02aa0a /crates/core/tedge | |
parent | 6bbcdff8de2569bfff3e1a8085c21aaf98a5d96f (diff) |
#733 Configurable Device Type (#782)
* configurable device type (#733)
Signed-off-by: initard <solo@softwareag.com>
* adding device data fragment to mapper init (#733)
Signed-off-by: initard <solo@softwareag.com>
* fixing test
Signed-off-by: initard <solo@softwareag.com>
* adding device type when making new device (#733)
Signed-off-by: initard <solo@softwareag.com>
* removing comment and unused package
Signed-off-by: initard <solo@softwareag.com>
* passing down device type and removing tedge util
Signed-off-by: initard <solo@softwareag.com>
* string formatting (#733)
Signed-off-by: initard <solo@softwareag.com>
* documenting device data settings
Signed-off-by: initard <solo@softwareag.com>
* addressing minor pr comments on syntax (#733)
Signed-off-by: initard <solo@softwareag.com>
Co-authored-by: initard <solo@softwareag.com>
Diffstat (limited to 'crates/core/tedge')
-rw-r--r-- | crates/core/tedge/src/cli/config/config_key.rs | 1 | ||||
-rw-r--r-- | crates/core/tedge/src/cli/connect/c8y_direct_connection.rs | 17 | ||||
-rw-r--r-- | crates/core/tedge/src/cli/connect/command.rs | 5 |
3 files changed, 19 insertions, 4 deletions
diff --git a/crates/core/tedge/src/cli/config/config_key.rs b/crates/core/tedge/src/cli/config/config_key.rs index f2c35c12..1b0fcef3 100644 --- a/crates/core/tedge/src/cli/config/config_key.rs +++ b/crates/core/tedge/src/cli/config/config_key.rs @@ -40,6 +40,7 @@ impl ConfigKey { pub fn list_all() -> Vec<ConfigKey> { vec![ config_key!(DeviceIdSetting), + config_key!(DeviceTypeSetting), config_key!(DeviceKeyPathSetting), config_key!(DeviceCertPathSetting), config_key!(C8yUrlSetting), diff --git a/crates/core/tedge/src/cli/connect/c8y_direct_connection.rs b/crates/core/tedge/src/cli/connect/c8y_direct_connection.rs index a9c45b31..049429b2 100644 --- a/crates/core/tedge/src/cli/connect/c8y_direct_connection.rs +++ b/crates/core/tedge/src/cli/connect/c8y_direct_connection.rs @@ -18,6 +18,7 @@ use tedge_users::UserManager; pub fn create_device_with_direct_connection( user_manager: UserManager, bridge_config: &BridgeConfig, + device_type: &str, ) -> Result<(), ConnectError> { const DEVICE_ALREADY_EXISTS: &[u8] = b"41,100,Device already existing"; const DEVICE_CREATE_ERROR_TOPIC: &str = "s/e"; @@ -49,7 +50,11 @@ pub fn create_device_with_direct_connection( for event in connection.iter() { match event { Ok(Event::Incoming(Packet::SubAck(_))) => { - publish_device_create_message(&mut client, &bridge_config.remote_clientid.clone())?; + publish_device_create_message( + &mut client, + &bridge_config.remote_clientid.clone(), + &device_type, + )?; } Ok(Event::Incoming(Packet::Publish(response))) => { // We got a response @@ -64,6 +69,7 @@ pub fn create_device_with_direct_connection( publish_device_create_message( &mut client, &bridge_config.remote_clientid.clone(), + &device_type, )?; device_create_try += 1; } else { @@ -88,14 +94,17 @@ pub fn create_device_with_direct_connection( Err(ConnectError::TimeoutElapsedError) } -fn publish_device_create_message(client: &mut Client, device_id: &str) -> Result<(), ConnectError> { +fn publish_device_create_message( + client: &mut Client, + device_id: &str, + device_type: &str, +) -> Result<(), ConnectError> { const DEVICE_CREATE_PUBLISH_TOPIC: &str = "s/us"; - const DEVICE_TYPE: &str = "thin-edge.io"; client.publish( DEVICE_CREATE_PUBLISH_TOPIC, QoS::ExactlyOnce, false, - format!("100,{},{}", device_id, DEVICE_TYPE).as_bytes(), + format!("100,{},{}", device_id, device_type).as_bytes(), )?; Ok(()) } diff --git a/crates/core/tedge/src/cli/connect/command.rs b/crates/core/tedge/src/cli/connect/command.rs index 004d1891..18052a03 100644 --- a/crates/core/tedge/src/cli/connect/command.rs +++ b/crates/core/tedge/src/cli/connect/command.rs @@ -118,12 +118,15 @@ impl Command for ConnectCommand { ); self.config_repository.store(&config)?; + let device_type = config.query(DeviceTypeSetting)?; + new_bridge( &bridge_config, &updated_mosquitto_config, self.service_manager.as_ref(), self.user_manager.clone(), &self.config_location, + &device_type, )?; match self.check_connection(&config) { @@ -373,6 +376,7 @@ fn new_bridge( service_manager: &dyn SystemServiceManager, user_manager: UserManager, config_location: &TEdgeConfigLocation, + device_type: &str, ) -> Result<(), ConnectError> { println!("Checking if {} is available.\n", service_manager.name()); let service_manager_result = service_manager.check_operational(); @@ -397,6 +401,7 @@ fn new_bridge( let () = c8y_direct_connection::create_device_with_direct_connection( user_manager, bridge_config, + &device_type, )?; } |