commandline development - victronenergy/venus GitHub Wiki

This page explains the software development oriented tools, tricks & tips.

There are also more operational commands, see the Venus OS commandline operational manual.

Working with D-Bus

Note that below examples use DbusCli (executable name: dbus). It is pre-installed on the CCGX, and can also be installed on your development computer. There are alternatives as well, see dbus-send.

Get a list of all dbus services

dbus -y

Get all paths of the com.victronenergy.settings service

dbus -y com.victronenergy.settings

Read a value

dbus -y com.victronenergy.settings /Settings/Logscript/Enabled GetValue

Read all values (works with most services, except some of the Python services including localsettings).

dbus -y com.victronenergy.solarcharger.ttyO2 / GetValue

Write a value

dbus -y com.victronenergy.settings /Settings/Logscript/Enabled SetValue %1

See the dbus interface

dbus -y com.victronenergy.settings /Settings/Logscript/Enabled

dbus-spy

dbus-spy is an ncurses tool, which shows a list of all com.victronenergy.* services on the D-Bus, and all paths and values within each service. The values are updated in real-time and can be changed.

The interface works somewhat like the CCGX gui:

  • up/down keys: move up and down in the menus
  • right/left: move in and out submenus
  • enter: enter a submenu or change a value.
  • t: switch between values and texts.
  • ctrl + c or q: close the application

Besides above there is also the very cool Favorites function. See f and F in the Readme for details.

Caveat: by default dbus-spy will only show the values of D-Bus services which support a GetValue on /, because finding all paths without this feature will take a long time, and a lot of D-Bus communication. If you want the content of the other services as well, start dbus-spy with the -i option and be patient.

dbus-send examples

dbus-send is a faster, but somewhat more complicated to use, alternative for dbus-cli as used in previous paragraph.

dbus-send --system --dest=com.victronenergy.settings /Settings/System/RemoteSupportPort com.victronenergy.BusItem.SetValue variant:int32:67

dbus-send --system --dest=com.victronenergy.settings /Settings/System/RemoteSupportPort com.victronenergy.BusItem.GetValue

dbus-send --system --print-reply --dest=com.victronenergy.settings /Settings/System/LogLevel com.victronenergy.BusItem.SetValue variant:int32:0

dbus-send --system --print-reply --dest=com.victronenergy.settings /Settings/System/LogLevel com.victronenergy.BusItem.SetValue variant:int32:0

dbus-send --system --print-reply --dest=net.connman /net/connman/technology/wifi net.connman.Technology.SetProperty string:"Powered" variant:boolean:true

dbus-send --system --print-reply --dest=net.connman /net/connman/ net.connman.Technology.SetProperty string:"Powered" variant:boolean:true

Connmand Manager

dbus-send --system --type=method_call --print-reply --dest=net.connman  net.connman.Manager.GetProperties
dbus-send --system --type=method_call --print-reply --dest=net.connman net.connman.Manager.GetTechnologies
dbus-send --system --type=method_call --print-reply --dest=net.connman net.connman.Manager.GetServices

dbus-send --system --type=method_call --print-reply --dest=net.connman  / net.connman.Technology.Scan

dbus-send --system --type=method_call --print-reply --dest=com.victronenergy.qwacs /Manager com.victronenergy.manager.TestArray
dbus-send --system --type=method_call --print-reply --dest=com.victronenergy.qwacs /Gateway com.victronenergy.gateway.GetUplink

Connmand Service

dbus-send --system --type=method_call --print-reply --dest=net.connman net.connman.Service.GetProperties

Connman NTP

dbus-send --system --type=method_call --print-reply --dest=net.connman  org.freedesktop.DBus.Introspectable.Introspect

dbus-send --system --type=method_call --print-reply --dest=net.connman / net.connman.Clock.GetProperties

dbus-send --system --type=method_call --print-reply --dest=net.connman / net.connman.Clock.SetProperty string:"Timezone" variant:string:"Europe/Amsterdam"

dbus-send --system --type=method_call --print-reply --dest=net.connman / net.connman.Clock.SetProperty string:"Timerservers" array:string:"0.pool.ntp.org","1.pool.ntp.org"

udev mount

dbus-send --system --type=signal / com.victronenergy.udev.mount string:$DEVNAME string:"/media/$name"

udev umount

dbus-send --system --type=signal / com.victronenergy.udev.umount string:$DEVNAME string:"/media/$name"

Managing services

svstat /service/logscript
svstat /service/*
svc -d /service/logscript
svc -u /service/logscript

Reading log files

tail -F /log/logscript/current | tai64nlocal
more /log/mk2/current | tai64nlocal
tail /log/*/current | tai64nlocal
dmesg
cat /log/messages.2 /log/messages.1 /log/messages.0 /log/messages | tai64nlocal
logread
grep -h -i "ERROR" /log/*/current | tai64nlocal
for file in `ls /log/*/current`; do echo "cleared log at `date`" > $file; done

Analyzing logfiles quickly

Configure the ipaddress:

export CURRENTIP=192.168.4.108

First arrange auto-login by using ssh-copy-id to all ipnumbers you want to look at.

ssh-copy-id root@$CURRENTIP  

Check that you have the right one

ssh root@$CURRENTIP "ifconfig"

Then copy past below lines.

ssh root@$CURRENTIP "cat /log/vrmlogger/* | tai64nlocal"
ssh root@$CURRENTIP "cat /log/vrmpubnub/* | tai64nlocal"
ssh root@$CURRENTIP "cat /log/mk2/* | tai64nlocal"
ssh root@$CURRENTIP "cat /log/dbus-pvinverter-vebus/* | tai64nlocal"
ssh root@$CURRENTIP "cat /log/dbus-systemcalc-py/* | tai64nlocal"
ssh root@$CURRENTIP "cat /log/vecan/* | tai64nlocal"    (note, starting message is not in the logs)
ssh root@$CURRENTIP "cat /log/messages.2 /log/messages.1 /log/messages.0 /log/messages | tai64nlocal"
ssh root@$CURRENTIP "cat /log/messages.2 /log/messages.1 /log/messages.0 /log/messages | tai64nlocal | grep Aligment"

Opkg

Introduction

opkg is the package manager we use in Venus OS, and consists of two parts: the opkg tools in Venus OS itself, and the available precompiled package repository online. Its similar to apt-get.

Use the package manager to install optional extra features.

Warning: for something to be opkg-installable, it needs to be pre-built by us and available in the online repository. And unlike Rasbian or Ubuntu and so forth, we do not feature an overcomplete repository of installable packages. Use the opkg list command to see what is available. The list of packages that we defined to be available for opkg install is here.

Note that Venus updates are image based, therefore (a) anything you install using opkg will be gone after a firmware update and (b) we do not used opkg to install updates. See the root access instruction for more information.

Steps

To use it, first set the right feed. It must match the location from which you installed the image. Typically thats release for official releases. And candidate for beta versions:

# when running a beta version:
/opt/victronenergy/swupdate-scripts/set-feed.sh candidate

# when running a release version:
/opt/victronenergy/swupdate-scripts/set-feed.sh release

Above will also make sure the filesystems is expanded to be 100% of the partition size and will (re)mount the rootfs as read/write. Source code for the set-feed script is here: https://github.com/victronenergy/meta-victronenergy/blob/master/meta-venus/recipes-support/swupdate-scripts/files/set-feed.sh

Next, update the package list, this command fetches the list of available packages from the online repository: it requires an internet connection.

opkg update

Now, you can list and grep available packages, for example like such:

opkg list | grep gdb

Then install a package

opkg install [name of package here]

or, see versions of all installed packages

root@ccgx:~# opkg list-installed
base-files - 3.0.14-r76
base-passwd - 3.5.26-r0
bash - 4.2-r5
...
websockify-c - v0.8.0-r1
wget - 1.14-r16.2
wpa-supplicant - 2.2-r1
wpa-supplicant-cli - 2.2-r1
wpa-supplicant-passphrase - 2.2-r1
zip - 3.0-r1

CPU speed

root@CCGX:/sys/devices/system/cpu/cpu0/cpufreq# cat ./scaling_available_governors
conservative userspace powersave ondemand performance
root@CCGX:/sys/devices/system/cpu/cpu0/cpufreq# echo performance > ./scaling_governor
root@CCGX:/sys/devices/system/cpu/cpu0/cpufreq# cat ./scaling_governor
performance
root@CCGX:/sys/devices/system/cpu/cpu0/cpufreq# cat ./cpuinfo_cur_freq
600000

ttys, serial port & serial-starter

The serial starter takes care of starting the drivers for built-in ttys (VE.Direct and VE.Bus ports), as well as all serial devices that are connected through USB, ie the plug-and-play work.

To work on a port yourself, you need to tell serial-starter to leave a tty alone. These commands exist for that purpose:

/opt/victronenergy/serial-starter/stop-tty.sh ttyUSB0
/opt/victronenergy/serial-starter/start-tty.sh ttyUSB0

Once serial-starter has backed off (tip: use ps to make sure), some example commands that can be used to see the output are these:

root@raspberrypi2:~# stty -F /dev/ttyUSB0 115200
root@raspberrypi2:~# cat /dev/ttyUSB0 
/XMX5LGBBFG1009224834

1-3:0.2.8(42)
0-0:1.0.0(171227232200W)
0-0:96.1.1(4530303330303033313536383532323135)
...

More detailed information about serial start is in the Howto add a driver to Venus document.

Sniffing a serial port.

Google socat and tee for more details; here a small reminder for myself:

Create two interlinked virtual serial ports

$ socat -d -d pty,raw,echo=0 pty,raw,echo=0
2019/09/01 19:16:18 socat[20448] N PTY is /dev/pts/4
2019/09/01 19:16:18 socat[20448] N PTY is /dev/pts/6
2019/09/01 19:16:18 socat[20448] N starting data transfer loop with FDs [5,5] and [7,7]

In another terminal, link the outside port to one of them; and to a file.

cat /dev/ttycan1 | tee /dev/pts/4 incoming.txt

In yet another, the other way around:

cat /dev/pts/4 | tee /dev/ttycan1 outgoing.txt

Lastly, start the userland program on the other pty. In my case, I was testing the slcan driver:

slcand -o -f -t hw -s 5 /dev/pts/6 can1

modem

the trick is to leave dbus-modem running, since it resets the watchdog; kill it, and you'll loose the modem all the time.

So instead, stop ppp, and use its interface:

svc -d /service/ppp
screen /dev/modem

To get out of screen and keep it running in the background use ctrl + a followed by d and you will to get back into the shell. Don't forget to kill screen if you're done. To do so run screen -r to reattach the screen session and use ctrl + a, ctrl + y or ctrl + c to kill it.