PiJuice temperature sensor error

Using PiJuice with an rPi 3B+ running on balenaCloud, I am encountering problems with some of the PiJuice functionality.

Specifically, selecting the temperature sensor ‘NTC’ reports that it works (GetBatteryTempSenseConfig() reports: {‘error’: ‘NO_ERROR’, ‘data’: ‘NTC’}), however, the PiJuice continues to report on-board temperatures, rather than the NTC temperatures.

Additionally, setting a custom battery profile results in an error when accessing the pijuice cli.

Following that, I accessed the cli, and selected battery settings, and got the following error message:

root@de3c342a2714:/# sudo -u pijuice pijuice_cli
Traceback (most recent call last):
  File "/usr/bin/pijuice_cli.py", line 2013, in <module>
  File "/usr/lib/python3/dist-packages/urwid/main_loop.py", line 278, in run
  File "/usr/lib/python3/dist-packages/urwid/main_loop.py", line 376, in _run
  File "/usr/lib/python3/dist-packages/urwid/main_loop.py", line 682, in run
  File "/usr/lib/python3/dist-packages/urwid/main_loop.py", line 719, in _loop
  File "/usr/lib/python3/dist-packages/urwid/raw_display.py", line 393, in <lambda>
    event_loop, callback, self.get_available_raw_input())
  File "/usr/lib/python3/dist-packages/urwid/raw_display.py", line 493, in parse_input
    callback(processed, processed_codes)
  File "/usr/lib/python3/dist-packages/urwid/main_loop.py", line 403, in _update
  File "/usr/lib/python3/dist-packages/urwid/main_loop.py", line 503, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
  File "/usr/lib/python3/dist-packages/urwid/container.py", line 592, in keypress  
    *self.calculate_padding_filler(size, True)), key)
  File "/usr/lib/python3/dist-packages/urwid/container.py", line 1587, in keypress
    key = self.focus.keypress(tsize, key)
  File "/usr/lib/python3/dist-packages/urwid/container.py", line 2269, in keypress
    key = w.keypress((mc,) + size[1:], key)
  File "/usr/lib/python3/dist-packages/urwid/decoration.py", line 621, in keypress
    return self._original_widget.keypress(maxvals, key)
  File "/usr/lib/python3/dist-packages/urwid/listbox.py", line 985, in keypress
    key = focus_widget.keypress((maxcol,),key)
  File "/usr/lib/python3/dist-packages/urwid/decoration.py", line 621, in keypress
    return self._original_widget.keypress(maxvals, key)
  File "/usr/lib/python3/dist-packages/urwid/wimp.py", line 535, in keypress
  File "/usr/lib/python3/dist-packages/urwid/widget.py", line 463, in _emit
    signals.emit_signal(self, name, self, *args)
  File "/usr/lib/python3/dist-packages/urwid/signals.py", line 264, in emit
    result |= self._call_callback(callback, user_arg, user_args, args)
  File "/usr/lib/python3/dist-packages/urwid/signals.py", line 294, in _call_callback
    return bool(callback(*args_to_pass))
  File "/usr/bin/pijuice_cli.py", line 1913, in item_chosen
  File "/usr/bin/pijuice_cli.py", line 1009, in __init__
  File "/usr/bin/pijuice_cli.py", line 1129, in refresh
  File "/usr/bin/pijuice_cli.py", line 1187, in _read_chemistry
    self.chemistries_idx = self.CHEMISTRY_OPTIONS.index(self.ext_profile_data['chemistry'])
ValueError: 'UNKNOWN' is not in list

I’ve discussed these matters with PiJuice, and they mentioned they haven’t worked with balenaOS/balenaCloud. Could something in my balena setup be causing these problems?

My balena supervisor version is 11.4.10, Host OS is balenaOS 2.50.4+rev1

I have a multi-container setup. The portion of my docker-compose for the relevant container is:

    container_name: sh_pijuice
    build: ./sh_pijuice
    restart: on-failure
    privileged: true
      - "/dev/i2c-1:/dev/i2c-1"
      - "cgroup:/sys/fs/cgroup"
      io.balena.features.supervisor-api: true
      io.balena.features.dbus: true
      io.balena.features.kernel-modules: true

My dockerfile for this container is:

FROM balenalib/rpi-raspbian:stretch

RUN apt-get update && apt-get install -y --no-install-recommends \
  python3 \
  dbus \
  i2c-tools \
  raspi-config \
  systemd \
  systemd-sysv \
  pijuice-base=1.6 \
  wget \
  && wget -q -O - http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key | apt-key add - \
  && wget -q -O /etc/apt/sources.list.d/mosquitto-stretch.list http://repo.mosquitto.org/debian/mosquitto-stretch.list \
  && apt-get install -y mosquitto mosquitto-clients \
  && touch boot/config.txt \
  && raspi-config nonint do_i2c 0

ENV DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket

COPY . /.

CMD bash entrypoint.sh

Is there anything in my setup that could be causing the problems I’m experiencing with the PiJuice?

Thanks in advance for any help.

the raspi-config nonint do_i2c 0 will not work as it modifies a file in the container rather than the one actually used by the Raspberry Pi. In order to make I2C work on balenaOS, you need to load the i2c-devkernel modules as described here: https://www.balena.io/docs/learn/develop/hardware/i2c-and-spi/#i2c Could you please confirm whether that helps? Thanks

@mtoman Thanks for your help!

I adjusted my Dockerfile to remove raspi-config nonint do_i2c 0 and so that the final line is instead:
CMD modprobe i2c-dev && bash entrypoint.sh as discussed in the docs you referenced.

Unfortunately it does not fix the problem.