eternalfroast
Posts: 11
Joined: Sun Feb 07, 2016 5:12 pm

Turning on/off motion sensor through android

Tue Mar 22, 2016 4:53 am

here is the basic of the code

if motionVallue == 3 when on is pressed in android 3 comes as value in python
then it search for the input from the motion sensor
infinite loop

if motionValue == 2
stop the motion sensor


This is not working. i can turn on the motion sensor. then the loop continues. and it never accepts motionValue == 2 part. It just continue the motion.. I did try using break. Then it stop sensing. Any ideas on how to make the motionValue == 2 work..The loop should be continuous and when press off button it should off the motion sensor and if on the motion sensor should be on without the programming terminating.

User avatar
Laurens-wuyts
Posts: 716
Joined: Wed Aug 21, 2013 7:35 pm
Location: Belgium
Contact: Website

Re: Turning on/off motion sensor through android

Tue Mar 22, 2016 5:14 am

I think you should try something like this:

Code: Select all

infinite loop {
    if motionVallue == 3 when on is pressed in android 3 comes as value in python
    then it search for the input from the motion sensor

    if motionValue == 2
    stop the motion sensor
}
Laurens

mysen
Posts: 13
Joined: Sun Feb 21, 2016 11:49 pm

Re: Turning on/off motion sensor through android

Tue Mar 22, 2016 10:55 pm

in python it's this...

and by the way, i looked EVERYWHERE on the internet for this code but i had to work it out myself through alot of pain and frustration. consider this an internet exclusive haha!

Code: Select all

import subprocess
subprocess.call("sudo -u root service motion start/stop", shell=true)
also go to /etc/init.d find the service and set permissions that work. i suggest 755 but it depends on your situation because of security.

Code: Select all

sudo chmod 755 motion

Return to “Python”