Python Forum
my function is stuck on loop - even when it not supposed to be
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
my function is stuck on loop - even when it not supposed to be
#1
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)
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 up
I replace the resistor\cables - the same resualt .
want to make sure the problem is not in the code

Thanks ,
Reply
#2
I'm not an Rpi expert, but since no one else has answered, I'll take a stab at it:

I don't see a loop that you might be stuck in. Am I missing something there?

I see you have a debug log enabled, is that working? Can you see the log?

Can you run this with the debugging serial console enabled? What does that show?
Reply
#3
Thanks you for trying to help -
How to run it with debugging serial console enabled?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Sad I'm stuck with the reinforcement learning function in my Code OskiLori 2 1,554 May-20-2023, 10:01 PM
Last Post: OskiLori
  Python class doesn't invoke setter during __init__, not sure if's not supposed to? mtldvl 2 3,323 Dec-30-2021, 04:01 PM
Last Post: mtldvl
  Exit Function - loop Tetsuo30 2 2,053 Sep-17-2020, 09:58 AM
Last Post: Tetsuo30
  a complicated randomized function which I'm stuck on jojo77m 11 3,540 Aug-27-2020, 09:24 AM
Last Post: DPaul
  Supposed to print out even numbers DallasPCMan 4 1,949 May-21-2020, 05:50 PM
Last Post: ndc85430
  Using Function in a For loop vp1989 5 2,796 May-19-2020, 03:53 PM
Last Post: vp1989
  while with try and except gets stuck in an endless loop? pcarra 3 4,630 Mar-27-2019, 07:50 PM
Last Post: pcarra
  while loop issue - stuck in the loop! EricMichel 6 8,595 Aug-06-2018, 03:59 PM
Last Post: EricMichel
  How to test a function that is supposed to return NoneType? w0mb4rt 1 3,473 Feb-17-2018, 07:38 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020