Example #1
0
def main():
    sonic.init_sensors(GPIO_TRIG, GPIO_ECHO)

    plugStatus = False
    onCount = 0
    offCount = 0
    while True:
        distance = sonic.get_distance(GPIO_TRIG, GPIO_ECHO)
        if distance < DIS_THRESH:
            print('distance < DIS_THRESH')
            offCount = 0
            onCount = onCount + 1
            if onCount >= ON_COUNT and plugStatus == False:
                #Plug ON
                onCount = 0
                plugStatus = True
                plug.control('192.168.0.106', 'on')
#                jt.jtalk('いらっしゃい')
        else:
            print('distance >= DIS_THRESH')
            onCount = 0
            offCount = offCount + 1
            if offCount >= OFF_COUNT and plugStatus == True:
                #Plug OFF
                offCount = 0
                plugStatus = False
                plug.control('192.168.0.106', 'off')


#                jt.jtalk('またね')

#        print('距離:{0} cm'.format(sonic.get_distance(GPIO_TRIG, GPIO_ECHO)))
        print('距離:{0} cm'.format(distance))
        print('onCount:{0}, offCount:{1}, plugStatus:{2}'.format(
            onCount, offCount, plugStatus))
        time.sleep(2)  #2sec wait
def PowerOnEntryValue(event):
    #PowerON
    plug.control('172.41.195.22', 'on')
def PowerOffEntryValue(event):
    #PowerOFF
    plug.control('172.41.195.22', 'off')
Example #4
0
import RPi.GPIO as GPIO
import tplink_smartplug_py3 as plug

GPIO.setmode(GPIO.BCM)
GPIO.setup(20, GPIO.IN)
GPIO.setup(21, GPIO.OUT)

while True:
    if GPIO.input(20) == GPIO.HIGH:
        GPIO.output(21, GPIO.HIGH)
        plug.control('172.41.195.22', 'on')
#        plug.control('172.41.195.22', 'off')
    else:
        GPIO.output(21, GPIO.LOW)
import tplink_smartplug_py3 as plug
plug.control('192.168.0.106', 'off')