kizniche / Mycodo

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

request to add Adafruit NeoKey 1x4 input board #1353

Closed Nithalik closed 1 month ago

Nithalik commented 11 months ago

Hi Kyle,

Found a device from adafruit that would be able to add a lot of possible functionality for people not super skilled in programming if you can add this input device. It is basically a i2c controlled mini keyboard that has 4 keyboard keys and 4 neopixels. basically a easy way to add 4 i2c controlled momentary switches to a system. It also has 8 possible i2c addresses so there is a lot of possibility here

https://www.adafruit.com/product/4980

adafruit neokey library: https://docs.circuitpython.org/projects/neokey/en/latest/

i have ordered one and been playing with it, have gotten their test code working, but getting it to work with mycodo is not working for me, with you already having neopixels added not sure if this would be complicated to sort out

kizniche commented 11 months ago

How were you envisioning it integrating?

Nithalik commented 11 months ago

im wanting to use the switches to start functions, and change what is displayed on a different i2c screen. neopixels are just a added bonus, they could be used as status led's or to show that the button was pressed and recognized

you can also have 8 of these together, so 32 total keys from one i2c bus

like be able to have a button to trigger some of the input actions on this page https://kizniche.github.io/Mycodo/Inputs/#input-actions

the more useful ones would be to trigger the supported actions which is where i would use it the most

https://kizniche.github.io/Mycodo/Supported-Actions/

button to capture a pic from all the cameras / execute command: shell / display backlight / pause would be the big ones i can think of right away.

im not currently able to access my mycodo system so not able to really go through all the different sections to see where it is useful, but i envision using it so i dont have to go into the webui when i do maintenance, i can do it by buttons.

-pause/enable everything -run waterchange function -pH balance / add nutrients -turn off main lights (or dim)

kizniche commented 11 months ago

I could throw together a simple function that you could execute one or more actions when a button is pressed.

Nithalik commented 11 months ago

that would work for almost all of my use cases, and i think i can add a lot with that. the only other thing is if there would be a way to address the neoled's too.

also need to be able to change the i2c address, will probably end up using more then 1

example for 1 button - when button is pressed, runs action, then flashes the neoled while that is active. and push the button again to undo if its not one based on a timer.

kizniche commented 11 months ago

All three sound doable. I'll let you know when I have a module for you to test.

Nithalik commented 11 months ago

All three sound doable. I'll let you know when I have a module for you to test.

cool, thanks

kizniche commented 11 months ago

Attached below is a module to test. Rename from txt to py and import as a Function. You will also need to upgrade to master to be able to use Actions for Custom Functions and see the Action ID needed to use the new Function. The instructions after creating the Function should be sufficient to use it. I won't detail how to use it to see if the instructions can stand on their own. Let me know if you run into any issues or can't get it working. Remember to enable the Function debug logging when testing to see all debug messages in the log.

function_adafruit_neokey_01.txt

Nithalik commented 11 months ago

Thank you for that, got it installed.

when i push a button it just lights up the LED underneath but nothing else. below is the error log.

just have all buttons mapped to deactivate a function for testing.

image

your assistance here is greatly appreciated



``` AttributeError: 'list' object has no attribute 'unique_id'
2023-12-10 15:31:46,916 - ERROR - mycodo.function.function_adafruit_neokey_01_8df033ec - Executing Action with ID dd3d8ad0
Traceback (most recent call last):
  File "/home/nithalik/Mycodo/mycodo/functions/custom_functions/function_adafruit_neokey_01.py", line 236, in check_key_press
    action.unique_id,
AttributeError: 'list' object has no attribute 'unique_id'
2023-12-10 15:31:46,928 - INFO - mycodo.function.function_adafruit_neokey_01_8df033ec - Button 4
2023-12-10 15:31:47,461 - ERROR - mycodo.function.function_adafruit_neokey_01_8df033ec - Executing Action with ID 8ceb33e8
Traceback (most recent call last):
  File "/home/nithalik/Mycodo/mycodo/functions/custom_functions/function_adafruit_neokey_01.py", line 236, in check_key_press
    action.unique_id,
AttributeError: 'list' object has no attribute 'unique_id'
2023-12-10 15:31:47,473 - ERROR - mycodo.function.function_adafruit_neokey_01_8df033ec - Executing Action with ID d05c3d60
Traceback (most recent call last):
  File "/home/nithalik/Mycodo/mycodo/functions/custom_functions/function_adafruit_neokey_01.py", line 236, in check_key_press
    action.unique_id,
AttributeError: 'list' object has no attribute 'unique_id'
2023-12-10 15:31:47,486 - ERROR - mycodo.function.function_adafruit_neokey_01_8df033ec - Executing Action with ID dd3d8ad0
Traceback (most recent call last):
  File "/home/nithalik/Mycodo/mycodo/functions/custom_functions/function_adafruit_neokey_01.py", line 236, in check_key_press
    action.unique_id,
AttributeError: 'list' object has no attribute 'unique_id'
kizniche commented 11 months ago

Here is an updated module. Delete all of this Function type, then delete the Function module, then import this new Function module.

function_adafruit_neokey_01.txt

kizniche commented 11 months ago

Wait, you didn't add the correct Function. That's one of the built-in functions. Your screenshot is of the Execute Actions Function, not the Device: Adafruit Neokey (Button Executes Actions) Function.

Nithalik commented 11 months ago

the screenshot was just the execute actions, to show the id's

in changing the settings in it, now the method page wont load giving 500 error. i must have done something stupid. reinstalling mycodo and will test out the new file

Error (Full Traceback):

Traceback (most recent call last): File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 2190, in wsgi_app response = self.full_dispatch_request() File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 1486, in full_dispatch_request rv = self.handle_user_exception(e) File "/var/mycodo-root/env/lib/python3.9/site-packages/flask_restx/api.py", line 674, in error_router return original_handler(e) File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 1484, in full_dispatch_request rv = self.dispatch_request() File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 1469, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(*view_args) File "/var/mycodo-root/env/lib/python3.9/site-packages/flask_login/utils.py", line 290, in decorated_view return current_app.ensure_sync(func)(args, **kwargs) File "/home/nithalik/Mycodo/mycodo/mycodo_flask/routes_function.py", line 514, in page_function return render_template('pages/function.html', File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/templating.py", line 151, in render_template return _render(app, template, context) File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/templating.py", line 132, in _render rv = template.render(context) File "/var/mycodo-root/env/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render self.environment.handle_exception() File "/var/mycodo-root/env/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception raise rewrite_traceback_stack(source=source) File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function.html", line 3, in top-level template code {% set help_page = ["https://kizniche.github.io/Mycodo/Functions/", dict_translation['function']['title']] %} File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/layout.html", line 383, in top-level template code {%- block body %}{% endblock -%} File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function.html", line 135, in block 'body' {% include 'pages/function_options/custom_function_entry.html' %} File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function_options/custom_function_entry.html", line 51, in top-level template code {% include 'pages/function_options/custom_function_options.html' %} File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function_options/custom_function_options.html", line 292, in top-level template code {% include 'pages/actions.html' %} File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/actions.html", line 40, in top-level template code {% include 'pages/form_options/Custom_Options.html' %} File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/form_options/Custom_Options.html", line 285, in top-level template code <option value="{{each_dev.unique_id}}"{% if (channel_options and each_dev.unique_id == custom_options_values[unique_id][channel][each_option['id']]) or (custom_options_values and each_dev.unique_id == custom_options_values[unique_id][each_option['id']]) %} selected{% endif %}>[{{name}} {{'%02d' % each_dev.id}}] {{each_dev.name}} File "/var/mycodo-root/env/lib/python3.9/site-packages/jinja2/environment.py", line 466, in getitem return obj[argument] jinja2.exceptions.UndefinedError: dict object has no element Undefined

kizniche commented 11 months ago

The IDs should show on all Functions. You should be only using the Function I created.

kizniche commented 11 months ago

What did you do in the time between it working and not working?

Nithalik commented 11 months ago

all i did was change the ID's in the new module to random numbers, thinking that using the id's from the execute actions function was causing the issue

Nithalik commented 11 months ago

i was just showing with that screenshot that i didnt make a error copying the action id's into the boxes in the new module

kizniche commented 11 months ago

It would be most beneficial if you can give steps to reproduce any errors you get. If you found an error that crashes the frontend, that is a major issue.

Nithalik commented 11 months ago

It would be most beneficial if you can give steps to reproduce any errors you get. If you found an error that crashes the frontend, that is a major issue.

i am working on trying to reproduce it now, as i could not load the method page, not much i could do other then reinstall. which i am doing now. if i can reproduce it, i will provide steps

all i did, was change the ids in the new module, not sure how that changed other things.

Nithalik commented 11 months ago

pretty sure i see what causes it, fresh install, installed the new module, and clicked on add action in the module itself, after adding a module to deactivate a controller in the action itself it gave the 500 error when i went to load the main functions page

/Error (Full Traceback):

Traceback (most recent call last): File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 2190, in wsgi_app response = self.full_dispatch_request() File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 1486, in full_dispatch_request rv = self.handle_user_exception(e) File "/var/mycodo-root/env/lib/python3.9/site-packages/flask_restx/api.py", line 674, in error_router return original_handler(e) File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 1484, in full_dispatch_request rv = self.dispatch_request() File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 1469, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(*view_args) File "/var/mycodo-root/env/lib/python3.9/site-packages/flask_login/utils.py", line 290, in decorated_view return current_app.ensure_sync(func)(args, **kwargs) File "/home/nithalik/Mycodo/mycodo/mycodo_flask/routes_function.py", line 514, in page_function return render_template('pages/function.html', File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/templating.py", line 151, in render_template return _render(app, template, context) File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/templating.py", line 132, in _render rv = template.render(context) File "/var/mycodo-root/env/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render self.environment.handle_exception() File "/var/mycodo-root/env/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception raise rewrite_traceback_stack(source=source) File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function.html", line 3, in top-level template code {% set help_page = ["https://kizniche.github.io/Mycodo/Functions/", dict_translation['function']['title']] %} File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/layout.html", line 383, in top-level template code {%- block body %}{% endblock -%} File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function.html", line 135, in block 'body' {% include 'pages/function_options/custom_function_entry.html' %} File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function_options/custom_function_entry.html", line 51, in top-level template code {% include 'pages/function_options/custom_function_options.html' %} File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function_options/custom_function_options.html", line 292, in top-level template code {% include 'pages/actions.html' %} File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/actions.html", line 40, in top-level template code {% include 'pages/form_options/Custom_Options.html' %} File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/form_options/Custom_Options.html", line 285, in top-level template code <option value="{{each_dev.unique_id}}"{% if (channel_options and each_dev.unique_id == custom_options_values[unique_id][channel][each_option['id']]) or (custom_options_values and each_dev.unique_id == custom_options_values[unique_id][each_option['id']]) %} selected{% endif %}>[{{name}} {{'%02d' % each_dev.id}}] {{each_dev.name}} File "/var/mycodo-root/env/lib/python3.9/site-packages/jinja2/environment.py", line 466, in getitem return obj[argument] jinja2.exceptions.UndefinedError: dict object has no element Undefined

Nithalik commented 11 months ago

Got it somewhat working.

new mycodo system. image

all the activate and deactivate does is turn on or off the ph and ec regulation.

the buttons work to turn it on and off. the only issue is, when using the deactivate action, the led never turns off. when using activate the led turns on for 1 second. if there is no action tied to a button it also turns on the LED and it does not turn off on any future button presses.

looks like the behaviour when deactivating a controller is leaving the led on, maybe because it just sees the controller deactivated so its duration never ends? if i go and turn on the controller the led does not turn off

I think the best use for the LED's on this board, is to only have them light up when the corresponding buttons actions are being ran, or for a set time after the last action happens.

image

logs look good now

023-12-10 16:19:07,905 - INFO - mycodo.function.function_adafruit_neokey_01_38392045 - Button 2 2023-12-10 16:19:08,651 - DEBUG - mycodo.function.function_adafruit_neokey_01_38392045 - Return message: Deactivate Controller e4a02994-af6c-49d0-bb9b-619e49782034 (Regulate pH and Electrical Conductivity). 2023-12-10 16:19:08,945 - INFO - mycodo.controllers.controller_function_e4a02994 - Deactivated in 196.5 ms 2023-12-10 16:19:13,649 - INFO - mycodo.controllers.controller_function_e4a02994 - Activated in 352.2 ms 2023-12-10 16:19:15,049 - INFO - mycodo.function.function_adafruit_neokey_01_38392045 - Button 2 2023-12-10 16:19:15,736 - DEBUG - mycodo.function.function_adafruit_neokey_01_38392045 - Return message: Deactivate Controller e4a02994-af6c-49d0-bb9b-619e49782034 (Regulate pH and Electrical Conductivity). 2023-12-10 16:19:15,908 - INFO - mycodo.controllers.controller_function_e4a02994 - Deactivated in 68.5 ms 2023-12-10 16:19:17,740 - ERROR - mycodo - Function controller with ID e4a02994-af6c-49d0-bb9b-619e49782034 not found 2023-12-10 16:19:21,248 - INFO - mycodo.function.function_adafruit_neokey_01_38392045 - Button 1 2023-12-10 16:19:21,977 - DEBUG - mycodo.function.function_adafruit_neokey_01_38392045 - Return message: Activate Controller e4a02994-af6c-49d0-bb9b-619e49782034 (Regulate pH and Electrical Conductivity). 2023-12-10 16:19:22,660 - INFO - mycodo.controllers.controller_function_e4a02994 - Activated in 571.2 ms

Found bug reproduction steps:

add neokey function

add controller:deactivate under measurement settings

image

do not need to add anything specific under, just save as blank and then try to load the functions page and you get 500 error.

i think the fix for this is just removing the measurement settings area as it is not needed for the neokey function, i was only playing with it at first as part of my troubleshooting

kizniche commented 11 months ago

I was able to replicate the error. Looking into a fix.

kizniche commented 11 months ago

Fixed the error. You'll need to upgrade to master to get that fix. And to fix the LED on all but the first button not working, change the last line of the module from:

self.neokey.pixels[0] = 0x0

to

self.neokey.pixels[key] = 0x0

The current behavior is to only have the LED on when the actions are executing. You are likely choosing short-lived actions, why the LED goes off quickly.

Nithalik commented 11 months ago

all working now, and the code change worked.

there are cases where having it be enabled for total duration would be helpful, would it be difficult to be able to select per key if it is pixels[0] to pixels[key]

kizniche commented 11 months ago

What do you mean by enabled for total duration? The LED stays on for as long as it takes the Actions to complete.

I also just majorly refactored the Function Module to utilize another method for organizing configuration data so it's easier to work with in the code. And added a delay to keep the LED on after all actions have completed. I also made the key press spawn a thread to complete the actions, so you can now have multiple key action sets running at the same time and you don't have to wait for the first to finish before starting the next.

function_adafruit_neokey_01.txt

Nithalik commented 11 months ago

Your screenshot does not look correct. Your Function is missing all options to set for each key.

i did upgrade to master. the screentshot was just of the execute actions of the functions i was going to use, to show the id's

What do you mean by enabled for total duration? The LED stays on for as long as it takes the Actions to complete.

I also just majorly refactored the Function Module to utilize another method for organizing configuration data so it's easier to work with in the code. And added a delay to keep the LED on after all actions have completed. I also made the key press spawn a thread to complete the actions, so you can now have multiple key action sets running at the same time and you don't have to wait for the first to finish before starting the next.

function_adafruit_neokey_01.txt

i just misunderstood the code change. what you did is perfect, the new changes make it very clear what is happening. I would say it is complete for at least my needs now.

Thank you very much for doing this

kizniche commented 11 months ago

I'm working on allowing the color of each key to be set

Nithalik commented 11 months ago

I'm working on allowing the color of each key to be set

if your working on that side, is it possible to have a start colour, then it change colour on its last action? like a colour change to signify when it is on its last action. just a thought

kizniche commented 11 months ago

Here is an update that adds LED colors for resting, running, and last action running. Let me know if it works.

function_adafruit_neokey_01.txt

Nithalik commented 11 months ago

Here is an update that adds LED colors for resting, running, and last action running. Let me know if it works.

function_adafruit_neokey_01.txt

very nice just tested and it all works.

only thing i would add, is since there is a resting led state now, maybe add a brightness option to resting so you can have the light off on rest

kizniche commented 11 months ago

I don't think brightness can be set. Here is a version that turns the LED off when set to 0.

function_adafruit_neokey_01.txt

kizniche commented 11 months ago

This version may or may not work to set the brightness.

function_adafruit_neokey_01.txt

Nithalik commented 11 months ago

Just running into a bit of a issue,

It does not seem like the buttons are actually doing anything now. the logs show the button press, but not that it is triggering an action, have saved it and tested a few times

2023-12-10 19:06:00,746 - INFO - mycodo.controllers.controller_function_7731aef4 - Activated in 710.7 ms 2023-12-10 19:06:01,331 - INFO - mycodo.function.function_adafruit_neokey_01_7731aef4 - Key 1 2023-12-10 19:06:02,441 - INFO - mycodo.function.function_adafruit_neokey_01_7731aef4 - Key 2 2023-12-10 19:06:03,276 - INFO - mycodo.function.function_adafruit_neokey_01_7731aef4 - Key 3 2023-12-10 19:06:05,563 - INFO - mycodo.function.function_adafruit_neokey_01_7731aef4 - Key 4 2023-12-10 19:06:09,512 - INFO - mycodo.controllers.controller_function_7731aef4 - Deactivated in 125.4 ms 2023-12-10 19:07:07,837 - DEBUG - mycodo.controllers.controller_function_7731aef4 - loop() not found 2023-12-10 19:07:07,839 - DEBUG - mycodo.controllers.controller_function_7731aef4 - listener() found 2023-12-10 19:07:07,839 - DEBUG - mycodo.controllers.controller_function_7731aef4 - Starting listener() thread 2023-12-10 19:07:07,840 - INFO - mycodo.controllers.controller_function_7731aef4 - Activated in 717.4 ms 2023-12-10 19:07:27,870 - INFO - mycodo.function.function_adafruit_neokey_01_7731aef4 - Key 1

kizniche commented 11 months ago

Here is a version with more debugging lines to find out what's wrong. Press a key that has an action associated with it and watch the log for debug lines.

function_adafruit_neokey_01.txt

Nithalik commented 11 months ago

This version may or may not work to set the brightness.

function_adafruit_neokey_01.txt

this results in the below error, brightness is not an issue, it was more having the led off when not needed

SError: [Errno 121] Remote I/O error

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/var/mycodo-root/env/lib/python3.9/site-packages/adafruit_bus_device/i2c_device.py", line 181, in __probe_for_device self.i2c.readfrom_into(self.device_address, result) File "/var/mycodo-root/env/lib/python3.9/site-packages/busio.py", line 197, in readfrom_into return self._i2c.readfrom_into(address, buffer, stop=True) File "/var/mycodo-root/env/lib/python3.9/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 67, in readfrom_into readin = self._i2c_bus.read_bytes(address, end - start) File "/var/mycodo-root/env/lib/python3.9/site-packages/Adafruit_PureIO/smbus.py", line 170, in read_bytes return self._device.read(number) OSError: [Errno 121] Remote I/O error

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/nithalik/Mycodo/mycodo/functions/custom_functions/function_adafruit_neokey_01.py", line 274, in initialize self.neokey = NeoKey1x4( File "/var/mycodo-root/env/lib/python3.9/site-packages/adafruit_neokey/neokey1x4.py", line 57, in init super().init(i2c_bus, addr) File "/var/mycodo-root/env/lib/python3.9/site-packages/adafruit_seesaw/seesaw.py", line 147, in init self.i2c_device = I2CDevice(i2c_bus, addr) File "/var/mycodo-root/env/lib/python3.9/site-packages/adafruit_bus_device/i2c_device.py", line 62, in init self.__probe_for_device() File "/var/mycodo-root/env/lib/python3.9/site-packages/adafruit_bus_device/i2c_device.py", line 184, in __probe_for_device raise ValueError("No I2C device at address: 0x%x" % self.device_address) ValueError: No I2C device at address: 0x30 2023-12-10 19:11:39,586 - INFO - mycodo.controllers.controller_function_d52ad914 - Activated in 194.5 ms

kizniche commented 11 months ago

I don't think this is a result of the brightness code I put in: "ValueError: No I2C device at address: 0x30"

Nithalik commented 11 months ago

here are the better error logs, it can see the address now and still acting the same, it recognizes the button press, but then does complete

2023-12-10 19:16:51,110 - DEBUG - mycodo.function.function_adafruit_neokey_01_90f34fe6 - Parsed Action IDs: OrderedDict([(0, ['34505ec9']), (1, ['8e4a9986']), (2, []), (3, [])])
2023-12-10 19:16:51,649 - DEBUG - mycodo.controllers.controller_function_90f34fe6 - loop() not found
2023-12-10 19:16:51,651 - DEBUG - mycodo.controllers.controller_function_90f34fe6 - listener() found
2023-12-10 19:16:51,651 - DEBUG - mycodo.controllers.controller_function_90f34fe6 - Starting listener() thread
2023-12-10 19:16:51,653 - INFO - mycodo.controllers.controller_function_90f34fe6 - Activated in 722.0 ms
2023-12-10 19:17:01,970 - DEBUG - mycodo.function.function_adafruit_neokey_01_90f34fe6 - Key 1
2023-12-10 19:17:02,493 - DEBUG - mycodo.function.function_adafruit_neokey_01_90f34fe6 - Attempting to execute Action with ID: 34505ec9
2023-12-10 19:17:10,920 - DEBUG - mycodo.function.function_adafruit_neokey_01_90f34fe6 - Key 2
2023-12-10 19:17:11,439 - DEBUG - mycodo.function.function_adafruit_neokey_01_90f34fe6 - Attempting to execute Action with ID: 8e4a9986
2023-12-10 19:17:14,998 - DEBUG - mycodo.function.function_adafruit_neokey_01_90f34fe6 - Key 1
2023-12-10 19:17:15,518 - DEBUG - mycodo.function.function_adafruit_neokey_01_90f34fe6 - Attempting to execute Action with ID: 34505ec9
kizniche commented 11 months ago

Are you sure you saved the action options?

Nithalik commented 11 months ago

Are you sure you saved the action options?

yes, i ensured i saved, and also restated the rpi to make sure

also the brightness control is tested and works now

kizniche commented 11 months ago

Try this with the debug lines moved to try to understand more.

function_adafruit_neokey_01.txt

Nithalik commented 11 months ago

the logs now are not even showing the button press on the most recent file. only shows activating and deactivating the controller

2023-12-10 19:27:27,355 - INFO - mycodo.controllers.controller_function_2f7d090c - Deactivated in 234.4 ms
2023-12-10 19:27:29,367 - DEBUG - mycodo.function.function_adafruit_neokey_01_2f7d090c - Parsed Action IDs: OrderedDict([(0, ['e793b14e']), (1, ['5e9e8958']), (2, []), (3, [])])
2023-12-10 19:27:29,906 - DEBUG - mycodo.controllers.controller_function_2f7d090c - loop() not found
2023-12-10 19:27:29,907 - DEBUG - mycodo.controllers.controller_function_2f7d090c - listener() found
2023-12-10 19:27:29,907 - DEBUG - mycodo.controllers.controller_function_2f7d090c - Starting listener() thread

was the most recent before the upgrade

kizniche commented 11 months ago

I didn't change anything except move a log line. So there's something not working about the device if it's not detectng button presses.

kizniche commented 11 months ago

Are you pressing the button for long enough?

Nithalik commented 11 months ago

yes the panel recognizes the button press, the led even turns on to what it is supposed to be for the running led colour, it just stays at that colour and nothing changes in the log

Nithalik commented 11 months ago

i went back to the version before you added the different led colour options and everything works right away

What do you mean by enabled for total duration? The LED stays on for as long as it takes the Actions to complete.

I also just majorly refactored the Function Module to utilize another method for organizing configuration data so it's easier to work with in the code. And added a delay to keep the LED on after all actions have completed. I also made the key press spawn a thread to complete the actions, so you can now have multiple key action sets running at the same time and you don't have to wait for the first to finish before starting the next.

function_adafruit_neokey_01.txt

I went back to this version and everything is working again, i re-tried every version that was made after this tothis

kizniche commented 11 months ago

Here's one with many more debug lines. Are you deleting the Function then deleting the Function Module, then importing the new module, then adding the Function?

function_adafruit_neokey_01.txt

Nithalik commented 11 months ago

Here's one with many more debig lines. Are you deleting the Function then deleting the Function Module, then importing the new module, then adding the Function?

function_adafruit_neokey_01.txt

yes i am following that process, delete the function, then the function module, then importing and adding new function

Nithalik commented 11 months ago

here is the error log from the most

Here's one with many more debug lines. Are you deleting the Function then deleting the Function Module, then importing the new module, then adding the Function?

function_adafruit_neokey_01.txt

here is the error log from this one, buttons still do not seem to do anything, have to go to the old file again

2023-12-10 19:47:07,584 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Parsed Action IDs: OrderedDict([(0, ['8e4a9986']), (1, ['34505ec9']), (2, []), (3, [])])
2023-12-10 19:47:07,584 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Brightness: 0.2
2023-12-10 19:47:07,585 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Colors: OrderedDict([(0, 0), (1, 0), (2, 0), (3, 0)]), OrderedDict([(0, 85), (1, 85), (2, 85), (3, 85)]), OrderedDict([(0, 255), (1, 255), (2, 255), (3, 255)])
2023-12-10 19:47:08,122 - DEBUG - mycodo.controllers.controller_function_eed44e0c - loop() not found
2023-12-10 19:47:08,124 - DEBUG - mycodo.controllers.controller_function_eed44e0c - listener() found
2023-12-10 19:47:08,125 - DEBUG - mycodo.controllers.controller_function_eed44e0c - Starting listener() thread
2023-12-10 19:47:08,126 - INFO - mycodo.controllers.controller_function_eed44e0c - Activated in 910.0 ms
2023-12-10 19:47:13,142 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Key 2
2023-12-10 19:47:13,663 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Executing Actions for Key 1
2023-12-10 19:47:18,630 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Key 1
2023-12-10 19:47:19,152 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Executing Actions for Key 0
2023-12-10 19:47:25,412 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Key 2
2023-12-10 19:47:26,451 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Executing Actions for Key 1
2023-12-10 19:47:27,404 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Key 1
kizniche commented 11 months ago

Now we're getting somewhere. Try this version. I suspect we'll see something strange in this one.

function_adafruit_neokey_01.txt

Nithalik commented 11 months ago

Now we're getting somewhere. Try this version. I suspect we'll see something strange in this one.

function_adafruit_neokey_01.txt

Here are the logs from that one

2023-12-10 19:54:10,793 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Parsed Action IDs: OrderedDict([(0, ['34505ec9']), (1, ['8e4a9986']), (2, []), (3, [])])
2023-12-10 19:54:10,794 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Brightness: 0.2
2023-12-10 19:54:10,794 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Colors: OrderedDict([(0, 0), (1, 0), (2, 0), (3, 0)]), OrderedDict([(0, 85), (1, 85), (2, 85), (3, 85)]), OrderedDict([(0, 255), (1, 255), (2, 255), (3, 255)])
2023-12-10 19:54:11,332 - DEBUG - mycodo.controllers.controller_function_b6dc24df - loop() not found
2023-12-10 19:54:11,332 - DEBUG - mycodo.controllers.controller_function_b6dc24df - listener() found
2023-12-10 19:54:11,333 - DEBUG - mycodo.controllers.controller_function_b6dc24df - Starting listener() thread
2023-12-10 19:54:11,334 - INFO - mycodo.controllers.controller_function_b6dc24df - Activated in 712.1 ms
2023-12-10 19:54:12,799 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Key 2
2023-12-10 19:54:13,327 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Executing Actions for Key 2
2023-12-10 19:54:18,227 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Key 1
2023-12-10 19:54:18,749 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Executing Actions for Key 1

here are the logs from the last version that was working

2023-12-10 19:51:34,573 - INFO - mycodo.controllers.controller_function_11107a50 - Deactivated in 230.7 ms
2023-12-10 19:51:41,250 - DEBUG - mycodo.controllers.controller_function_11107a50 - loop() not found
2023-12-10 19:51:41,251 - DEBUG - mycodo.controllers.controller_function_11107a50 - listener() found
2023-12-10 19:51:41,252 - DEBUG - mycodo.controllers.controller_function_11107a50 - Starting listener() thread
2023-12-10 19:51:41,262 - INFO - mycodo.controllers.controller_function_11107a50 - Activated in 731.0 ms
2023-12-10 19:51:51,647 - INFO - mycodo.function.function_adafruit_neokey_01_11107a50 - Key 1
2023-12-10 19:51:52,401 - DEBUG - mycodo.function.function_adafruit_neokey_01_11107a50 - Return message:  Deactivate Controller 4671a538-ed2d-4c17-888e-00eaab4414c0 (Seedling Regulate pH and Electrical Conductivity).
2023-12-10 19:51:52,699 - INFO - mycodo.controllers.controller_function_4671a538 - Deactivated in 210.6 ms
2023-12-10 19:52:00,551 - INFO - mycodo.function.function_adafruit_neokey_01_11107a50 - Key 2
2023-12-10 19:52:01,247 - DEBUG - mycodo.function.function_adafruit_neokey_01_11107a50 - Return message:  Activate Controller 4671a538-ed2d-4c17-888e-00eaab4414c0 (Seedling Regulate pH and Electrical Conductivity).
2023-12-10 19:52:01,691 - INFO - mycodo.controllers.controller_function_4671a538 - Activated in 356.7 ms
2023-12-10 19:52:07,173 - INFO - mycodo.function.function_adafruit_neokey_01_11107a50 - Key 1
2023-12-10 19:52:07,866 - DEBUG - mycodo.function.function_adafruit_neokey_01_11107a50 - Return message:  Deactivate Controller 4671a538-ed2d-4c17-888e-00eaab4414c0 (Seedling Regulate pH and Electrical Conductivity).
2023-12-10 19:52:08,205 - INFO - mycodo.controllers.controller_function_4671a538 - Deactivated in 245.7 ms
kizniche commented 11 months ago

I understand. There's nothing I can tell between the versions that would affect anything. THe only thing I cna do is give you versions to try, since i don't have the device.

kizniche commented 11 months ago

This version I threw in a slew of debug lines.

function_adafruit_neokey_01.txt