-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add pro for internal openwb * rename * commands for pro+ --------- Co-authored-by: Lutz Bender <[email protected]>
- Loading branch information
Showing
5 changed files
with
206 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/components/charge_points/internal_openwb/commands.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters