<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta content="text/html;charset=UTF-8" http-equiv="Content-Type"></head><body ><div style='font-size:10pt;font-family:Verdana,Arial,Helvetica,sans-serif;color:#00000;'><div id=""><div><span style="top: 326px; left: 6px">Hi Mark,</span><br></div><div><br></div><div>Great news about scripting.<br></div><div><br></div><div>Which of your comments below are still to be addressed?<br></div><div><br></div><div><i>Note that this is very hacky and experimental at the moment. A better approach seems to be to have a javascript task running, initialised at boot with a </i><i>user’s javascript program. That can have timers, and whatever else it needs, to do it’s stuff. Then, scripts executed are run in the context of that task.</i><br></div><div><br></div><div><i>The </i><i>current implementation is really just a proof of concept. The OvmsPrint is particularly kludgy (a better implementation would be to hook to the duktape I/O </i>><i> system). </i><br></div><div><br></div><div><i>Duktape is also currently running in internal RAM, although changing it to use SPI RAM should not be hard.</i><br></div><div><br></div><div><br></div><div>Thanks,</div><div>Rob<br></div><div><br></div></div><pre style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">Am 09.07.2018 um 07:40 schrieb Mark Webb-Johnson:
><i>
</i>><i> I’ve enabled the javascript support in the ovms_scripts module. You can now write script files using the javascript language, and they will be run by the
</i>><i> duktape engine. Any script file ending with “.js” extension will be treated as javascript.
</i>><i>
</i>><i> I’ve also added OvmsCommand and OvmsPrint extension commands.
</i>><i>
</i>><i> Two examples:
</i>><i>
</i>><i>     OVMS# vfs cat /store/scripts/helloworld.js
</i>><i>     OvmsPrint("Hello world!\n”);
</i>><i>
</i>><i>     OVMS# . helloworld.js
</i>><i>     Hello world!
</i>><i>
</i>><i>
</i>><i>     OVMS# vfs cat /store/scripts/ota.js
</i>><i>     OvmsPrint(OvmsCommand("ota status"));
</i>><i>
</i>><i>     OVMS# . ota.js
</i>><i>     Running partition: factory
</i>><i>     Boot partition:    factory
</i>><i>     Firmware:          3.1.008-40-g9254170-dirty/factory/edge (build idf v3.1-dev-1583-g0fb2019f Jul  9 2018 08:49:48)
</i>><i>     Server Available:  3.1.008-37-g939416c (no update required)
</i>><i>
</i>><i>     Sat Jul 7 16:00:45 UTC 2018 Automated build (markhk8)
</i>><i>     ...
</i>><i>
</i>><i>
</i>><i> A useful example would be to have a script that runs on location.leave, and checks the v.e.gear metric for vehicle in Drive, before firing off the homelink to
</i>><i> close the garage door.
</i>><i>
</i>><i> Like all good things, the opportunity for evil is forever prevalent (and truly scary):
</i>><i>
</i>><i>     OVMS# vfs cat /store/scripts/bruteforce.js
</i>><i>     for (var pin = 1000; pin < 10000; pin++)
</i>><i>       {
</i>><i>       OvmsCommand("unlock " + pin);
</i>><i>       }
</i>><i>
</i>><i>     OVMS# . bruteforce.js
</i>><i>     V (1421374) canlog: TX can1 id 102 len 8: 0b 03 00 00 e8 03 00 40 | .......@
</i>><i>     V (1421374) canlog: TX can1 id 102 len 8: 0b 03 00 00 e9 03 00 40 | .......@
</i>><i>     V (1421374) canlog: TX can1 id 102 len 8: 0b 03 00 00 ea 03 00 40 | .......@
</i>><i>     V (1421384) canlog: TX can1 id 102 len 8: 0b 03 00 00 eb 03 00 40 | .......@
</i>><i>     V (1421384) canlog: TX can1 id 102 len 8: 0b 03 00 00 ec 03 00 40 | .......@
</i>><i>     V (1421384) canlog: TX can1 id 102 len 8: 0b 03 00 00 ed 03 00 40 | .......@
</i>><i>     V (1421384) canlog: TX can1 id 102 len 8: 0b 03 00 00 ee 03 00 40 | .......@
</i>><i>     V (1421384) canlog: TX can1 id 102 len 8: 0b 03 00 00 ef 03 00 40 | .......@
</i>><i>     V (1421384) canlog: TX can1 id 102 len 8: 0b 03 00 00 f0 03 00 40 | .......@
</i>><i>     V (1421394) canlog: TX can1 id 102 len 8: 0b 03 00 00 f1 03 00 40 | .......@
</i>><i>     ...
</i>><i>
</i>><i>
</i>><i> I’ll leave it up to an exercise to the reader to change that script to use DukOvmsMetricValue() to monitor the v.e.locked metric to record success.
</i>><i>
</i>><i> Note that this is very hacky and experimental at the moment. A better approach seems to be to have a javascript task running, initialised at boot with a
</i>><i> user’s javascript program. That can have timers, and whatever else it needs, to do it’s stuff. Then, scripts executed are run in the context of that task. The
</i>><i> current implementation is really just a proof of concept. The OvmsPrint is particularly kludgy (a better implementation would be to hook to the duktape I/O
</i>><i> system). Duktape is also currently running in internal RAM, although changing it to use SPI RAM should not be hard.
</i>><i>
</i>><i> Regards, Mark.
</i>><i>
</i>>><i> Begin forwarded message:
</i>>><i>
</i>>><i> *From: *GitHub
</i>>><i>
</i>>><i>  Branch: refs/heads/master
</i>>><i>  Home:   <a href="https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3">https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3</a>
</i>>><i>  Commit: f1736f927df582c5ff374ef5d8c3a565e8f67295
</i>>><i>      <a href="https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/commit/f1736f927df582c5ff374ef5d8c3a565e8f67295">https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/commit/f1736f927df582c5ff374ef5d8c3a565e8f67295</a>
</i>>><i>  Author: Mark Webb-Johnson <<a href="http://lists.openvehicles.com/mailman/listinfo/ovmsdev">mark at webb-johnson.net</a> <mailto:<a href="http://lists.openvehicles.com/mailman/listinfo/ovmsdev">mark at webb-johnson.net</a>>>
</i>>><i>  Date:   2018-07-09 (Mon, 09 Jul 2018)
</i>>><i>
</i>>><i>  Changed paths:
</i>>><i>    M vehicle/OVMS.V3/main/ovms_command.cpp
</i>>><i>
</i>>><i>  Log Message:
</i>>><i>  -----------
</i>>><i>  Javascript: Add a OvmsCommand function to execute an OVMS command
</i>>><i>
</i>>><i>
</i>>><i>  Commit: 69427f4ac0cf68dc462b05752936befe4be22256
</i>>><i>      <a href="https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/commit/69427f4ac0cf68dc462b05752936befe4be22256">https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/commit/69427f4ac0cf68dc462b05752936befe4be22256</a>
</i>>><i>  Author: Mark Webb-Johnson <<a href="http://lists.openvehicles.com/mailman/listinfo/ovmsdev">mark at webb-johnson.net</a> <mailto:<a href="http://lists.openvehicles.com/mailman/listinfo/ovmsdev">mark at webb-johnson.net</a>>>
</i>>><i>  Date:   2018-07-09 (Mon, 09 Jul 2018)
</i>>><i>
</i>>><i>  Changed paths:
</i>>><i>    M vehicle/OVMS.V3/main/ovms_script.cpp
</i>>><i>
</i>>><i>  Log Message:
</i>>><i>  -----------
</i>>><i>  Javascript: Add a OvmsPrint function to be able to print a string
</i>>><i> JavaScript: Support .js script files (executed with javascript engine)
</i>>><i>
</i>>><i>
</i>>><i> Compare: <a href="https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/compare/925417081d8e...69427f4ac0cf">https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/compare/925417081d8e...69427f4ac0cf</a>
</i>>><i>      **NOTE:** This service been marked for deprecation: <a href="https://developer.github.com/changes/2018-04-25-github-services-deprecation/">https://developer.github.com/changes/2018-04-25-github-services-deprecation/</a>
</i>>><i>
</i>>><i>      Functionality will be removed from GitHub.com <<a href="http://github.com/">http://GitHub.com</a>> on January 31st, 2019.
</i>><i>
</i>><i>
</i>><i>
</i>><i> _______________________________________________
</i>><i> OvmsDev mailing list
</i>><i> <a href="http://lists.openvehicles.com/mailman/listinfo/ovmsdev">OvmsDev at lists.openvehicles.com</a>
</i>><i> <a href="http://lists.openvehicles.com/mailman/listinfo/ovmsdev">http://lists.openvehicles.com/mailman/listinfo/ovmsdev</a>
</i>
-- 
Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
Fon 02333 / 833 5735 * Handy 0176 / 206 989 26
<br></pre><div id=""><div><span style="top: 278px; left: 108px; cursor: n-resize"></span><span style="top: 370px; left: 108px; cursor: s-resize"></span><br></div></div><div><br></div></div><br></body></html>