内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

怎么用樹莓派搭建傳感器物聯(lián)網(wǎng)應用

這篇文章將為大家詳細講解有關怎么用樹莓派搭建傳感器物聯(lián)網(wǎng)應用,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

創(chuàng)新互聯(lián)公司專注于正定企業(yè)網(wǎng)站建設,響應式網(wǎng)站開發(fā),電子商務商城網(wǎng)站建設。正定網(wǎng)站建設公司,為正定等地區(qū)提供建站服務。全流程按需定制網(wǎng)站,專業(yè)設計,全程項目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務

1. 掛載DS18B20

sudo modprobe w1-gpio
sudo modprobe w1-therm

2. 安裝Python的庫單總線溫度計訪問庫: w1thermsensor

pip install w1thermsensor

3. 新建一個iot.py文件敲入以下代碼

#!/usr/bin/env python
#coding=utf8

import httplib, urllib

from w1thermsensor import W1ThermSensor
import time
import socket, serial, time
import httplib
import json

HOST = "open.lewei50.com"

PORT = 80
 

user_key = '樂為物聯(lián)的userkey'

def send_data_to_yeelink(temp):

		httpClient = None
		try:
			params = json.dumps({'value': temp})
			headers = {"Content-type": "application/json"
                    , "Accept": "text/plain",'U-ApiKey': 'Yeelink的api key'}
 
			print params
			httpClient = httplib.HTTPConnection('api.yeelink.net', 80, timeout=30)
			httpClient.request("POST", "/v1.1/device/設備id/sensor/傳感器id/datapoints", params, headers)
 
			response = httpClient.getresponse()
			print response.status
			print response.reason
			print response.read()
			print response.getheaders() #獲取頭信息
		except Exception, e:
			print e
		finally:
			if httpClient:
				httpClient.close()
 

def send_data(temp):

		httpClient = None
		try:
			params = json.dumps([{'Name': '傳感器名稱', 'Value': temp}])
			headers = {"Content-type": "application/x-www-form-urlencoded"
                    , "Accept": "text/plain","userkey":user_key}
 
			print params
			httpClient = httplib.HTTPConnection(HOST, 80, timeout=30)
			httpClient.request("POST", "/api/V1/Gateway/UpdateSensors/01", params, headers)
 
			response = httpClient.getresponse()
			print response.status
			print response.reason
			print response.read()
			print response.getheaders() #獲取頭信息
		except Exception, e:
			print e
		finally:
			if httpClient:
				httpClient.close()
while True:
	for sensor in W1ThermSensor.get_available_sensors([W1ThermSensor.THERM_SENSOR_DS18B20]):
		temp=sensor.get_temperature()
		print("Sensor %s has temperature %.2f" % (sensor.id,temp ))
		send_data(temp)
		send_data_to_yeelink(temp)
	time.sleep(120)

4. 運行python腳本

python iot.py

5. 如果溫度讀取成功且上傳成功會打印相關消息.

關于“怎么用樹莓派搭建傳感器物聯(lián)網(wǎng)應用”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

網(wǎng)頁名稱:怎么用樹莓派搭建傳感器物聯(lián)網(wǎng)應用
網(wǎng)址分享:http://m.rwnh.cn/article22/pcohjc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供面包屑導航、搜索引擎優(yōu)化、商城網(wǎng)站、外貿建站、品牌網(wǎng)站制作、虛擬主機

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

h5響應式網(wǎng)站建設
双辽市| 潍坊市| 威远县| 庆阳市| 马山县| 黑龙江省| 武乡县| 疏附县| 晋中市| 米林县| 奉化市| 弋阳县| 玛多县| 通化市| 纳雍县| 泾阳县| 余江县| 余干县| 肥城市| 南京市| 镇平县| 芒康县| 绥德县| 镇雄县| 安义县| 墨玉县| 博客| 巴东县| 张北县| 垦利县| 安远县| 陇川县| 贵州省| 蒙城县| 定襄县| 电白县| 罗源县| 界首市| 淮安市| 灵武市| 海林市|