This guide is for Renogy BT-1 compatible charge controllers and the Junctek KH140F Battery Monitor (or other Junctek KG-F series Battery Monitors), monitored by a Raspberry Pi.
A real-time dashboard for monitoring the performance of your system uses a touch-screen LCD displaying a Grafana dashboard with Prometheus for data logging from a Python script.
BT-1 Compatible Charge Controllers: A python script reads data from Renogy solar Charge Controllers via its BT-1 bluetooth adapter. Tested with a Rover 40A Charge Controller and Adventurer 30A Charge Controller. May also work with Renogy Wanderer series charge controllers.
Junctek KG-F Series KH140F Bluetooth Battery Monitor: The python script reads data from the Junctek KH140F battery monitor.
- Set up a Raspberry Pi with wifi/bluetooth. See the hardware instructions specific to my build. Or set up two Raspberry Pis: one for running python/prometheus/grafana server and the other as a LCD touch-screen dashboard. See 2nd Pi Instructions
- Install this project on your Raspberry Pi - https://github.com/chriskomus/solar-battery-bt-monitor.git
cd ~/ git clone git@github.com:chriskomus/solar-battery-bt-monitor.git
- Copy the ini file
cd solar-battery-bt-monitor cp solar-battery-bt-monitor.ini.dist solar-battery-bt-monitor.ini
-
Check the prometheus website for the latest version of their application. The URL below may link to older versions.
cd ~/ wget https://github.com/prometheus/prometheus/releases/download/v2.42.0/prometheus-2.42.0.linux-armv7.tar.gz tar xfz prometheus-2.42.0.linux-armv7.tar.gz rm prometheus-2.42.0.linux-armv7.tar.gz mv prometheus-2.42.0.linux-armv7/ prometheus/
-
Copy the file in this project (
prometheus\prometheus.yml
) into the prometheus install folder (~/prometheus/prometheus.yml
), overwriting the existing file:cp ~/solar-battery-bt-monitor/prometheus/prometheus.yml ~/prometheus/prometheus.yml
-
Create the prometheus.service file in /etc/systemd/system/prometheus.service
sudo nano /etc/systemd/system/prometheus.service
Paste the following and save. Change the User and the file paths to your username and the correct filepaths.
[Unit] Description=Prometheus Server Documentation=https://prometheus.io/docs/introduction/overview/ After=network-online.target [Service] User=pi Restart=on-failure #Change this line if Prometheus is somewhere different ExecStart=/home/pi/prometheus/prometheus \ --config.file=/home/pi/prometheus/prometheus.yml \ --storage.tsdb.path=/home/pi/prometheus/data [Install] WantedBy=multi-user.target
-
Setup the Prometheus Service
sudo systemctl daemon-reload sudo systemctl start prometheus sudo systemctl status prometheus sudo systemctl enable prometheus
-
Verify Prometheus is running (modify the address below with the IP address of your Raspberry Pi)
- http://192.168.0.XXX:9090 or http://solar-monitor.local:9090 if you set up the hostname
-
Add the APT key used to authenticate packages.
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
-
Add the Grafana APT repository
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
-
Install Grafana.
sudo apt-get update sudo apt-get install -y grafana
-
Install Custom Plugins:
sudo grafana-cli plugins install petrslavotinek-carpetplot-panel sudo grafana-cli plugins install speakyourcode-button-panel
-
Enable and start the Grafana server
sudo /bin/systemctl enable grafana-server sudo /bin/systemctl start grafana-server
-
After grafana is installed, go to http://192.168.0.36:3000 or http://solar-monitor.local:3000/
- Default log in is username: admin, password: admin
- You'll be prompted to create a unique password for your installation
-
More info on installing Grafana on a Raspberry Pi here.
- Install the GATT library
pip install gatt sudo apt-get install python3-dbus
- Install the prometheus-client library
pip install prometheus-client
- Install libscrc. I had to build libscrc because it's not installable with pip3
cd ~/ git clone https://github.com/hex-in/libscrc cd libscrc/ python3 setup.py build sudo python3 setup.py install
- Now you'll need to edit the solar-battery-bt-monitor.ini with the specifics of your setup. You need to get the MAC address of your particular Renogy BT-1 device and Junctek KG-F Series device.
sudo bluetoothctl scan on
- Look for devices with alias
BT-TH-XXXX..
and note the device name and mac address. If the device doesn't show up in the scanner, make sure you force quit any of the Renogy apps that might be connected to your BT-1.
- Look for devices with alias
BTGXXX
and note the device name and mac address. Note there is no documention online regarding the BT device name for this device. So I'm taking a guess that other KG-F Series devices have a similar alias. Download the official Juncket app, and tap "Search" and it should bring up the device name. Tap connect to confirm it's correct, then be sure to disconnect before proceeding.
- If you are using BT-1 data, set
renogy_enable
to True. - If you are using KG-F Series data, set
junctek_enable
to True. - Edit solar-battery-bt-monitor.ini file with the device name and MAC address for both devices.
-
It's time to test it out:
cd ~/solar-battery-bt-monitor python3 solar-battery-bt-monitor.py
-
The script will attempt to connect to your BT-1 and KG-F Series device. Often times, the bluetooth libraries will immediately disconnect. This script is set up by default to reconnect if that happens. Usually after a handful of reconnect attempts, the application will connect and you'll see the values output on the console.
-
The script by default logs the data read from the controller to prometheus. If prometheus is running on your pi, you should be able to go to the URL http://192.168.0.XXX:5000 or http://solar-monitor.local:5000 and see some output that looks something like the following (you'll likely see a bunch of additional parameters).
# HELP solarshed_battery_percentage Battery % # TYPE solarshed_battery_percentage gauge solarshed_battery_percentage 100.0 # HELP solarshed_battery_volts Battery Voltage # TYPE solarshed_battery_volts gauge solarshed_battery_volts 13.600000000000001 # HELP solarshed_battery_current Battery Current # TYPE solarshed_battery_current gauge solarshed_battery_current 5.5 # HELP solarshed_controller_temperature_celsius Controller Temperature # TYPE solarshed_controller_temperature_celsius gauge solarshed_controller_temperature_celsius 32.0 # HELP solarshed_battery_temperature_celsius Battery Temperature # TYPE solarshed_battery_temperature_celsius gauge solarshed_battery_temperature_celsius 25.0 # HELP solarshed_load_volts Load Voltage # TYPE solarshed_load_volts gauge solarshed_load_volts 13.600000000000001 # HELP solarshed_load_amperes Load Current # TYPE solarshed_load_amperes gauge solarshed_load_amperes 0.15 # HELP solarshed_load_power_watts Load Power # TYPE solarshed_load_power_watts gauge solarshed_load_power_watts 2.0 ...
- Create the solar-bt-service.service file in /etc/systemd/system/solar-battery-bt-monitor.service
sudo nano /etc/systemd/system/solar-battery-bt-monitor.service
Paste the following and save. Change the User and the file paths to your username and the correct filepaths.
[Unit]
Description=Solar Bluetooth Monitor
After=network.target
[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi/solar-battery-bt-monitor
ExecStart=/usr/bin/python3 /home/pi/solar-battery-bt-monitor/solar-battery-bt-monitor.py
RestartSec=13
Restart=always
[Install]
WantedBy=multi-user.target
- Start up the solar-battery-bt-monitor service
sudo systemctl daemon-reload
sudo systemctl start solar-battery-bt-monitor
sudo systemctl status solar-battery-bt-monitor
sudo systemctl enable solar-battery-bt-monitor
- Now that you're logging data to prometheus, we need to set up grafana to use this data source to display an awesome dashboard!
- Go to your grafana install at http://192.168.0.XXX:3000 or http://solar-monitor.local:3000 and log in.
- Set up the grafana data source coming from prometheus
- From the navigation bar running down the left side of the window, select:
- Configuration (gear icon) -> Data Sources
- Select Prometheus
- Give the data source a good name (solar-monitor)
- Under the HTTP section, set the URL to http://192.168.0.XXX:9090 or http://solar-monitor.local:9090
- Scroll to the bottom and select Save & Test
- From the Create menu (Dashboard -> + icon on left navigation panel), choose Import and import the dashboard json files included in the grafana folder in this project. There are multiple files for different views on the LCD. Set
solar-battery-bt-monitor.json
to be the default dashboard. If hostname is not solar-monitor, find and replacehttp://solar-monitor.local
with whatever the host name is for all the grafana dashboard json files.
Yay! At this point setup should be complete. Go to http://192.168.0.XXX:3000 or http://solar-monitor.local:3000 and you should start seeing at minimum a battery charge % and a battery voltage. Additional information should also display if the battery monitor is working and the solar panels are supplying power.
This is an optional step if you have a touch screen LCD. Complete the hardware setup instructions first, if you haven't already.
- Edit the grafana config file:
sudo nano /etc/grafana/config.ini
- Look for the section starting with [auth.anonymous] and change to the following values (don't forget to remove the ; at the beginning of the line):
[auth.anonymous]
# enable anonymous access
enabled = true
# specify organization name that should be used for unauthenticated users
org_name = SolarBluetoothMonitor
# specify role for unauthenticated users
org_role = Viewer
# mask the Grafana version number for unauthenticated users
hide_version = true
- In a browser go to http://192.168.0.XXX:3000 or http://solar-monitor.local:3000
- From the navigation bar running down the left side of the window, select Server admin (shield icon) -> Organizations:
- Click on the organizations
- Update the Organization name in Grafana to
SolarBluetoothMonitor
or whatever you chose in step 2.
- From the navigation bar, select Dashboards -> Browse:
- Click on Solar Bluetooth Monitor
- Click on the star to make it the default.
- From the navigation bar, select Configuration -> Preferences.
- Set the Home dashboard for the organisation
- Set the Org name to to match the name above
- If you completed the above steps on the Raspberry Pi, log out of grafana.
- On the Raspberry Pi that will be running the LCD, ensure you are logged out of grafana dashboard, then go to http://192.168.0.XXX:3000 or http://solar-monitor.local:3000
- You should now see the dashboard without having logged in!
- Open a terminal and type this to get to the configuration setting:
cd .config
sudo mkdir -p lxsession/LXDE-pi
sudo nano lxsession/LXDE-pi/autostart
- Paste this into nano and save:
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
#@xscreensaver -no-splash
point-rpi
@chromium-browser --start-fullscreen --start-maximized
- Optional: Install virtual keyboard for the touchscreen.
sudo apt install onboard
- Go to Main Menu -> Preferences -> Raspberry Pi Configuration -> Display
- Disable Screen-Blanking.
- If you'd like Grafana to launch after booting continue with the following steps. If you prefer an html launcher instead, read the launcher guide and skip to step 21 in this section.
- Bookmark the dashboard with the settings you'd like to see as a default.
- Go into Chromium settings -> Appearance -> Show Home Button.
- Set the home button to the grafana url that you bookmarked.
- Go into Chromium settings -> On start-up -> Open a specific page... -> Add a new page
- Paste the grafana url.
- Use the shutdown script or reboot:
sudo shutdown -r now
- The grafana dashboard should load after the reset. F11 to toggle fullscreen.
Some BT dongles work better than others. It's probably best to use a Pi with integrated BT, but I ran into issues with that too. I have had success with this Broadcom based BT Dongle.
Try this:
sudo hciconfig hci0 down; sudo systemctl restart bluetooth
Unload and reload btusb kernel:
sudo rmmod btusb
sudo modprobe btusb
Power off and on with bluetoothctl. If successful you should see results after running scan on
sudo bluetoothctl
power off
power on
scan on
Restart the solar-battery-bt-monitor service and check the status:
sudo systemctl daemon-reload
sudo service solar-battery-bt-monitor restart
sudo service solar-battery-bt-monitor status
If that doesn't work, try to restart the bluetooth service:
sudo service bluetooth restart
sudo service bluetooth status
In case you run into issues running as a Service and want to stop and disable it:
sudo systemctl stop solar-battery-bt-monitor
sudo systemctl disable solar-battery-bt-monitor
Run the script instead
python3 ~/solar-battery-bt-monitor/solar-battery-bt-monitor.py
Powering the Pi off the front USB port on the charge controller can result in low voltage warnings. The best solution is to use an official Raspberry Pi power supply. In a 12v system this means running an inverter 24/7. Alternatively, find some magical combo of USB cables and 12v power where the number of voltage warnings is reduced or eliminated.
If the Pi gets stuck on a white screen after launching Chromium in full screen after booting, you may have to use the launcher instead. Instead of automatically loading Grafana after booting, it will instead load a static html page with a link to Grafana. It also has a button to enable and disable full screen.
- If the Kiosk Pi is running really slow, increase the swap size. First stop swapfile:
sudo dphys-swapfile swapoff
- Modify swapfile config
sudo nano /etc/dphys-swapfile
- Change
CONF_SWAPSIZE=100
toCONF_SWAPSIZE=1024
- Restart swapfile
sudo dphys-swapfile setup
sudo dphys-swapfile swapon
If you want to learn more about the process of reverse engineering a BT device using just the device and a Raspberry Pi, check out my guide here: BLE Sniffer Walkthrough for Junctek BT Battery Monitor
Big thanks to snichol67's solar-bt-monitor for his implementation using grafana and prometheus, and Olen's solar-monitor which stands as the foundation of this project, and contains the Junctek plugin that I wrote and then adapted for this project.
This project contains elements of the following: