查看树莓派的版本

树莓派现在已经出到4了,手上也有几个不同的版本,有时候要查看一下版本,新的raspbian支持直接查看了,执行命令为:

cat /proc/device-tree/model

输出结果如下(型号不同结果也有不同),如:

Raspberry Pi 2 Model B Rev 1.1

旧的系统版本则需要通过查看/proc/cpuinfo中的Revision的值来判断。

DHT22温湿度传感器的使用

使用python读取dht22温湿度传感器的值。

 import sys
 import Adafruit_DHT
 import requests
 import json
 url = 'https://www.3gcomet.com/iot/iot_receive.php'
 sensor = Adafruit_DHT.DHT22
 pin = 4
 humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
 if humidity is not None and temperature is not None:
     temp = '{:.1f}'.format(temperature)
     humi = '{:.1f}'.format(humidity)
     payload = {"ac":'iotofict',"loc":'CloudDC',"tem":temp,"hum":humi}
     response = requests.post(url=url,data=payload)
     print(response.text)
     #print('Temp={0:0.1f}*  Humidity={1:0.1f}%'.format(temperature, humidity))
 else:
     print('Failed to get reading. Try again!')
     sys.exit(1)