<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=""><div class=""><br class=""></div>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 duktape engine. Any script file ending with “.js” extension will be treated as javascript.<div class=""><br class=""></div><div class="">I’ve also added OvmsCommand and OvmsPrint extension commands.</div><div class=""><br class=""></div><div class="">Two examples:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">OVMS# vfs cat /store/scripts/helloworld.js</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">OvmsPrint("Hello world!\n”);</span></font></div></div><div class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">OVMS# . helloworld.js</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">Hello world!</span></font></div></div></blockquote><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">OVMS# vfs cat /store/scripts/ota.js<br class="">OvmsPrint(OvmsCommand("ota status"));</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">OVMS# . ota.js<br class="">Running partition: factory<br class="">Boot partition: factory<br class="">Firmware: 3.1.008-40-g9254170-dirty/factory/edge (build idf v3.1-dev-1583-g0fb2019f Jul 9 2018 08:49:48)<br class="">Server Available: 3.1.008-37-g939416c (no update required)<br class=""><br class="">Sat Jul 7 16:00:45 UTC 2018 Automated build (markhk8)</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">...</span></font></div><div class=""></div></blockquote><div class=""><div class=""><br class=""></div><div class="">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 close the garage door.</div><div class=""><br class=""></div><div class="">Like all good things, the opportunity for evil is forever prevalent (and truly scary):</div><div class=""><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><span style="font-family: "Andale Mono"; font-size: 14px;" class="">OVMS# vfs cat /store/scripts/bruteforce.js</span><br style="font-family: "Andale Mono"; font-size: 14px;" class=""></div></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">for (var pin = 1000; pin < 10000; pin++)<br class=""> {<br class=""> OvmsCommand("unlock " + pin);<br class=""> }</span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class=""><br class=""></span></font></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">OVMS# . bruteforce.js</span><br class=""><span style="font-size: 14px;" class="">V (1421374) canlog: TX can1 id 102 len 8: 0b 03 00 00 e8 03 00 40 | .......@</span><br class=""><span style="font-size: 14px;" class="">V (1421374) canlog: TX can1 id 102 len 8: 0b 03 00 00 e9 03 00 40 | .......@</span><br class=""><span style="font-size: 14px;" class="">V (1421374) canlog: TX can1 id 102 len 8: 0b 03 00 00 ea 03 00 40 | .......@</span><br class=""><span style="font-size: 14px;" class="">V (1421384) canlog: TX can1 id 102 len 8: 0b 03 00 00 eb 03 00 40 | .......@</span><br class=""><span style="font-size: 14px;" class="">V (1421384) canlog: TX can1 id 102 len 8: 0b 03 00 00 ec 03 00 40 | .......@</span><br class=""><span style="font-size: 14px;" class="">V (1421384) canlog: TX can1 id 102 len 8: 0b 03 00 00 ed 03 00 40 | .......@</span><br class=""><span style="font-size: 14px;" class="">V (1421384) canlog: TX can1 id 102 len 8: 0b 03 00 00 ee 03 00 40 | .......@</span><br class=""><span style="font-size: 14px;" class="">V (1421384) canlog: TX can1 id 102 len 8: 0b 03 00 00 ef 03 00 40 | .......@</span><br class=""><span style="font-size: 14px;" class="">V (1421384) canlog: TX can1 id 102 len 8: 0b 03 00 00 f0 03 00 40 | .......@</span><br class=""><span style="font-size: 14px;" class="">V (1421394) canlog: TX can1 id 102 len 8: 0b 03 00 00 f1 03 00 40 | </span></font><span style="font-size: 14px; font-family: "Andale Mono";" class="">.......@</span></div><div class=""><font face="Andale Mono" class=""><span style="font-size: 14px;" class="">...</span></font></div></blockquote><div class=""><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">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 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 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 system). Duktape is also currently running in internal RAM, although changing it to use SPI RAM should not be hard.</div><div class=""><br class=""></div><div class="">Regards, Mark.<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">Begin forwarded message:</div><br class="Apple-interchange-newline"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(0, 0, 0, 1.0);" class=""><b class="">From: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">GitHub</span></div><br class=""><div class=""><div class=""> Branch: refs/heads/master<br class=""> Home: <a href="https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3" class="">https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3</a><br class=""> Commit: f1736f927df582c5ff374ef5d8c3a565e8f67295<br class=""> <a href="https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/commit/f1736f927df582c5ff374ef5d8c3a565e8f67295" class="">https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/commit/f1736f927df582c5ff374ef5d8c3a565e8f67295</a><br class=""> Author: Mark Webb-Johnson <<a href="mailto:mark@webb-johnson.net" class="">mark@webb-johnson.net</a>><br class=""> Date: 2018-07-09 (Mon, 09 Jul 2018)<br class=""><br class=""> Changed paths:<br class=""> M vehicle/OVMS.V3/main/ovms_command.cpp<br class=""><br class=""> Log Message:<br class=""> -----------<br class=""> Javascript: Add a OvmsCommand function to execute an OVMS command<br class=""><br class=""><br class=""> Commit: 69427f4ac0cf68dc462b05752936befe4be22256<br class=""> <a href="https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/commit/69427f4ac0cf68dc462b05752936befe4be22256" class="">https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/commit/69427f4ac0cf68dc462b05752936befe4be22256</a><br class=""> Author: Mark Webb-Johnson <<a href="mailto:mark@webb-johnson.net" class="">mark@webb-johnson.net</a>><br class=""> Date: 2018-07-09 (Mon, 09 Jul 2018)<br class=""><br class=""> Changed paths:<br class=""> M vehicle/OVMS.V3/main/ovms_script.cpp<br class=""><br class=""> Log Message:<br class=""> -----------<br class=""> Javascript: Add a OvmsPrint function to be able to print a string<br class="">JavaScript: Support .js script files (executed with javascript engine)<br class=""><br class=""><br class="">Compare: <a href="https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/compare/925417081d8e...69427f4ac0cf" class="">https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/compare/925417081d8e...69427f4ac0cf</a><br class=""> **NOTE:** This service been marked for deprecation: <a href="https://developer.github.com/changes/2018-04-25-github-services-deprecation/" class="">https://developer.github.com/changes/2018-04-25-github-services-deprecation/</a><br class=""><br class=""> Functionality will be removed from <a href="http://GitHub.com" class="">GitHub.com</a> on January 31st, 2019.<br class=""></div></div></blockquote></div><br class=""></div></div></body></html>