May-22-2019, 02:26 PM
hello ,
can someone explain why my code is stuck on loop?
even if I don't press the button it run the button_callback function (like I press the button)
I use the configuration from here (very simple one)
want to make sure the problem is not in the code
Thanks ,
can someone explain why my code is stuck on loop?
even if I don't press the button it run the button_callback function (like I press the button)
I use the configuration from here (very simple one)
https://raspberrypihq.com/use-a-push-button-with-raspberry-pi-gpio/and this is the code :
from twilio.rest import Client
import socket #Import udp
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
import json # import json read\write
import time
import logging
def button_callback(channel):
print("Button was pushed!")
CurrentTime = str(time.ctime())
MESSAGE = (CurrentTime + " Test")
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE.encode(), (UDP_IP, UDP_PORT))
print (MESSAGE)
whatsupp()
logging.basicConfig(filename='/home/pi/Desktop/message.log',level=logging.DEBUG)
logging.debug(MESSAGE)
time.sleep(1)
def whatsupp():
account_sid = "********"
auth_token = "********"
client = Client(account_sid, auth_token)
message = client.messages.create(
to="whatsapp:+12346578912329",
from_="whatsapp:+14155299999",
body="test")
print(message.sid)
UDP_IP = "10.0.0.51"
UDP_PORT = 9051
GPIO.setwarnings(False) # Ignore warning for now
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # pin 10 to be an input pin and set initial value to be pulled low (off)
GPIO.add_event_detect(10,GPIO.RISING,callback=button_callback) # Setup event on pin 10 rising edge
message = input("Press enter to quit\n\n") # Run until someone presses enter
GPIO.cleanup() # Clean upI replace the resistor\cables - the same resualt .want to make sure the problem is not in the code
Thanks ,
