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).

 

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