Raspberry Pi B + regularly uploads CPU GPU temperature to IOT yeelink, raspberryyeelink

Source: Internet
Author: User

Raspberry Pi B + regularly uploads CPU GPU temperature to IOT yeelink, raspberryyeelink
Zookeeper Raspberry Pi B + regularly uploads CPU GPU temperature to IOT yeelink

Hardware Platform: Raspberry Pi B +

Software Platform: Raspberry

For system and preliminary installation, see:Raspberry Pi (Rospberry Pi B +) Arrival test: http://blog.csdn.net/xiabodan/article/details/38984617#0-qzone-1-66514-d020d2d2a4e8d1a374a433f596ad1440 

More follow http://blog.csdn.net/xiabodan

1. Install the requests Library

First, we need to solve the requests library. When we send a message to YEELINK, we will use: r = requests. POST (apiurl, headers = apiheaders, data = json. dumps (payload ))

Install easy_install:

Wget http://peak.telecommunity.com/dist/ez_setup.py

Python ez_setup.py

Easy_install requests

After the installation is complete, run python. If no error is reported, the installation is successful.

python
    import requests
2 Apply for YEELINK account and add device
A Chinese startup Yeelink, an Internet of Things platform, is also using wireless networks, open source hardware and software, and of course smartphones and apps to do this.

Applying for an account is simple. On the official website, a detailed instruction document is available: http://www.yeelink.net/

The important thing is that we need to add two devices, one is the CPU temperature and the other is the GPU temperature, here we want to get two important things, that is, the destination of the program message POST (self application)

1 'ApiKey' View in "My Account Settings"

2 URL: http://api.yeelink.net/v1.0/device/13926/sensor/23121/datapoints (apply for yourself)


3 Write Python source program
With the YEELINK platform, our job is to transfer the temperature data to YEELINK regularly on the Raspberry Pi B + and create a new pi_temp.py python file

#! / usr / bin / env python
#-*-coding: utf-8-*-
import requests
import json
import time
import commands

def main ():
    # fileRecord = open ("result.txt", "w")
    # fileRecord.write ("connect to yeelink \ n");
    # fileRecord.close ()
    while True:
        # open a file

        apiheaders = {'U-ApiKey': 'a96bbccdd8f5e6e24fd3b2358d6cbc45', 'content-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_gpu = 'http://api.yeelink.net/v1.0/device/13926/sensor/23125/datapoints'
        #YEELINK User password, specify upload encoding as JSON format i
        #apiheaders = {'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 / class / thermal / thermal_zone0 / temp")
        # Read the result and convert to floating point
        cpu = float (file.read ()) / 1000
        # Close the file
        file.close ()
        #print ('cpu value:%. 2f'% cpu)
        # CPU device URI
        apiurl_cpu = 'http://api.yeelink.net/v1.0/device/13926/sensor/23121/datapoints'
        #YEELINK User password, specify upload encoding to JSON format
        #apiheaders = {'U-ApiKey': 'a96bbccdd8f5e6e24fd3b2358d6cbc45', 'content-type': 'application / json'}
        # Dictionary type data, converted to JSON format string by json.dumps during post {"value": 48.123}
        payload_cpu = {'value': cpu}
        #send request
        r = requests.post (apiurl_cpu, headers = apiheaders, data = json.dumps (payload_cpu))

        # Print results to the 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 the writing is completed, only interrupt the direct operation
python pi_temp.py

After debugging, this step is completed

4 Add script file auto_start.sh
 Create a new auto_start.sh file, add the following content

#! / bin / bash
    cd / workplace /
    python pi_temp.py &
5 Start up and modify the /etc/rc.local file
 vim /etc/rc.local
  Add the following code:

 # Upload the temperature of the Raspberry Pi CPU to yeelink. Note that the path of the .sh file is your own path, mine is / workplace
 /workplace/auto-start.sh start
  Reboot reboot

  Check the new process just now

 ps aux | grep pi_temp.py
 

You can see that our process is 2840

The process can be closed by kill 2840

6 Refresh the YEELINK device webpage
  You can see that there is already data uploaded to the server

 
   



                        
reference:
               

      Raspberry Pi (Rospberry Pi B +) arrival pro test: http://blog.csdn.net/xiabodan/article/details/38984617#0-qzone-1-66514-d020d2d2a4e8d1a374a433f596ad1440
           Raspberry Pi study notes-regularly upload the Raspberry Pi CPU temperature to yeelink: http://blog.csdn.net/xukai871105/article/details/38349519

           Installation and simple use 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 transplantation (install easy_install): http://blog.csdn.net/xiabodan/article/details/37565261

           Understand Linux system /etc/init.d directory and /etc/rc.local script: http://blog.csdn.net/acs713/article/details/7322082

           N methods for killing processes under Linux: http://blog.csdn.net/andy572633/article/details/7211546

           Raspberry Pi Automatic login and automatic running program when plugged in 

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.