LTE and Ethernet status query inside container

I am using a balenaFin 1.1 board. I have a Quectel EC25 LTE modem. The modem is working properly, and my default traffic goes out the ethernet port. If I do a speedtest with and without ethernet connected it is quite obvious which interface is being used. When I disconnect my ethernet it takes about 60 seconds to fall back to LTE and the device comes back on line. When I reconnect the ethernet it takes about 60 seconds for it to start using ethernet instead of LTE. So I am happy with this thus far. Is there a way from inside the container to know that ethernet network is down and it is using LTE. For my application the LTE is just a back up. I would like to send an alert when it is operating just on LTE. What command would I do at the command line inside the container to get the status? Thanks

Hey @chetferry

If I was trying to tackle this problem, I think the way that I would go about it is to add the dbus socket into your container (documented here: https://www.balena-staging.io/docs/learn/develop/runtime/#dbus-communication-with-host-os) and use that to query the network manager status (documented here: https://developer.gnome.org/NetworkManager/stable/spec.html). There’s also likely a library already created for your language of choice.

I cannot seem to access dbus. I am trying out some of the example commands. Here is what happens when I try one out:

root@08deac0:/# DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket \

dbus-send
–system
–print-reply
–reply-timeout=2000
–type=method_call
–dest=org.freedesktop.timedate1
/org/freedesktop/timedate1
org.freedesktop.DBus.Properties.GetAll
string:“org.freedesktop.timedate1”
bash: dbus-send: command not found
root@08deac0:/#

Here is how I build my container:

FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:stretch

WORKDIR /

#cross compile locally for raspberry pi compute module then copy the executable
COPY /app/hangar ./

COPY /app/redis.conf ./

COPY /app/start.sh ./

RUN apt-get update && apt-get install -yq
python3 python3-pip minicom screen redis-server

RUN pip3 install speedtest-cli

CMD [“bash”, “/start.sh”]

Is there something I am missing in my container build? Thanks.

That looks to me like you need to install the dbus-send command, from the dbus package.

How do I do that?

You can add dbus to the end of the command:

RUN apt-get update && apt-get install -yq
python3 python3-pip minicom screen redis-server

so:

RUN apt-get update && apt-get install -yq
python3 python3-pip minicom screen redis-server dbus

OK, I added dbus as you showed me and now when I run the command I get this:

root@08deac0:/# DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket \

dbus-send
–system
–print-reply
–reply-timeout=2000
–type=method_call
–dest=org.freedesktop.timedate1
/org/freedesktop/timedate1
org.freedesktop.DBus.Properties.GetAll
string:“org.freedesktop.timedate1”
method return time=1571345764.049785 sender=:1.27 → destination=:1.26 serial=4 reply_serial=2
array [
dict entry(
string “Timezone”
variant string “”
)
dict entry(
string “LocalRTC”
variant boolean false
)
dict entry(
string “CanNTP”
variant boolean false
)
dict entry(
string “NTP”
variant boolean false
)
dict entry(
string “NTPSynchronized”
variant boolean true
)
dict entry(
string “TimeUSec”
variant uint64 1571345764048134
)
dict entry(
string “RTCTimeUSec”
variant uint64 1571345764000000
)
]

Now I just need to figure out the magic commands for the network manager.

You should be able to find a higher level library to work with the dbus api in your language of choice, for example we have produced such a library for node: https://github.com/balena-io-modules/nm-api

I found this link:

and it gives some examples of how to use dbus to get interface info. This seems a bit painful to me.

After pondering what I am trying to accomplish. A simple query of ifconfig seems to be much simpler. When I pull the ethernet and do the ifconfig at the command line the inet address goes away on ethernet. So its pretty easy to see that event I just need to parse the output of the ifconfig command.

The LTE modem is a bit trickier. If I reboot the device with the antennas disconnected the wwan0 interface (LTE modem) is not present when I do ifconfig. But if I pull the antennas after the LTE modem has connected the wwan0 is persistant even thought I am pretty certain the LTE connection is down. So I guess I have what I am really after and that is to know if ethernet is down. I will have to dig some more to figure out if LTE is down.

I will look into a less painful interface to dbus as you suggested also.