Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin for piusv #981

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

SergeoLacruz
Copy link
Contributor

This is for the piusv+.
The original SW for piusv+ is not up to date any longer. A open source version in C is available here:

https://github.com/dehapama/piupsmonitor-raspberrypi

The plugin communicates directly with the PIUSV via I2C. There is still some work to do but the major
functions are OK. Fine tuning is still needed.

@Morg42
Copy link
Member

Morg42 commented Dec 8, 2024

Anyone able to test this?

Main class of the Plugin. Does all plugin specific stuff and provides the update functions for the items
"""
# Handle
piusv_handle = smbus.SMBus(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does instantiation connect to SMBus? In that case please initialize as None and intantiate in run(). Otherwise, I'd also recommend moving this to init to prevent class-members to span multiple instances (cleaner code)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have a look

@Morg42 Morg42 added this to the Version 1.12 milestone Dec 8, 2024
@wvhn
Copy link
Contributor

wvhn commented Dec 15, 2024

Do I need to install the new piupsmon version in order to run the plugin? I can test the plugin if it runs with the original versio n.

@SergeoLacruz
Copy link
Contributor Author

The plugin does not need any piupsmon. I communicates with piusv via I2C. You can disable piupsmon.

@wvhn
Copy link
Contributor

wvhn commented Dec 15, 2024

Thanks for the plugin! It has been on my to-do list for a long time but I'm not really familiar with Python (yet).

Configuration docs are missing but I got it running. Had to activate i2c in raspi-config and add the user "smarthome" to the "i2c" group.
Now I'm getting errors in the log every few seconds:

> Traceback (most recent call last):
>   File "/home/smarthome/.local/lib/python3.9/site-packages/cherrypy/_cprequest.py", line 659, in respond
>     self._do_respond(path_info)
>   File "/home/smarthome/.local/lib/python3.9/site-packages/cherrypy/_cprequest.py", line 718, in _do_respond
>     response.body = self.handler()
>   File "/home/smarthome/.local/lib/python3.9/site-packages/cherrypy/lib/encoding.py", line 223, in __call__
>     self.body = self.oldhandler(*args, **kwargs)
>   File "/home/smarthome/.local/lib/python3.9/site-packages/cherrypy/_cpdispatch.py", line 54, in __call__
>     return self.callable(*self.args, **self.kwargs)
>   File "/usr/local/smarthome/plugins/piusv/webif/__init__.py", line 109, in get_data_html
>     data['plugin_suspended'] = self.plugin.suspended
> AttributeError: 'piusv' object has no attribute 'suspended'

The Webif is working well, however. It would be nice to see the voltage / current values in their physical units and an explanation of the status code would be great.

Do I have to add database: yes myself to the struct "piusv_info_db"?

@SergeoLacruz
Copy link
Contributor Author

I added the missing status variable. Surprisingly I did not get this error.
The docu needs some work. You can create a visu panel like this:

grafik

The status value is the raw value from the piusv. You are right, it should be translated:
Bit 0 Micro-USB Power active
Bit 1 Uext Power active
Bit 2 Battery low
Bit 3 Battery charging
Bit 4 ?
Bit 5 Button 1 pressed
Bit 6 ?
Bit 7 ?

@wvhn
Copy link
Contributor

wvhn commented Dec 15, 2024

Starts now without error. Thanks!

  • items are accessible and provide data.

  • Looking into different docs I found on the internet the definitions of status bits seem to be:

    • Bit 0 External power supply
    • Bit 1 Power supply from battery

    So plausibility is given w/ status 9 and u_usb=100 / u_ext=5000

  • Poll interval seems to be quite long. No information available how poll interval can be configured

  • this should be moved to plugin config, too:
    # setup scheduler for device poll loop (disable the following line, if you don't need to poll the device. Rember to comment the self_cycle statement in __init__ as well)

  • automatic updates in web interface are not working. I always have to update manually. Update interval changes back to 30 sec if you try to change it

  • Is there a reason why battery voltage is v_batt and not u_batt like u_ext and u_rasp?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants