Chat freely about anything...

User avatar
By mevero
#92801 I made a program on a Raspberry Pi with Twilio sending a SMS notification when you pushed a button, it was for a lady who must use a wheelchair if she has a problem her huisbnd get an SMS. Now I made it on a ESP8266 but I have not enough knowledge, the program is/was right !! This is where you can find the article : https://www.twilio.com/blog/sms-doorbel ... hon-twilio
I must include the statements form the Twilio class as they stand in the article and not change tihings.
But now I need some info that I can add the two buttons for the different messages. I renamed the main.py into Alarm01.py and Alarm02.py.
And the new main must have when you pushed Button 1 an statement run Alarm01.py and when you pus the other button goto (run) Alarm02.py I hope you understand my question and will be able to find a solution for me. The problem with the Pi by power fail the program did not restart and ESP8266 keeps his program.

Thanks very much also from the lady I want to help. And off cores form her husband because now he knows if there is a real problem or she wants to get some attention.
User avatar
By mevero
#93089 I found somewhere on the internet a solution when you press a button a file starts. But i don't find a solution for two buttons. A file starting : exec(open('mydoorbell.py').read()). I duplicate the lines ( for one button) only one works, but there is no Error message. Do you have any idea to solve ?? This is how it is:

from machine import Pin

led = Pin(5, Pin.OUT)
but1 = Pin(4, Pin.IN, Pin.PULL_UP)
but2 = Pin(14, Pin.IN, Pin.PULL_UP)

def debounce(pin):
prev = None
for _ in range(32):
current_value = pin.value()
if prev != None and prev != current_value:
return None
prev = current_value
return prev


def but1_callback(pin):
d = debounce(pin)

if d == None:
return
elif not d:
led.value(not led.value())
print('WIT')

def but2_callback(pin):
d = debounce(pin)

if d == None:
return
elif not d:
led.value(not led.value())
print('zwart')

but1.irq(trigger=Pin.IRQ_FALLING, handler=but1_callback)
but2.irq(trigger=Pin.IRQ_FALLING, handler=but2_callback)
User avatar
By mevero
#93104 Problem solved, I think there was something wrong whit a wire may the button.
from machine import Pin

led = Pin(5, Pin.OUT)
but1 = Pin(4, Pin.IN, Pin.PULL_UP)
but2 = Pin(14, Pin.IN, Pin.PULL_UP)

def debounce(pin):
prev = None
for _ in range(32):
current_value = pin.value()
if prev != None and prev != current_value:
return None
prev = current_value
return prev


def but1_callback(pin):
d = debounce(pin)

if d == None:
return
elif not d:
led.value(not led.value())
print('WIT')

def but2_callback(pin):
d = debounce(pin)

if d == None:
return
elif not d:
led.value(not led.value())
print('zwart')

but1.irq(trigger=Pin.IRQ_FALLING, handler=but1_callback)
but2.irq(trigger=Pin.IRQ_FALLING, handler=but2_callback)

This was/is the right solution for the buttons, exec(open('door.py'(.read()) was the solution for calling a file, in my case two files whit different message. And of cause the Twilio doorbell from mister Grinberg.
Thanks for the time you spend for finding a solution.