Skip to main content

PiSugar Power Manager (Software)

PiSugar Power Manager is a software created for PiSugar 2/3 series.

Source Code: https://github.com/PiSugar/pisugar-power-manager-rs

IMPORTANT

  • This software will occupy i2c addresses (0x75 & 0x32 for PiSugar2, 0x57 & 0x68 for PiSugar3). Please avoid other pHATs using these addresses.

  • We had upgradged PiSugar2 to new model. To identify it, please check the charging indicate led count, 4-leds is for old model, 2-leds is for new model. The new model is able to accurately detected the charging status and control the charging recycle.

After attaching PiSugar to you pi, you can use the following commands to see whether it works properly:

# turn on i2c interface
sudo raspi-config

# Interfacing Options -> I2C -> Yes

# detect i2c bus and devices (PiSugar2)
i2cdetect -y 1
i2cdump -y 1 0x32
i2cdump -y 1 0x75

# detect i2c bus and devices (PiSugar3)
i2cdetect -y 1
i2cdump -y 1 0x57
i2cdump -y 1 0x68

If you cannot find any devices, or see lots of 'X.XX.X.X...' things, please try turning off PiSugar 2 and restart one minutes later.

Support Model List

During the installation process, you need to select the corresponding model. Choosing the correct PiSugar model is essential for the server to function properly.

ModelDescriptionPhoto
PiSugar 3PiSugar 3/ PiSugar 3 PlusPiSugar 3 PiSugar3Plus
PiSugar 2 2-ledsPiSugar 2PiSugar2-2led
PiSugar 2 4-ledsPiSugar 2 (old model, discontinued in 2021)PiSugar2-4led
PiSugar 2 ProPiSugar 2 Plus (Previously named PiSugar 2 Pro)PiSugar2-plus

Installation

Run the following script on your pi:

wget https://cdn.pisugar.com/release/pisugar-power-manager.sh
bash pisugar-power-manager.sh -c release

After finished, you can manage the battery by visiting http://<your raspberry ip>:8421 in your browser.

PiSugar2 WebUI

PiSugar Power Manager is develop in Rust and Vue2.0, with high performace (less than 2% pi0 cpu) and exquisite designed webUI.

One more thing, you can also manage the battery by PiSugar APP.

PiSugar App

PiSugar App is now available on APP store and Android. It connects the PiSugar-server via port 8423. It allows you manage multiple batteries in your mobile phone!

qrcode 39796c9

Scan QR Code or click Here to get PiSugar App.

Commands of controlling pisugar-server systemd service

# reload daemon
sudo systemctl daemon-reload

# check status
sudo systemctl status pisugar-server

# start service
sudo systemctl start pisugar-server

# stop service
sudo systemctl stop pisugar-server

# disable service
sudo systemctl disable pisugar-server

# enable service
sudo systemctl enable pisugar-server

The service will start automatically after first install. If you stop it, you should restart it manually next time.

Unix Domain Socket / Websocket / TCP

If you need to get the battery data in your own software, you can request via the following ports

Default ports:

uds     /tmp/pisugar-server.sock
tcp 0.0.0.0:8423
ws 0.0.0.0:8422 # standalone websocket api
http 0.0.0.0:8421 # web UI and websocket (/ws)

Commands

Examples:

    nc -U /tmp/pisugar-server.sock
get battery
get model
rtc_alarm_set 2020-06-26T16:09:34+08:00 127
set_button_enable long 1
set_button_shell long sudo shutdown now
safe_shutdown_level 3
safe_shutdown_delay 30

Or

echo "get battery" | nc -q 0 127.0.0.1 8423

CommandDescriptionResponse/Usage
get firmware_versionfirmware versionfirmware_version: [string]
get batterybattery level %battery: [number]
get battery_iBAT current in A (PiSugar 2 only)battery_i: [number]
get battery_vBAT voltage in Vbattery_v: [number]
get battery_chargingcharging status (for new model please use battery_power_plugged and battery_allow_charging to get charging status)battery_charging: [true|false]
get battery_input_protect_enabledBAT input protect enabledbattery_input_protect_enable: [true|false]
get modelpisugar modelmodel: PiSugar 2
get battery_keep_inputKeep power input when reading voltagebattery_keep_input: [true|false]
get battery_led_amountcharging led amount (2 is for new model)battery_led_amount: [2|4]
get battery_power_pluggedcharging usb plugged (new model only)battery_power_plugged: [true|false]
get battery_charging_rangecharging range restart_point% stop_point% (new model only)battery_charging_range: [number, number]
get battery_allow_chargingwhether charging is allowed when usb is plugged (new model only)battery_allow_charging: [true|false]
get battery_output_enabledbattery output statusbattery_output_enabled: [true|false]
get rtc_timertc clockrtc_time: [ISO8601 time string]
get rtc_alarm_enabledrtc wakeup alarm enablertc_alarm_enabled: [true|false]
get rtc_alarm_timertc wakeup alarm timertc_alarm_time: [ISO8601 time string]
get alarm_repeatrtc wakeup alarm repeat in weekdays (127=1111111)alarm_repeat: [number]
get button_enablecustom button enable statusbutton_enable: [single|double|long] [true|false]
get button_shellshell script when button is clickedbutton_shell: [single|double|long] [shell]
get safe_shutdown_levelauto shutdown levelsafe_shutdown_level: [number]
get safe_shutdown_delayauto shutdown delaysafe_shutdown_delay: [number]
get rtc_adjust_ppm(pisugar3) adjust rtc ppmrtc_adjust_ppm: [number]
get auth_usernamehttp auth usernameauth_username: [string]
get anti_mistouchanti-mistouchanti_mistouch: [true|false]
get soft_poweroffsoftware poweroffsoft_poweroff: [true|false]
get soft_poweroff_shellsoft poweroff shell scriptsoft_poweroff_shell: [string]
get temperaturechip temperaturetemperature: [number]
get input_protectbattery hardware protectinput_protect: [true|false]
rtc_pi2rtcsync time pi => rtc
rtc_rtc2pisync time rtc => pi
rtc_websync time web => rtc & pi
rtc_alarm_setset rtc wakeup alarmrtc_alarm_set [ISO8601 time string] [repeat]
rtc_alarm_disabledisable rtc wakeup alarmrtc_alarm_disable
rtc_adjust_ppm(pisugar3) adjust rtc ppm, -500.0 to 500.0rtc_adjust_ppm [number]
set_battery_keep_inputSet keep power input when reading voltageset_battery_keep_input [true|false]
set_button_enableauto shutdown level %set_button_enable [single|double|long] [0|1]
set_button_shellauto shutdown levelsafe_shutdown_level [single|double|long] [shell]
set_battery_input_protectset BAT input protectset_battery_input_protect [true|false]
set_safe_shutdown_levelset auto shutdown level %safe_shutdown_level [number]
set_safe_shutdown_delayset auto shutdown delay in secondsafe_shutdown_delay [number]
set_battery_charging_rangeset charging rangeset_battery_charging_range [number, number]
set_allow_chargingenable or disable chargingset_allow_charging [true|false]
set_battery_outputenable or disable battery outputset_battery_output [true|false]
set_authset or clear http auth (with no arguments)set_auth [username password]
set_anti_mistouchenable or disable anti-mistouchset_anti_mistouch [true|false]
set_soft_poweroffenable or disable software poweroffset_soft_poweroff [true|false]
set_soft_poweroff_shellsoft poweroff shellset_soft_poweroff_shell [string]
set_input_protectenable or disable battery hardware protectset_input_protect [true|false]

Server Config

You can manually edit /etc/pisugar-server/config.json to update the config.

https://github.com/PiSugar/pisugar-power-manager-rs/blob/master/doc/config.md

Uninstall

# Uninstall/Purge
sudo dpkg -P pisugar-server

Release

See https://github.com/PiSugar/pisugar-power-manager-rs/releases

LICENSE

GPL v3