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

Error after restarts: The GPIO channel has not been set up as an OUTPUT #1238

Closed
TeaPot169 opened this issue Oct 27, 2022 · 7 comments
Closed

Comments

@TeaPot169
Copy link

Describe the problem/bug

I have 2 outputs that are controlled by conditional controllers. I have a few other outputs that I turn on and off manually.
We experience frequent power outages where I assume the PI shuts down and will restart again.
After this the 2 outputs that are automated no longer automatically switch on or off, and when manually trying to switch them they give the following error:
2022-10-27 12:23:22,099 - ERROR - mycodo.outputs.on_off_gpio_b1fcf97d - State change error: The GPIO channel has not been set up as an OUTPUT
Traceback (most recent call last):
File "/home/pi/Mycodo/mycodo/outputs/on_off_gpio.py", line 175, in output_switch
not self.options_channels['on_state'][output_channel])
RuntimeError: The GPIO channel has not been set up as an OUTPUT

If I go into the output and save it, it functions normally again until after another power outage.

A few more details that may be important:
The other outputs that are not under controllers switch on/off fine after the shutdown without having to be saved again.
I have moved the GPIO pin of the controlled output around on the PI to see if this makes a difference, no success.
I have even moved it to the GPIO pin of a previously working output that I used to switch on manually and modified the controller to control this output. The issue then carried over to that output as well...

Any advice on how to possibly add something in that automatically saves the outputs at certain intervals.
Or of course a solution that would prevent the issue altogether, any help would be appreciated.

Versions:

  • Mycodo Version: 8.14.2
  • Raspberry Pi Version: 2B+
  • Raspbian OS Version:
@kizniche
Copy link
Owner

kizniche commented Nov 6, 2022

There's nothing I can see in the code that would cause this behavior. I've also never experienced it and have used this output type extensively (it was the very first Output created in Mycodo). Perhaps the power outages have caused fileysetem corruption. An uninterruptable power supply is recommended to allow proper shutdown and filesystem dismounting. If you can provide a way to replicate the issue without cutting the power to the Pi, I'll investigate the issue. I would suggest installing the OS/Mycodo on a new SD card and see if the issue persists, which will indicate if it's a filesystem/disk issue.

@kizniche
Copy link
Owner

kizniche commented Nov 6, 2022

The only reason I can think why this would happen is if you have something else set up to set your GPIO pins as something other than outputs (i.e. as input). You may be incorrectly using the GPIO State Condition rather than the Output State Condition in your Conditional Controller.

@kizniche
Copy link
Owner

kizniche commented Nov 6, 2022

I just updated the descriptions of the Conditions to make this distinction more clear in 503a708.

@TeaPot169
Copy link
Author

TeaPot169 commented Nov 10, 2022 via email

@kizniche
Copy link
Owner

Is this the cause of the issue: #1238 (comment) ?

@TeaPot169
Copy link
Author

TeaPot169 commented Dec 5, 2022

I went to check the conditional controller, nothing seems out of place there to me, they are working with the output state condition and not GPIO state condition.

This is my code is the conditional controller:

# Example code for learning how to use a Conditional. See the manual for more information.
self.logger.info("Starting humidity measurement")

self.run_loop_count += 1  # Counts how many times the run code has been executed

measurement = self.condition("41d0035d")  # Replace ID with correct Conditional ID
self.logger.info(f"Measurement value is {measurement}")

if measurement is not None:  # If a measurement exists
    self.message += "This message appears in email alerts and notes.\n"

    if measurement < 88:  # If the measurement is less than 80
        self.message += f"Humidity is too Low! Measurement is {measurement}\n"
        self.run_action("0d2f939e", message=self.message)  # Run actions sequentially

    elif measurement > 90:  # Else If the measurement is greater than 27
        self.message += f"Humidity is too High! Measurement is {measurement}\n"
        self.run_action("59a1103a", message=self.message)  # Run a single specific Action

I went to have a look at the rest and wondering if this may be causing the problem:
I have inputs tracking those outputs (Raspberry Pi GPIO state). But according to my understanding that only measures the state and does not have an impact on set up of the pin.
Have deactived those inputs for now to see what impact it has, but I do like using them for the graphical interface.

GPIO state input
Conditional controller - output

@kizniche
Copy link
Owner

kizniche commented Dec 5, 2022

You are not describing your setup correctly. You are using a Measurement Condition, not the Output State Condition. This is why you are having an issue. There is also no reason to have a GPIO State Input in use. This is the reason for the output not working.

You cannot use both a GPIO Output and a GPIO Input, i.e. a GPIO cannot simultaneously be set as an input and output.

Delete the GPIO Input. Delete the Measurement Condition. Add an Output State Condition to the Conditional Function.

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

No branches or pull requests

2 participants