[Ovmsdev] http client calls from script
Mark Webb-Johnson
mark at webb-johnson.net
Fri Oct 25 14:14:41 HKT 2019
Not at the moment. Still trying to work out how to do it. @Michael brought this up a week or so ago.
I am uncomfortable with doing a blocking implementation. For example, blocking the entire ticker.600 for an HTTP download.
Duktape supports javascript threads, but only one thread per native thread (and we can’t have too many of those anyway). It doesn’t seem to have any async / promise support (although there is talk of that in the mailing lists).
The issue is similar to file I/O (also requested). It probably would not be too hard to implemented both via some event / callback mechanism - but that is hardly the javascript way.
Regards, Mark.
> On 25 Oct 2019, at 1:22 PM, Anko Hanse <anko_hanse at hotmail.com> wrote:
>
> Hi all,
>
> I was wondering if the OVMS scripting support already includes some kind of http -client. I would like to be able to do something like this:
>
> function stopCharging() {
> var xhttp = new XMLHttpRequest();
>
> xhttp.onreadystatechange = function() {
> if (this.readyState == 4 && this.status == 200) {
> var resp = JSON.parse(xhttp.responseText);
> var status = resp.response.status;
> print(‘status: ‘ + status);
> }
> };
>
> xhttp.open("POST", "https://<url to charge box manufacturer>/<my deviceId>/stop-charge", true);
> xhttp.setRequestHeader(‘Authorization’, ‘<some magic token>’);
> xhttp.send( ‘<some magic json struct>’);
> }
> I’ve got a proof-of-concept javascript running on my pc, including some preparation http calls to get the right magic token and the charge-box indeed receives the command and stops charging.
> But am now having trouble translating this in javascript that is accepted by the OVMS module…
>
> I also have the beginning of a OVMS script, triggered by ticker.60, that basically does:
>
> var charging = OvmsMetrics.Value("v.c.charging");
> var bat_soc = OvmsMetrics.AsFloat("xnl.v.b.soc.instrument");
>
> if (charging === "yes" && bat_soc >= 80) {
> stopCharging(); // <-- this still fails…
>
> // Note: OvmsVehicle.StopCharge(); is not possible on Nissan Leaf (only StartCharge is)
> }
>
> It would be really nice if I could get the OVMS module to trigger the stop charging command by itself. That would give me similar functionaliy as what this guy did using a CarLoop device (https://www.mynissanleaf.com/viewtopic.php?t=23741 <https://www.mynissanleaf.com/viewtopic.php?t=23741>).
>
> If it is not possible, then I need to revert to running a script somewhere on a server, that will periodically keep an eye on the OVMS metrics and then triggers the stop.
>
> OKidoki,
> Anko
> _______________________________________________
> OvmsDev mailing list
> OvmsDev at lists.openvehicles.com <mailto:OvmsDev at lists.openvehicles.com>
> http://lists.openvehicles.com/mailman/listinfo/ovmsdev <http://lists.openvehicles.com/mailman/listinfo/ovmsdev>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20191025/7443aa36/attachment.htm>
More information about the OvmsDev
mailing list