<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Not at the moment. Still trying to work out how to do it. @Michael brought this up a week or so ago.<div class=""><br class=""></div><div class="">I am uncomfortable with doing a blocking implementation. For example, blocking the entire ticker.600 for an HTTP download.</div><div class=""><br class=""></div><div class="">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).</div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">Regards, Mark.<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 25 Oct 2019, at 1:22 PM, Anko Hanse <<a href="mailto:anko_hanse@hotmail.com" class="">anko_hanse@hotmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 24px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Hi all,<o:p class=""></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">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:<o:p class=""></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt; background-color: rgb(250, 250, 250);" class=""><span style="font-family: inherit, serif; color: rgb(204, 102, 0);" class="">function</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(204, 102, 0);" class="">stopCharging</span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">()</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">{</span><span style="" class=""><o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt;" class=""><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""> </span><span style="font-family: inherit, serif; color: rgb(204, 102, 0);" class="">var</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(34, 34, 34);" class="">xhttp</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(34, 34, 34);" class="">=</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(204, 102, 0);" class="">new</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(204, 102, 0);" class="">XMLHttpRequest</span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">();<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt;" class=""><span style="" class=""><o:p class=""> </o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt; background-color: rgb(250, 250, 250);" class=""><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""> </span><span style="font-family: inherit, serif; color: rgb(34, 34, 34);" class="">xhttp</span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">.</span><span style="font-family: inherit, serif; color: rgb(34, 34, 34);" class="">onreadystatechange</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(34, 34, 34);" class="">=</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(204, 102, 0);" class="">function</span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">()</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">{</span><span style="" class=""><o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt;" class=""><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""> </span><b class=""><span style="font-family: inherit, serif; color: rgb(204, 102, 0);" class="">if</span></b><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">(</span><span style="font-family: inherit, serif; color: rgb(204, 102, 0);" class="">this</span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">.</span><span style="font-family: inherit, serif; color: rgb(34, 34, 34);" class="">readyState</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(34, 34, 34);" class="">==</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(34, 34, 34);" class="">4</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(34, 34, 34);" class="">&&</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(204, 102, 0);" class="">this</span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">.</span><span style="font-family: inherit, serif; color: rgb(34, 34, 34);" class="">status</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(34, 34, 34);" class="">==</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(34, 34, 34);" class="">200</span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">)</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">{<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt;" class=""><span style="" class=""> var resp = JSON.parse(xhttp.responseText);<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt;" class=""><span style="" class=""> var status = resp.response.status;<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt; background-color: rgb(250, 250, 250);" class=""><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""> </span><span style="font-family: inherit, serif; color: rgb(34, 34, 34);" class="">print(‘status: ‘ + status);</span><span style="" class=""><o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt; background-color: rgb(250, 250, 250);" class=""><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""> </span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">}</span><span style="" class=""><o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt;" class=""><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""> </span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">};<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt;" class=""><span style="" class=""><o:p class=""> </o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt; background-color: rgb(250, 250, 250);" class=""><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""> </span><span style="font-family: inherit, serif; color: rgb(34, 34, 34);" class="">xhttp</span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">.</span><span style="font-family: inherit, serif; color: rgb(204, 102, 0);" class="">open</span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">(</span><span style="font-family: inherit, serif; color: rgb(0, 102, 153);" class="">"POST"</span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">,</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(0, 102, 153);" class="">"https://<url to charge box manufacturer>/<my deviceId>/stop-charge"</span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">,</span><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: inherit, serif; color: rgb(204, 102, 0);" class="">true</span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">);<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt; background-color: rgb(250, 250, 250);" class=""><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class=""> xhttp.setRequestHeader(‘Authorization’, ‘<some magic token>’);</span><span style="" class=""><o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt;" class=""><span style="font-family: inherit, serif; color: rgb(0, 111, 224);" class=""> </span><span style="font-family: inherit, serif; color: rgb(34, 34, 34);" class="">xhttp</span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">.</span><span style="font-family: inherit, serif; color: rgb(204, 102, 0);" class="">send</span><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">( ‘<some magic json struct>’);</span><span style="" class=""><o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt; background-color: rgb(250, 250, 250);" class=""><span style="font-family: inherit, serif; color: rgb(51, 51, 51);" class="">}</span><span style="" class=""><o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">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.<o:p class=""></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">But am now having trouble translating this in javascript that is accepted by the OVMS module…<o:p class=""></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">I also have the beginning of a OVMS script, triggered by ticker.60, that basically does:<o:p class=""></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt;" class="">var charging = OvmsMetrics.Value("v.c.charging");<o:p class=""></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> var bat_soc = OvmsMetrics.AsFloat("xnl.v.b.soc.instrument");<o:p class=""></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; text-indent: 36pt;" class="">if (charging === "yes" && bat_soc >= 80) {<o:p class=""></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> stopCharging(); // <-- this still fails…<o:p class=""></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> // Note: OvmsVehicle.StopCharge(); is not possible on Nissan Leaf (only StartCharge is)<o:p class=""></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> }<o:p class=""></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">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 (<a href="https://www.mynissanleaf.com/viewtopic.php?t=23741" style="color: rgb(149, 79, 114); text-decoration: underline;" class="">https://www.mynissanleaf.com/viewtopic.php?t=23741</a>).<o:p class=""></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">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.<o:p class=""></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">OKidoki,<o:p class=""></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Anko<o:p class=""></o:p></div></div><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 24px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">_______________________________________________</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 24px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 24px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">OvmsDev mailing list</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 24px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><a href="mailto:OvmsDev@lists.openvehicles.com" style="color: rgb(149, 79, 114); text-decoration: underline; font-family: Helvetica; font-size: 24px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">OvmsDev@lists.openvehicles.com</a><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 24px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><a href="http://lists.openvehicles.com/mailman/listinfo/ovmsdev" style="color: rgb(149, 79, 114); text-decoration: underline; font-family: Helvetica; font-size: 24px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">http://lists.openvehicles.com/mailman/listinfo/ovmsdev</a></div></blockquote></div><br class=""></div></body></html>