Skip to content

Commit

Permalink
Pro+ (#601)
Browse files Browse the repository at this point in the history
* add pro for internal openwb

* rename

* commands for pro+

---------

Co-authored-by: Lutz Bender <[email protected]>
  • Loading branch information
LKuemmel and benderl authored Dec 16, 2024
1 parent 58cb6b8 commit fb4eb57
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 45 deletions.
44 changes: 44 additions & 0 deletions public/modules/charge_points/internal_openwb/commands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
$valid_commands = array(
"update_pro_plus"
);
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
print("invalid request");
http_response_code(400);
exit(1);
}
if (!isset($_REQUEST["command"])) {
print("missing command");
http_response_code(400);
exit(1);
}
if (!in_array($_REQUEST["command"], $valid_commands)) {
print("unsupported command: " . $_REQUEST["command"]);
http_response_code(400);
exit(1);
}

print("executing command '" . $_REQUEST["command"] . "'\n");
switch ($_REQUEST["command"]) {
case 'update_pro_plus':
$post_data = array("update" => 1);
$url = "http://192.168.192.50/connect.php";
$options = array(
"http" => array(
"header" => "Content-type: application/x-www-form-urlencoded",
'method' => 'POST',
'content' => http_build_query($post_data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
break;
}

if ($result === false) {
print("command failed");
http_response_code(500);
exit(1);
}

print("command done");
82 changes: 41 additions & 41 deletions public/modules/charge_points/openwb_pro/commands.php
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
<?php
$valid_commands = array(
"update"
"update"
);
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
print("invalid request");
http_response_code(400);
exit(1);
print("invalid request");
http_response_code(400);
exit(1);
}
if (!isset($_REQUEST["command"])) {
print("missing command");
http_response_code(400);
exit(1);
print("missing command");
http_response_code(400);
exit(1);
}
if (!in_array($_REQUEST["command"], $valid_commands)) {
print("unsupported command: " . $_REQUEST["command"]);
http_response_code(400);
exit(1);
print("unsupported command: " . $_REQUEST["command"]);
http_response_code(400);
exit(1);
}
if (!isset($_REQUEST["data"])) {
print("missing data");
http_response_code(400);
exit(1);
print("missing data");
http_response_code(400);
exit(1);
}
$request_data = json_decode($_REQUEST["data"], true);
if (is_null($request_data)) {
print("invalid data");
http_response_code(400);
exit(1);
print("invalid data");
http_response_code(400);
exit(1);
}
if (!array_key_exists("ip_address", $request_data)) {
print("incomplete data");
http_response_code(400);
exit(1);
print("incomplete data");
http_response_code(400);
exit(1);
}
if (!filter_var($request_data["ip_address"], FILTER_VALIDATE_IP)) {
# "ip_address" may contain a hostname! try to resolve and validate
if (!filter_var(gethostbyname($request_data["ip_address"]), FILTER_VALIDATE_IP)) {
print("invalid ip or hostname");
http_response_code(400);
exit(1);
}
# "ip_address" may contain a hostname! try to resolve and validate
if (!filter_var(gethostbyname($request_data["ip_address"]), FILTER_VALIDATE_IP)) {
print("invalid ip or hostname");
http_response_code(400);
exit(1);
}
}

print("executing command '" . $_REQUEST["command"] . "' with ip '" . $request_data["ip_address"] . "'\n");
switch ($_REQUEST["command"]) {
case 'update':
$post_data = array("update" => 1);
$url = "http://" . $request_data["ip_address"] . "/connect.php";
$options = array(
"http" => array(
"header" => "Content-type: application/x-www-form-urlencoded",
'method' => 'POST',
'content' => http_build_query($post_data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
break;
case 'update':
$post_data = array("update" => 1);
$url = "http://" . $request_data["ip_address"] . "/connect.php";
$options = array(
"http" => array(
"header" => "Content-type: application/x-www-form-urlencoded",
'method' => 'POST',
'content' => http_build_query($post_data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
break;
}

if ($result === false) {
print("command failed");
http_response_code(500);
exit(1);
print("command failed");
http_response_code(500);
exit(1);
}

print("command done");
8 changes: 4 additions & 4 deletions src/components/charge_points/internal_openwb/chargePoint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
{ value: 'duo', text: 'openWB series1/2 Duo' },
{ value: 'socket', text: 'openWB series1/2 Buchse' },
{ value: 'pro_plus', text: 'openWB Pro+' },
]"
:model-value="chargePoint.configuration.mode"
@update:model-value="updateMode($event)"
Expand All @@ -25,8 +26,7 @@
@update:model-value="updateConfiguration($event - 1, 'configuration.duo_num')"
>
<template #help>
Bei einfachen Ladepunkten ist hier immer eine "1" einzutragen. Lediglich bei einer openWB Duo kann mit "2" der
zweite enthaltene Ladepunkt angesprochen werden.
Bei einer openWB Duo können mit "1" oder "2" die beiden enthaltenen Ladepunkte angesprochen werden.
</template>
</openwb-base-number-input>
</div>
Expand All @@ -40,8 +40,8 @@ export default {
mixins: [ChargePointConfigMixin],
methods: {
updateMode(event) {
// set "duo_num" to "1" for modes only supporting one charge point
if (event == "series" || event == "socket") {
// reset "duo_num" for modes only supporting one charge point
if (["series", "socket", "pro_plus"].includes(event)) {
this.updateConfiguration(0, "configuration.duo_num");
}
this.updateConfiguration(event, "configuration.mode");
Expand Down
103 changes: 103 additions & 0 deletions src/components/charge_points/internal_openwb/commands.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<template>
<div class="charge-point-commands-internal-openwb">
<div v-if="chargePoint.configuration.mode == 'pro_plus'">
<openwb-base-button-input
title="Ladepunkt aktualisieren"
button-text="Update anfordern"
subtype="success"
@button-clicked="triggerUpdate"
>
<template #help>
Hier können Sie die Aktualisierung der openWB Pro anstoßen. Bitte stellen Sie sicher, dass kein Fahrzeug
angesteckt ist.
</template>
</openwb-base-button-input>
<openwb-base-button-input
title="Einstellungen öffnen"
button-text="Zu den Einstellungen"
subtype="success"
@button-clicked="openSettings"
>
<template #help>
Mit diesem Befehl können Sie die Einstellungen der openWB Pro in einem neuen Browser-Tab oder -Fenster öffnen.
</template>
</openwb-base-button-input>
</div>
<openwb-base-alert
v-else
subtype="secondary"
>
Der Ladepunkt-Typ "{{ chargePoint.type }}" bietet für die Bauart "{{ mode }}" keine Befehle an.
</openwb-base-alert>
</div>
</template>

<script>
import ChargePointCommandsMixin from "../ChargePointCommandsMixin.vue";
export default {
name: "ChargePointCommandsInternalOpenwb",
mixins: [ChargePointCommandsMixin],
computed: {
mode() {
switch (this.chargePoint.configuration.mode) {
case "series":
return "openWB series1/2 custom, standard & standard+";
case "duo":
return "openWB series1/2 Duo";
case "socket":
return "openWB series1/2 Buchse";
case "pro_plus":
return "openWB Pro+";
default:
return this.chargePoint.configuration.mode;
}
},
},
methods: {
async triggerUpdate() {
let formData = new FormData();
formData.append("command", "update_pro_plus");
const startedMessage = "Die Aktualisierung der openWB Pro+ wird gestartet...";
this.$root.postClientMessage(startedMessage, "info");
console.debug(location);
this.axios
.post(
location.protocol +
"//" +
location.host +
"/openWB/web/settings/modules/charge_points/internal_openwb/commands.php",
formData,
{ timeout: 5000 },
)
.then(() => {
const successMessage = "Die Aktualisierung der openWB Pro+ wurde erfolgreich gestartet.";
this.$root.postClientMessage(successMessage, "success");
})
.catch((error) => {
var alertMessage = "Aktualisierung fehlgeschlagen!<br />";
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.error(error.response.status, error.response.data);
alertMessage += error.response.status + ": " + error.response.data;
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
console.error(error.request);
alertMessage += "Es wurde keine Antwort vom Server empfangen.";
} else {
// Something happened in setting up the request that triggered an Error
console.error("Error", error.message);
alertMessage += "Es ist ein unbekannter Fehler aufgetreten.";
}
this.$root.postClientMessage(alertMessage, "danger");
});
},
openSettings() {
window.open("http://" + location.hostname + ":8080", "_blank");
},
},
};
</script>
14 changes: 14 additions & 0 deletions src/components/charge_points/openwb_pro/commands.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
angesteckt ist.
</template>
</openwb-base-button-input>
<openwb-base-button-input
title="Einstellungen öffnen"
button-text="Zu den Einstellungen"
subtype="success"
:disabled="chargePoint.configuration.ip_address == undefined"
@button-clicked="openSettings"
>
<template #help>
Mit diesem Befehl können Sie die Einstellungen der openWB Pro in einem neuen Browser-Tab oder -Fenster öffnen.
</template>
</openwb-base-button-input>
</div>
</template>

Expand Down Expand Up @@ -63,6 +74,9 @@ export default {
this.$root.postClientMessage(alertMessage, "danger");
});
},
openSettings() {
window.open("http://" + this.chargePoint.configuration.ip_address, "_blank");
},
},
};
</script>

0 comments on commit fb4eb57

Please sign in to comment.