Giter VIP home page Giter VIP logo

pisugar-power-manager's Introduction

pisugar-power-manager

Management program for PiSugar 2

Note: python version will be deprecated, we had migranted to rust.

Install

# before installation

# turn on the i2c interface on raspbian.
# make sure there's no other phat using address 0x32 or 0x75
# make sure your python version is 3.6

# check if device 0x32 and 0x75 work. 
# If you can't find them or find some meaningless random code, please reattach the battery module and try again. 
i2cdetect -y 1
i2cdump -y 1 0x32
i2cdump -y 1 0x75

# install
apt-get update
apt-get install python3-pyqt5 pyqt5-dev-tools
pip3 install smbus2 websockets

Start the core with Web UI:

$ python3 core/PiSugarCore.py

# core program will host an http server at port 8000
# please visit http://<ip of your pi>:8000

# core program will also create a unix domain socket file: /tmp/pisugar.sock
# use following commands to get / set data from the battery

# get model  (pisugar model)
# get battery  (battery level percent)
# get battery_v  (lithium battery votage)
# get battery_i  (lithium battery current)
# get battery_charging  (charging status)
# get rtc_time  (rtc time string)
# get rtc_time_list  (rtc time in python list)
# get rtc_alarm_flag  (rtc alarm flag)
# get safe_shutdown_level
# get alarm type (1: daily alarm, 0: off)
# get alarm time (alarm timestamp)
# get alarm type (alarm week repeat)
# get button enable <type> (type: single/double/long)
# get button shell <type> (type: single/double/long)

# rtc_clean_flag  (clean alarm flag)
# rtc_pi2rtc  (sync time from Pi to rtc)
# rtc_alarm_set  (set auto wake up alarm)
# rtc_alarm_disable  (disable wake up alarm)
# rtc_test_wake (test wake in 1min30sec)
# set_button_enable (argv1: single/double/long  argv2: 1/0)
# set_button_shell (argv1: single/double/long  argv2: shell script to execute)
# set_safe_shutdown_level (e.g. -1 / 3 / 5)

# e.g. get battery level precentage
$ echo get battery | nc -U /tmp/pisugar.sock
63.15938281249997

# e.g. set auto wake up alarm on 15:39:00 repeat on Sun, Mon, Tue, Wed, Sat
$ echo rtc_alarm_set 0,39,15,0,0,0,0 0b1001111 | nc -U /tmp/pisugar.sock
Done.


Start with Destop UI (not finished yet):

$ export DISPLAY=:0
$ python3 app.py

Architecture diagram

pisugar-power-manager's People

Contributors

jdaielin avatar wlmh110 avatar fengyc avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.