kizniche / Mycodo

An environmental monitoring and regulation system
http://kylegabriel.com/projects/
GNU General Public License v3.0
2.99k stars 499 forks source link

Feature Request: Slider output control for desktop #699

Closed SAM26K closed 5 years ago

SAM26K commented 5 years ago

Mycodo Feature Request:

Request a slide bar type output control. Reason: Want to use it for a light dimmer.

kizniche commented 5 years ago

For PWM Outputs?

SAM26K commented 5 years ago

Yes. Plan on using GPIO for PWM and a level shifter to boost to 10VDC.

kizniche commented 5 years ago

And you're suggesting this be a Dashboard widget?

SAM26K commented 5 years ago

Yes. Would be more convenient to use a slider vs discrete numbers or arrow button.

SAM26K commented 5 years ago

Would be nice to have slider combined with number input for fine adjustment.

SAM26K commented 5 years ago

Just started looking at the GPIO PWM signal with a Fluke 199 scope-meter and it looks like there might be some PW jitter in the signal. Seems to be random but not sure if it's a scope triggering problem or real jitter. Which library does Mycodo use for GPIO PWM control? TIA!

SAM26K commented 5 years ago

Using a new 3B.

SAM26K commented 5 years ago

Screen shot of the output control: Tried different frequencies from 60-22000 Hz same jitter. ie it looks like P W jitters randomly up to 10-20%. Think it might be a lib problem. pwm1

kizniche commented 5 years ago

Have you tried a dedicated hardware PWM pin?

kizniche commented 5 years ago

Also, PWM is controlled by pigpio. You can change the sample rate of pigpio in the configuration menu.

SAM26K commented 5 years ago

what is the difference between "any pin" and "hardware pin"?

SAM26K commented 5 years ago

Changing Configure pigpiod from 1msec to 5msec helped a lot. Now jitter is only around 2%.

kizniche commented 5 years ago

Browsers have an integrated range selector input. I added a PWM Output widget with this. This is what it looks like in Firefox:

Screenshot_2019-09-29 tango - Dashboard - Mycodo 7 7 9

SAM26K commented 5 years ago

Do I need to upgrade to master? Upgraded t0 the latest Mycoco rev and get this in Firefox: Earlier rev of Mycodo works ok (cert is bypassed not accepted). pwm2

SAM26K commented 5 years ago

Also it looks like the output control is no longer compatible with chrome.

SAM26K commented 5 years ago

Guess I have to open a new issue since you closed this one?

kizniche commented 5 years ago

You can reopen this one if it's about the Output PWM Slider desktop widget. I'm not exactly sure what your issue is or the steps to replicate it. You'll need to provide more information.

SAM26K commented 5 years ago

I don't see an option to re-open (using chrome). Need some time to organize the details. Thanks.

SAM26K commented 5 years ago

Turned out the certificate error was unique to the new RPi3B and Firefox. Got that working now but don't see the new slider feature. Is there a Firefox plugin I need to install? Have V7.7.9 installed. TIA.

kizniche commented 5 years ago

You can check the changelog to see the release status of changes. To test the code for 7.7.10 prior to release, you'll need to upgrade to master.

SAM26K commented 5 years ago

Upgraded to master and got PWM (any pin) working but still haven't got hardware pin (12) working. Also getting a db version error:

Python Version: 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] Database Version: 895ddcdef4ce (Incorrect Version. Should be 0ce53d526f13) Daemon Status: Running Daemon Process ID: 4524 Daemon RAM Usage: 67.564 MB Daemon Virtualenv: Yes Frontend RAM Usage: 74.348 MB Frontend Virtualenv: Yes

SAM26K commented 5 years ago

Tried pin 18 PWM no luck with Hardware Pin library but works with any pin library. That is the BCM pin 18 that maps to hardware pin 12 right? TIA,

SAM26K commented 5 years ago

No errors in daemon log. Output Control shows green and active but a scope on the pin shows 0V.If I select "any pin" it works but not with "hardware pin" selected.

SAM26K commented 5 years ago

The new slide control works great but only with "any pin". Thanks.

kizniche commented 5 years ago

Working fine for me. Though, there may have been something fixed with the latest code you're not running (from master). Are you able to verify the PWM signal? Can you explain more by what you mean by it not working? It's very hard for me to figure out the cause of an issue without a good amount of information to investigate.

Pi Pin 18

Mycodo Output PWM

Oscilloscope duty cycle

Mycodo Dash Output Slider

SAM26K commented 5 years ago

Any ideas on how to fix this problem? Complete re-install?

Database Version: 895ddcdef4ce (Incorrect Version. Should be 0ce53d526f13)

kizniche commented 5 years ago

You can just install from master (git clone), then just restore one of your backups when you want to go back to a release.

kizniche commented 5 years ago

To answer the question, there are a lot of potential reasons why the database version doesn't match the expected version. The upgrade log will give an idea, but if you're on master, it's too much work for me to diagnose such an issue that's likely resolved in the latest commit. Again, I'd recommend a git clone of master and install from that, and after you're done testing, use the restore page to go back to a stable release you have in the backup list.

SAM26K commented 5 years ago

How do I git clone from master? I am hooked up as shown in your pix above. By not working I meant there is no square wave on the gpio BCM pin 18 using a scopemeter when "hardware pin" is selected in the PWM output control.

SAM26K commented 5 years ago

upgrade log says "........successful." After upgrading to master.

SAM26K commented 5 years ago

Having mixed results. PWM "Hardware Pin" 18 is working now and much more stable than "any pin". Did the following:

  1. Restored V7.7.8
  2. Upgraded to release V7.7.9 At this; point PWM works fine and database version is green.
  3. Upgraded to master. Slider and PWM works great. Database shows a dB mismatch. No errors in the logs and things seem to work so far. pwm4
SAM26K commented 5 years ago

I don't want to try the rework instructions for db errors in the database before you have a chance to suggest something else. TIA!

kizniche commented 5 years ago

Ah, the mismatch is because I haven't yet updated config.py to reflect the latest DB version. This is expected behavior.

SAM26K commented 5 years ago

Updated the config.py file with the expected dB name and mismatch is gone now.

Since this control will control grow light intensity, I want it to conserve the PWM setting across reboots in case of a power interrupt. Is there anyway to update the Mycodo code to do that? Thanks again.

kizniche commented 5 years ago

What is setting the PWM? If it's a Trigger or Conditional, then it should be set back to whatever duty cycle it was at shortly after the daemon starts back up after a reboot.

SAM26K commented 5 years ago

First attempt is just a GPIO PWM output control controlled by the new PWM dashboard widget and works well. Looking at the manual but so far haven't figured out how to preserve PWM after a reboot without writing a python or linux code control.

kizniche commented 5 years ago

I assume if it's growing something, you're going to want it on a regular, automatic cycle. The Trigger (daily time) can accomplish this. A Conditional can as well, but is more complex (and powerful) and requires experience writing Python.

SAM26K commented 5 years ago

Basically I'm using a mechanical timer to turn the lights on and off and using the rpi and Mycodo only for dimming. Want to preserve what ever the slider value on the dashboard is set to be restored for the PWM output across reboots.

SAM26K commented 5 years ago

Is it possible to somehow make the PWM control static so the last setting is restored after a reboot?

SAM26K commented 5 years ago

Is there a get-measurement command to return PWM duty cycle?

SAM26K commented 5 years ago

Tried this control to return %duty cycle but it always returns 0's and turns the GPIO off after every measurement: sigpwm-18-a

SAM26K commented 5 years ago

errors:

2019-10-05 18:57:45,420 - DEBUG - mycodo.controllers.controller_input_516513a3 - Adding measurements to InfluxDB with ID 516513a3-2650-4866-8faa-da072926b386: {0: {'measurement': 'frequency', 'unit': 'Hz', 'timestamp_utc': None, 'value': 0.0}, 1: {'measurement': 'pulse_width', 'unit': 'us', 'timestamp_utc': None, 'value': 0.0}, 2: {'measurement': 'duty_cycle', 'unit': 'percent', 'timestamp_utc': None, 'value': 0.0}} 2019-10-05 18:58:45,259 - ERROR - mycodo.inputs.rpi_signal_pwm_516513a3 - InputModule raised an exception when taking a reading: unsupported operand type(s) for /: 'float' and 'NoneType' Traceback (most recent call last): File "/var/mycodo-root/mycodo/inputs/base_input.py", line 122, in read self._measurements = self.get_measurement() File "/home/pi/Mycodo/mycodo/inputs/rpi_signal_pwm.py", line 87, in get_measurement self.value_set(2, read_pwm.duty_cycle()) File "/home/pi/Mycodo/mycodo/inputs/rpi_signal_pwm.py", line 173, in duty_cycle return 100.0 * self._high / self._period TypeError: unsupported operand type(s) for /: 'float' and 'NoneType' 2019-10-05 18:59:45,327 - DEBUG - mycodo.controllers.controller_input_516513a3 - Adding measurements to InfluxDB with ID 516513a3-2650-4866-8faa-da072926b386: {0: {'measurement': 'frequency', 'unit': 'Hz', 'timestamp_utc': None, 'value': 0.0}, 1: {'measurement': 'pulse_width', 'unit': 'us', 'timestamp_utc': None, 'value': 0.0}, 2: {'measurement': 'duty_cycle', 'unit': 'percent', 'timestamp_utc': None, 'value': 0.0}}

kizniche commented 5 years ago

The PWM Input is for detecting a PWM signal and writing it to the measurement to the database. You can't both generate and detect a PWM signal on the same pin. You could connect the pin generating the signal to another pin that is measuring the PWM signal, but that's unnecessary because the PWM signal being generated is stored in the database when the duty cycle is changed. So, you're attempting to measure something that's already stored in the database.

For solving your problem of desiring to set the last known duty cycle of a PWM output back to that duty cycle after a reboot, it's not an easy task. It could be done with a Conditional or Trigger, but that would work best if it was also defining the timer for the light itself.

I improved the Output startup/shutdown options, so PWM Outputs will now have the option to have the duty cycle at startup to be set to a user-specified value or the last known value.

SAM26K commented 5 years ago

Trying to use terminal mycodo daemon commands to turn on GPIO PWM outputs and nothing works. Tried:

  1. mycodo-client --dutycycle 44.0 73697cab-bfb3-40a8-b630-09dd49a50f2e (returns error: unrecognized arguments:73697cab-bfb3-40a8-b630-09dd49a50f2e)

  2. mycodo-client --outputon 73697cab-bfb3-40a8-b630-09dd49a50f2e (returns: 2019-10-06 19:48:09,786 [Remote command] Turn on output with ID '73697cab-bfb3-40a8-b630-09dd49a50f2e': Server returned:) and output stays off.

Edit: I didn't see your post above. Trying new version now.

kizniche commented 5 years ago

The command should be mycodo_client.py --outputon ID --dutycycle DUTYCYCLE

SAM26K commented 5 years ago

Still no preservation of settings after reboot: image

SAM26K commented 5 years ago

ie the PWM is low inactive after reboot.

SAM26K commented 5 years ago

This command does work: mycodo-client --outputon aab93daf-8be1-494d-a547-c034849e2964 --dutycycle 44

progress :)

SAM26K commented 5 years ago

PWM setting sticks after a daemon restart but not after a system restart.

SAM26K commented 5 years ago

Seems to be working now. :)