I’m a new Blynker . … Started with Python on Raspberry 2A+. Wrote app to open garage doors. All was workin OK. Upgraded to Raspberry 3 after 2A+ shorted out. I took a few months off and now I am unable to get GPx buttons to work. Used reguests library to access Blynk before. Tried using Blynklib but still no progress. Virtual pins read OK. Terminal writes OK. But GPx buttons are inop via Blynk app. They work OK when manually set.
Where to go for help/example/code for my GPx button in python.
Was using private-anon-093dde407a-blynkapi.apiary-proxy.com as Blynk server but I get a hash error on it so now using blynk-cloud.com .
import RPi.GPIO as GPIO
import time
import datetime
import os
import requests
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(5, GPIO.IN)
GPIO.setup(6, GPIO.IN)
# these are two switches to be controlled by Blynk app.
GPIO.setup(2, GPIO.OUT) #activate left door
GPIO.setup(3, GPIO.OUT) #activate Right door
GPIO.output(2, 1) #make sure switches are open (off)
GPIO.output(3, 1)
blynktoken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
blynkprivatedomain = 'xxxxx://private-anon-093dde407a-blynkapi.apiary-proxy.com/'
blynkdomain = "xxxx://blynk-cloud.com/"
.
.
S0arg = ' -vw 0 0'
S1arg = ' -vw 1 0'
def waitforconnect():
global sleeping
while True:
response = requests.get(blynkdomain + blynktoken + "/isAppConnected")
response = response.text
if response == "true" :
lasttime = time.time()
print(time.strftime('%Y%m%d'), time.strftime('%H%M'), "App Connected")
sleeping = False
break
else:
if not sleeping:
print(time.strftime('%Y%m%d'), time.strftime('%H%M'), "sleeping ...")
sendtermmsg(" Sleeping since " + str(time.strftime('%H%M') ) )
sleeping = True
time.sleep(appsleeptime)
.
.
waitforconnect()
elapsed = 0
os.system("sudo python /home/pi/blynk/blynk_ctrl.py -t " + blynktoken + " -vw 0 0 -vw 1 0 ")
sendtermmsg("\n")
sendtermmsg("Program start")
getnotifytimes()
print("Notify times:", dooropenstart, dooropenend)
sendtermmsg("Notify: " + str(dooropenstart)[:5] + " " + str(dooropenend)[:5])
sendtermmsg("AppCycle:" + str(waittime))
sendtermmsg("AppSleep:" + str(appsleeptime))
while True:
timestamp = datetime.datetime.now().time()
if elapsed > elapsedmax:
waitforconnect()
elapsed = 0
if GPIO.input(5) == False: # door close
if door0open:
S0arg = ' -vw 0 0'
sendtermmsg("Left door closed")
door0open = False
needtoreset = True
else:
pass
else: # door open
if not door0open:
S0arg = ' -vw 0 255'
print (time.strftime('%Y%m%d'), time.strftime('%H%M'), "Door 0 open")
sendtermmsg("Left door open")
values = {"body": "Left garage door open" }
door0open = True
needtoreset = True
if GPIO.input(6) == False: # door closed
if door1open:
S1arg = ' -vw 1 0'
sendtermmsg("Right door closed")
door1open = False
needtoreset = True
else:
pass
else: # door open
if not door1open:
S1arg = ' -vw 1 255'
print (time.strftime('%Y%m%d'), time.strftime('%H%M'), "Door 1 open")
sendtermmsg("Right door open")
values = {"body": "Right garage door open" }
door1open = True
needtoreset = True
if door1open or door0open:
if doortimeroff:
dooropentime = time.time()
doortimeroff = False
else:
pass
else:
doortimeroff = True
# Send message if doors open after hours
if (door0open or door1open ) and time.time() - dooropentime > dooropendelay:
print(time.strftime('%Y%m%d'), time.strftime('%H%M'), "Door open in notify range")
rrequest = requests.post('xxxxs://' + blynkprivatedomain + '/' + blynktoken + '/notify', json=values)
preq = (rrequest.text)
if len(preq) > 0 :
print (time.strftime('%Y%m%d'), time.strftime('%H%M'), "Error sending Notify: ", preq)
dooropentime = time.time()
if needtoreset:
os.system("sudo python /home/pi/blynk/blynk_ctrl.py -t " + blynktoken + " " + S0arg + S1arg)
delaycount = 0
needtoreset = False
time.sleep(waittime)
elapsed = time.time() - lasttime
print("finished")