#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import RPi.GPIO as GPIO
import time
# 设备URI
apiurl = "
http://api.yeelink.net"#你的api地址
# 用户密码
apiheaders = {*U-ApiKey*: "e2064e01d60ccaadee5a82xxxxxxxx"} #你的密钥
while True:
#发送请求
r = requests.get(apiurl,headers=apiheaders)
# 打印响应内容
print(r.text)
# 转换为字典类型 请注意 2.7.4版本使用r.json()
led = r.json()
# {*value*:x} x=1打开状态,x=0关闭状态
if led[*value*] == 1:
print("led on")
bus.write_byte( 0x20 , 1 )
else:
print("led off")
bus.write_byte( 0x20 , 0 )
# 延时5S
time.sleep(5)