diff --git a/README.md b/README.md index 876ed32..8f35331 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ Those parameters can be used to allow the MQTT Gateway to send data to an OsmAnd |---------------------------|---------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | --osmand-server-uri | OSMAND_SERVER_URI | The URL of your OsmAnd Server | | --osmand-device-id | OSMAND_DEVICE_ID | Mapping of VIN to OsmAnd Device Id. Multiple mappings can be provided separated by ',' Example: LSJXXXX=12345-abcdef,LSJYYYY=67890-ghijkl. Defaults to use the car VIN as Device Id if unset | +| --osmand-use-knots | OSMAND_USE_KNOTS | Whether to use knots of kph as a speed unit in OsmAnd messages. Enabled (True) by default to ensure compatibilty with Traccar. | | | --publish-raw-osmand-data | PUBLISH_RAW_OSMAND_DATA_ENABLED | Publish raw ABRP OSMAND request/response to MQTT. Disabled (False) by default. | ### OpenWB Integration diff --git a/src/configuration/__init__.py b/src/configuration/__init__.py index 77a5adb..e4c050f 100644 --- a/src/configuration/__init__.py +++ b/src/configuration/__init__.py @@ -54,6 +54,7 @@ def __init__(self) -> None: # OsmAnd Integration self.osmand_device_id_map: dict[str, str] = {} self.osmand_server_uri: str | None = None + self.osmand_use_knots: bool = True self.publish_raw_osmand_data: bool = False @property diff --git a/src/configuration/parser.py b/src/configuration/parser.py index bc5d3d3..c7b97f5 100644 --- a/src/configuration/parser.py +++ b/src/configuration/parser.py @@ -144,11 +144,16 @@ def __setup_abrp(args: Namespace, config: Configuration) -> None: def __setup_osmand(args: Namespace, config: Configuration) -> None: config.osmand_server_uri = args.osmand_server_uri + if args.osmand_device_id: cfg_value_to_dict(args.osmand_device_id, config.osmand_device_id_map) + if args.publish_raw_osmand_data is not None: config.publish_raw_osmand_data = args.publish_raw_osmand_data + if args.osmand_use_knots is not None: + config.osmand_use_knots = args.osmand_use_knots + def __setup_parser() -> argparse.ArgumentParser: parser = argparse.ArgumentParser(prog="MQTT Gateway") @@ -434,6 +439,18 @@ def __setup_parser() -> argparse.ArgumentParser: action=EnvDefault, envvar="OSMAND_DEVICE_ID", ) + parser.add_argument( + "--osmand-use-knots", + help="Whether to use knots of kph as a speed unit in OsmAnd messages. " + "Enabled (True) by default to ensure compatibilty with Traccar. " + "Environment Variable: OSMAND_USE_KNOTS", + dest="osmand_use_knots", + required=False, + action=EnvDefault, + envvar="OSMAND_USE_KNOTS", + default=True, + type=check_bool, + ) parser.add_argument( "--publish-raw-osmand-data", help="Publish raw ABRP OsmAnd request/response to MQTT. Environment Variable: " diff --git a/src/handlers/vehicle.py b/src/handlers/vehicle.py index 66628ee..58f394e 100644 --- a/src/handlers/vehicle.py +++ b/src/handlers/vehicle.py @@ -116,6 +116,7 @@ def __setup_osmand( return OsmAndApi( server_uri=self.configuration.osmand_server_uri, device_id=osmand_device_id, + use_knots=self.configuration.osmand_use_knots, listener=api_listener, ) diff --git a/src/integrations/osmand/api.py b/src/integrations/osmand/api.py index 9adeb25..6bf1c88 100644 --- a/src/integrations/osmand/api.py +++ b/src/integrations/osmand/api.py @@ -50,11 +50,13 @@ def __init__( *, server_uri: str, device_id: str, + use_knots: bool, listener: OsmAndApiListener | None = None, ) -> None: self.__device_id = device_id self.__listener = listener self.__server_uri = server_uri + self.__use_knots = use_knots self.client = httpx.AsyncClient( event_hooks={ "request": [self.invoke_request_listener], @@ -158,12 +160,11 @@ def __extract_basic_vehicle_status( if basic_vehicle_status.is_parked: # We assume the vehicle is stationary, we will update it later from GPS if available - data["speed"] = (0.0,) + data["speed"] = 0.0 return data - @staticmethod - def __extract_gps_position(gps_position: GpsPosition) -> dict[str, Any]: + def __extract_gps_position(self, gps_position: GpsPosition) -> dict[str, Any]: data: dict[str, Any] = {} # Do not use GPS data if it is not available @@ -176,7 +177,8 @@ def __extract_gps_position(gps_position: GpsPosition) -> dict[str, Any]: speed = way_point.speed if speed is not None and value_in_range(speed, -999, 4500): - data["speed"] = speed / 10 + actual_speed = speed * 0.0539956803 if self.__use_knots else speed / 10.0 + data["speed"] = actual_speed heading = way_point.heading if heading is not None and value_in_range(heading, 0, 360):