Skip to content

Add fetching and writing car location #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ CREATE TABLE IF NOT EXISTS carStatus (
zoneRearRightEnabled boolean,
frontWindowHeatingState text,
rearWindowHeatingState text,
odometer integer
odometer integer,
latitude decimal(8, 6),
longitude decimal(9, 6)
);

CREATE TABLE IF NOT EXISTS users (
Expand Down Expand Up @@ -62,4 +64,4 @@ CREATE TABLE IF NOT EXISTS chargingSessions (
CREATE TABLE IF NOT EXISTS settings (
settingKey varchar(128) NOT NULL PRIMARY KEY,
settingValue text
)
)
6 changes: 4 additions & 2 deletions db_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ CREATE TABLE IF NOT EXISTS carStatus (
zoneRearRightEnabled boolean,
frontWindowHeatingState text,
rearWindowHeatingState text,
odometer integer
odometer integer,
latitude decimal(8, 6),
longitude decimal(9, 6)
);

CREATE TABLE IF NOT EXISTS users (
Expand Down Expand Up @@ -62,4 +64,4 @@ CREATE TABLE IF NOT EXISTS chargingSessions (
CREATE TABLE IF NOT EXISTS settings (
settingKey varchar(128) NOT NULL PRIMARY KEY,
settingValue mediumtext
)
)
2 changes: 1 addition & 1 deletion public/idView/js/idView.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,4 @@ function processCarGraphUpdate(graphData){
chart.data.datasets[4].data = graphData.chargePower;
chart.data.datasets[5].data = graphData.chargeRateKMPH;
chart.update();
}
}
9 changes: 8 additions & 1 deletion src/vwid/CarStatusFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ class CarStatusFetcher{
"odometerStatus" => [
"odometer" => null
]
],
"parking" => [
"parkingPosition" => [
"latitude" => "latitude",
"longitude" => "longitude"
]
]
];

Expand All @@ -96,7 +102,8 @@ class CarStatusFetcher{
"measurements",
"departureTimers",
"lvBattery",
"readiness"
"readiness",
"parking"
];

public function __construct(array $config){
Expand Down
4 changes: 3 additions & 1 deletion src/vwid/CarStatusWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class CarStatusWriter implements CarStatusUpdateReceiver{
"zoneRearRightEnabled",
"frontWindowHeatingState",
"rearWindowHeatingState",
"odometer"
"odometer",
"latitude",
"longitude"
];

private DatabaseConnection $db;
Expand Down
8 changes: 7 additions & 1 deletion src/vwid/db/DBmigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct(DatabaseConnection $db, bool $initialStart = false){
if(!$initialStart){
$this->doAutoMigration();
}else{
$this->setDBversion("1.1");
$this->setDBversion("1.2");
Logger::log("Successfully initialized database with schema version V".$this->dbSchemaVersion);
}
}
Expand Down Expand Up @@ -45,6 +45,12 @@ public function doAutoMigration(){
$this->db->query("ALTER TABLE carStatus ADD COLUMN odometer integer");
$this->setDBversion("1.1");
}
if(version_compare($this->dbSchemaVersion, "1.2") < 0){
Logger::notice("Upgrading schema to V1.2 (Adding position columns)");
$this->db->query("ALTER TABLE carStatus ADD COLUMN latitude decimal(8, 6)");
$this->db->query("ALTER TABLE carStatus ADD COLUMN longitude decimal(9, 6)");
$this->setDBversion("1.2");
}
if($startupDbSchemaVersion !== $this->dbSchemaVersion){
Logger::log(
"Successfully upgraded from database schema version ".
Expand Down
2 changes: 1 addition & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
DIR="$(cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
cd "$DIR" || exit 1

exec "php" "./src/vwid/Server.php" "$@"
exec "php" "./src/vwid/Server.php" "$@"