|
发表于 2014-9-28 18:00:30
|
显示全部楼层
lilei105 发表于 2014-9-28 17:58
前天收到的,谢谢菜哥。想把上次做的用电池当电源的yeelink控制电灯改成这个,但是手上没烙铁,先写了几行 ...
python代码很简单,先要安装requests库,然后就这么点:- import requests
- import RPi.GPIO as GPIO
- import time
- apiurl = "http://api.yeelink.net/v1.1/device/xxxxx/sensor/xxxxx/datapoints"
- apikey = "xxxxx"
- apiheaders = {'U-ApiKey': apikey}
- pin = 15
- ############################## Main ##############################
- GPIO.setwarnings(False)
- GPIO.setmode(GPIO.BOARD)
- GPIO.setup(pin, GPIO.OUT, initial = 1)
- while True:
- r = requests.get(apiurl, headers=apiheaders)
- value = r.json()['value']
- print(value)
- if (value == 1):
- GPIO.output(pin, 0)
- else:
- GPIO.output(pin, 1)
- time.sleep(1)
复制代码 |
|