In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use raspberry pie to build sensor Internet of things applications. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
1. Mount DS18B20
Sudo modprobe w1-gpiosudo modprobe w1-therm
two。 Install Python library 1-wire thermometer access library: w1thermsensor
Pip install w1thermsensor
3. Create a new iot.py file and type in the following code
#! / usr/bin/env python#coding=utf8import httplib, urllibfrom w1thermsensor import W1ThermSensorimport timeimport socket, serial Timeimport httplibimport jsonHOST = "open.lewei50.com" PORT = 80 user_key = 'userkey'def send_data_to_yeelink (temp): httpClient = None try: params = json.dumps ({' value': temp}) headers = {"Content-type": "application/json" "Accept": "text/plain", 'Umura print params httpClient:' api key' of Yeelink} print params httpClient = httplib.HTTPConnection ('api.yeelink.net', 80, timeout=30) httpClient.request ("POST", "/ v1.1/device/ device id/sensor/ sensor id/datapoints", params Headers) response = httpClient.getresponse () print response.status print response.reason print response.read () print response.getheaders () # get header information except Exception E: print e finally: if httpClient: httpClient.close () def send_data (temp): httpClient = None try: params = json.dumps ([{'Name':' sensor name' ) 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 () # get header information 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
4. Run the python script
Python iot.py
5. If the temperature is read successfully and uploaded successfully, the relevant message will be printed.
This is the end of the article on "how to use raspberry pie to build sensor Internet of things applications". I hope the above content can be helpful to you, so that you can learn more knowledge. If you think the article is good, please 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.