In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how raspberry pie uses Python to implement the yeelink platform. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
First, register on the yeelink platform and get your own APIKEY.
Create the device and the sensor on the device and read the apiurl of the sensor.
Example 1: upload raspberry pie temperature data to yeelink-> yeelink_temp.py
#! / usr/bin/env python#-*-coding: utf-8-*-import requestsimport jsonimport timedef main (): fileRecord = open ("result.txt", "w") fileRecord.write ("connect to yeelink\ n") FileRecord.close () while True: # Open the file file = open ("/ sys/class/thermal/thermal_zone0/temp") # read the result And convert to floating-point number temp = float (file.read ()) / 1000 # close the file file.close () # device URI, view your own sensor apiurl at the created temperature sensor and replace the path apiurl = 'http://api.yeelink.net/v1.0/device/2342/sensor/2555/datapoints' # user password below Specify the upload code as JSON format apiheaders = {'UmurApiKeyweights:' f07f2b260a6635uplob4a3auplo5codes, 'content-type':' application/json'} # dictionary type data During the post process, the request r = requests.post (apiurl, headers=apiheaders, data=json.dumps (payload)) # is converted by json.dumps to the JSON format string {"value": 48.123} payload = {'value': temp} # to print the result fileRecord = open ("result.txt") to the console. "a") strTime = time.strftime ('% Ymuri% MMI% dGV% HMI% MMI% S' Time.localtime (time.time ()) fileRecord.writelines (strTime + "\ n") strTemp = "temp:% .1F"% temp + "\ n" fileRecord.writelines (strTemp) fileRecord.writelines (str (r.status_code) + "\ n") fileRecord.close () time.sleep (2x60) if _ name__ = ='_ main__': main ()
Example 2:yeelink creates switch control led-> yeelink_led_ctl.py
#! / usr/bin/env python #-*-coding: utf-8-*-import requests import time import driver_gpio_led# device URI Check your own sensor apiurl at the created temperature sensor to replace the following path apiurl = 'http://api.yeelink.net/v1.0/device/2332/sensor/2578/datapoints' # user password apiheaders = {' Umura ApiKeyweights: 'f07f2b260a6635roomb4a3aroom5'} led = driver_gpio_led.gpio_led (7) while True: # send request r = requests.get (apiurl Headers=apiheaders) # print response # print (r.text) # convert to dictionary type Please note that version 2.7.4 uses r.json () led_state = r.json () # {'value':x} xroom1 open status Xfolo off status if led_state ['value'] = = 1: print ("led on") led.gpio_high () else: print ("led off") led.gpio_low () # delay 5S time.sleep (5) led.clean () Thank you for reading! This is the end of the article on "how to use Python to implement the yeelink platform for raspberry pie". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.