Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/configuration/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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: "
Expand Down
1 change: 1 addition & 0 deletions src/handlers/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
10 changes: 6 additions & 4 deletions src/integrations/osmand/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down