13 posts / 0 new
Last post
dar63
Scripting with OVMS

I'd like to try to implement add-ons to my OVMS box with scripting functionality.
I already went through the documentation, tried a tiny script to extract GPS position, soc, but I am wondering how to be more efficient, which tools to use to avoid, for each new line, to write it with the web editor and launch it with the web console to check if it works. For example, how to evaluate a data and make step by step running to understand an issue?

What are you using ?

dexter
dexter's picture
Scripting with OVMS

I normally first write the whole functionality as planned in my preferred code editor (Kate), then install & test it. If I need to check some Javascript core functionality, I use the browser console. You won't need to test each new line of code once you get used to the system, but I get your point.

A simple first option is to use scripts to deploy code changes to the module. For example, use curl to upload the file, execute "script reload" and issue some test calls by "script eval".

See below for an example on how to do this.

For an advanced option, it shouldn't be hard to create a test environment in Javascript, that emulates the OVMS API. Then you can run that in your browser and use the browser developer tools to debug and test your plugin. That would offer breakpoints etc.

I'll have a look at that.

Regards,
Michael

Example script:

#!/bin/bash
# Upload & execute a script file:

FILE="test.js"
PATH="/store/scripts/"

OVMS_HOST="http://test1.local"
OVMS_USER="admin"
OVMS_PASS="password"

CURL="/usr/bin/curl -c .auth -b .auth"
SED="/usr/bin/sed"

# Login:
RES=$($CURL "${OVMS_HOST}/login" --data-urlencode "username=${OVMS_USER}" --data-urlencode "password=${OVMS_PASS}" 2>/dev/null)
if [ "$RES" =~ "Error" ] ; then
echo -n "LOGIN ERROR: "
echo $RES | $SED -e 's:.*<li>\([^<]*\).*:\1:g'
exit 1
fi

# Upload:
RES=$($CURL "${OVMS_HOST}/edit" --data-urlencode "path=${PATH}${FILE}" --data-urlencode "content@${FILE}" 2>/dev/null)
if [ "$RES" =~ "Error" ] ; then
echo -n "UPLOAD ERROR: "
echo $RES | $SED -e 's:.*<li>\([^<]*\).*:\1:g'
exit 1
fi

# Execute:
$CURL "${OVMS_HOST}/api/execute" --data-urlencode "command=script run ${FILE}"

dar63
Thank you for your answer. I

Thank you for your answer. I'll try to use browser tools as you suggest.
Will be happy to have feedback if you can emulate OVMS api :-)

dexter
dexter's picture
Scripting with OVMS

For reference, I've added a section to the manual:

https://docs.openvehicles.com/en/latest/userguide/scripting.html#test-ut...

dar63
thanks a lot, dexter !

thanks a lot, dexter !

dexter
dexter's picture
Script development with OVMS

David,

to simplify testing and developing OVMS scripts, I've added an embedded Javascript evaluation feature to the editor.

Also see…

https://docs.openvehicles.com/en/latest/userguide/scripting.html#testing...

…for a simple way to bypass the save-reload cycle.

Regards,
Michael

dar63
javascript object to send a http GET request ?

Hi,
I tried to use the object XMLHttpRequest, without success. Is there another object available ?
Or to create a socket ?
My goal is to get data from OVMS and send it to abrp (abetterrouteplanner). For more details, see the post "Home » Forums » OVMS v3 » Vehicle Module » Send live data to abrp"
thank you

dexter
dexter's picture
javascript object to send a http GET request ?

No, unfortunately there is no HTTP/HTTPS API yet. File I/O is also still missing.

For more details see the threads on the developer list, see October archive if not registered.

dar63
web plugin

Hi Dexter,
I found how to send data from the OVMS to abrp, using the web plugin functionality.
I'd like to add it as an example in the documentation, but I am not familiar with the rst format I found in GitHub.
David

dexter
dexter's picture
HTTP API / RST docs

David,

I just pushed the first implementation of a HTTP API:

https://docs.openvehicles.com/en/latest/userguide/scripting.html#http

Included in edge build version 3.2.008-147-g73ae2d19 on my server (dexters-web.de), will be in edge on openvehicles.com within 24 hours.

Also, if you'd like to add to the documentation: "rst" is "reStructuredText", and the documentation is built using sphinx. You can also use Markdown, but rst is the better choice.

Ressources:

a) https://www.sphinx-doc.org/en/master/

b) https://docutils.sourceforge.io/rst.html

c) https://thomas-cokelaer.info/tutorials/sphinx/rest_syntax.html

Regards,
Michael

dar63
send live data to "a better route planner" done !

Michael,

Thanks to your new HTTP API, I've written a script which is running in my OVMS box. So now I have 2 versions, one running through web plugin, which is not using the OVMS data connexion, and one more convenient in a script with a few exposed commands, with no need to have a web browser, just the android app and the ohms box. I'd like to share this also in a doc.
David

dexter
dexter's picture
ABRP Plugin

David,

happy new year :-)

I've added a dedicated plugin area just yesterday to our main repository, would be glad to merge your plugin(s) there:

https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/tree/ma...

We'll be introducing some kind of "plugin store" on this structure later, so users can easily search, install and update plugins. Up to now, simply add a directory "abrp" containing your files and a README.md -- use the edimax plugin as a template.

Normal project submission is via Github, preferrably by a "pull request", so we can easily discuss and merge your work, and you can easily submit updates and get collaboration results.

If you're new to Git & Github, check out the tutorials -- it's easy to use and very powerful.

If you don't want to use/learn Git, upload your files to an issue:

https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/issues?...

Regards,
Michael

dar63
happy new year !

My abrp script example in on Github !
/David

Log in or register to post comments
randomness