Raspberry Pi B + timing to IoT Yeelink uploading CPU GPU temperature

Source: Internet
Author: User

Raspberry Pi B + timing to IoT Yeelink uploading CPU GPU temperature

Hardware platform: Raspberry Pi B +

Software platform:

1 Installing the Requests Library

First we have to solve the requests library, when we send to Yeelink POST message will use: R = Requests.post (Apiurl, Headers=apiheaders, Data=json.dumps (payload))

Install Easy_install:

  <span style= "LINE-HEIGHT:1.6EM; font-family:arial; " >wget </span><a target=_blank href= "http://peak.telecommunity.com/dist/ez_setup.py" >http:// Peak.telecommunity.com/dist/ez_setup.py</a><span style= "LINE-HEIGHT:1.6EM; font-family:arial; " > </span>
<span style= "LINE-HEIGHT:1.6EM; font-family:arial; " >    <span style= "LINE-HEIGHT:1.6EM; font-family:arial;" >python ez_setup.py</span></span>
<span style= "LINE-HEIGHT:1.6EM; font-family:arial; " ><span style= "LINE-HEIGHT:1.6EM; font-family:arial; " >    <span style= "Font-family:courier New;" >easy_install requests</span></span></span>

After the installation is running Python, if not the error, it means the installation is successful

    Python    Import Requests

2 Apply for Yeelink account and add device

Yeelink, a Chinese start-up company, is also using wireless networks, open source hardware and software, and of course smartphones and apps to do this.

The application account is simple on the official website. Detailed Documentation: http://www.yeelink.net/

The important thing is that we need to add two devices, one is CPU temperature and the other is the GPU temperature, where we want to get two important things, that is, the destination of the Write program message post

1 ' ApiKey ' view in ' My Account Settings '

2 url:http://api.yeelink.net/v1.0/device/13926/sensor/23121/datapoints

3 Writing Python source program

With the Yeelink platform, what we do is we need to upload the temperature data to Yeelink on the Raspberry Pi B +, and create a new pi_temp.py python file.

#!/usr/bin/env python#-*-coding:utf-8-*-import requestsimport jsonimport timeimport commandsdef Main (): # FileRecor    d = Open ("Result.txt", "W") # Filerecord.write ("Connect to yeelink\n"); # Filerecord.close () while True: # Open File Apiheaders = {' U-apikey ': ' A96bbccdd8f5e6e24fd3b2358d6cbc45 ', ' Co Ntent-type ': ' Application/json '} GPU = Commands.getoutput ('/opt/vc/bin/vcgencmd measure_temp '). Replace (' temp= '), "). Replace (' \ ' C ', ') GPU = float (GPU) #print (' GPU value:%.2f '% GPU) # GPU device URI APIURL_GP u = ' http://api.yeelink.net/v1.0/device/13926/sensor/23125/datapoints ' #YEELINK user password, specify upload encoding as JSON format I #apihea  DERs = {' U-apikey ': ' a96bbccdd8f5e6e24fd3b2358d6cbc45 ', ' content-type ': ' Application/json '} Payload_gpu = {' Value ': GPU} r = Requests.post (Apiurl_gpu, Headers=apiheaders, Data=json.dumps (PAYLOAD_GPU)) file = Open ("/sys/clas S/thermal/thermal_zone0/temp ") # Read results and convert to floating point CPU = FLOat (File.read ())/1000 # Close File File.close () #print (' CPU value:%.2f '% CPU) # CPU device URI A        piurl_cpu = ' http://api.yeelink.net/v1.0/device/13926/sensor/23121/datapoints ' #YEELINK user password, specify upload encoding as JSON format #apiheaders = {' U-apikey ': ' a96bbccdd8f5e6e24fd3b2358d6cbc45 ', ' content-type ': ' Application/json '} # Dictionary type data, in the post process The json.dumps is converted to the JSON format string {"Value": 48.123} payload_cpu = {' value ': CPU} #发送请求 r = Requests.post (apiur        L_CPU, Headers=apiheaders, Data=json.dumps (PAYLOAD_CPU) # Print results to console # Filerecord = open ("Result.txt", "a") # strtime = time.strftime ('%y-%m-%d:%h-%m-%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 (1*60) if __name__ = = ' __main__ ': Main ()


After writing is complete, only the interrupts are run directly

Python pi_temp.py

This step is complete after the debug is correct

4 Add script file auto_start.sh #!/bin/bash cd/home/pi/python-works/yeelink-temp python yeelink-temp.py &










Reference:

Raspberry Pi Learning notes--timed to Yeelink upload Raspberry Pi CPU temperature: http://blog.csdn.net/xukai871105/article/details/38349519

Installation and simple application of Python requests: http://www.zhidaow.com/post/python-requests-install-and-brief-introduction

Raspberry Pi + temperature sensor for indoor temperature monitoring: http://shumeipai.nxez.com/2013/10/03/raspberry-pi-temperature-sensor-monitors.html

Get the CPU and GPU temperature of the Raspberry Pi (Python): http://shumeipai.nxez.com/2014/02/20/get-raspberry-pi-cpu-and-gpu-temperature-python.html

ROS zynq Transplant (Installation easy_install): http://blog.csdn.net/xiabodan/article/details/37565261

Raspberry Pi B + timing to IoT Yeelink uploading CPU GPU temperature

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.