Please help a novice. I am trying to turn an LED on and off on my Raspberry pi. When I push my Anvil “on” button in my app, the LED on my Rpi turns on, but when I push the off button, I get the following error: I have gone over the code several times, but can’t find the problem.
anvil.server.NoServerFunctionError: No server function matching “turn_off” has been registered at [Form1, line 19](javascript:void(0))
Here is my code on Anvil:
from ._anvil_designer import Form1Template
from anvil import *
import anvil.server
class Form1(Form1Template):
def init(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Any code you write here will run when the form opens.
def button_1_click(self, **event_args):
“”“This method is called when the button is clicked”""
anvil.server.call(“turn_on”)
def button_2_click(self, **event_args):
“”“This method is called when the button is clicked”""
anvil.server.call(“turn_off”)
Here is the code on the Raspberry pi
from gpiozero import LED
from time import sleep
import anvil.server
red = LED(4)
red.on()
sleep(1)
red.off()
sleep(1)
@anvil.server.callable
def turn_on():
red.on()
sleep(1)
def turn_off():
red.off()
sleep(1)
anvil.server.connect(“W6NKWLYPBLRBXSPSFCDC44RD-DBH4NWCQGCFNQ62T”)
anvil.server.wait_forever()
Thanks for any help.
Bill