just copy and paste here. i cannot access your link.
#!/usr/bin/env python
from picamera import PiCamera
from time import sleep
import RPi.GPIO as GPIO
import datetime
camera = PiCamera()
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN) #PIR
camera.rotation =180 # flip the pic
import cayenne.client
import time
x = 0
# Cayenne authentication info. This should be obtained from the Cayenne Dashboa$
# Cayenne authentication info. This should be obtained from the Cayenne Dashboa$
#MQTT_USERNAME = ""
#MQTT_PASSWORD = ""
#MQTT_CLIENT_ID = ""
# The callback for when a message is received from Cayenne.
def on_message(message):
global x
print("message received: " + str(message))
# If there is an error processing the message return an error string, other$
if (message.channel == 4) and (message.value == "1"):
print("button is pressed")
x = 1
if (message.channel == 5) and (message.value == "1"):
print("quit button is pressed")
quit()
client = cayenne.client.CayenneMQTTClient()
client.on_message = on_message
indent preformatted text by 4 spaces
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID, port=8883)
i=0
timestamp = 0
motion = False
motioncounter = 0
while True:
client.loop()
if motion:
motioncounter += 1
if (not motion) or (motioncounter > 50):
if motioncounter > 50:
motioncounter = 0
if GPIO.input(18):
print(āMotion Detectedā¦ā)
dt = datetime.datetime.now()
fn = ā{:/home/pi/mqtt/examples/pic/%Y%m%dT%H%M%S.jpg}ā.format(dt)
client.virtualWrite(2,1,ādigital_sensorā,ādā)
camera.start_preview()
#time.sleep(5) ####If you really do need a delay here make it less $
camera.capture(fn)
camera.capture(ā/home/pi/Desktop/image.jpgā)
camera.stop_preview()
motion = True
motioncounter = 0
else:
if (time.time() > timestamp + 10):
print("making two state zero")
client.virtualWrite(2,0,"digital_sensor","d")
timestamp = time.time()
motion = False
time.sleep(0.1)
indent preformatted text by 4 spaces
this is because the button channel is 5 and when channel 5 becomes 1 it runs:
which shutdown the raspberry pi.
when adding a button select channel as 6.
Yes,that is correct, but I added a new widget on channel 7 with a trigger that should send an email.
When I press this widget, the pi keep running, but no email is sent, and the trigger run 0 times
sir,Would you mind sharing you account with me ? You can PM me your login and password and change your password here if you need. https://cayenne.mydevices.com/cayenne/forgot
It is Devise 2346
Now the triggers are working for motion and button.
Very good.Then I can start my project.
Now it is time to test if also sms is working.
ā¦
Yes it is working ā¦yipppi
once done, share the project with community.