将采集数据通过TCP协议传输到服务器/局域网(14)
将上一章节的大气压强+温度信息上传至服务器
首先,在服务器运行网络调试助手
有很多免费的网络调试助手可用
将如下代码记录为xxx.py文件
#!/usr/bin/python
#-*-coding:utf-8-*-
import socket
import time
from BMP180 import BMP180
# Initialise the BMP085 and use STANDARD mode (default value)
# bmp = BMP085(0x77, debug=True)
bmp = BMP180()
# To specify a different operating mode, uncomment one of the following:
# bmp = BMP085(0x77, 0) # ULTRALOWPOWER Mode
# bmp = BMP085(0x77, 1) # STANDARD Mode
# bmp = BMP085(0x77, 2) # HIRES Mode
# bmp = BMP085(0x77, 3) # ULTRAHIRES Mode
HOST = '121.40.69.30'
PORT = 4000
Flag = True
while True:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # 定义socket类型,网络通信,TCP
s.connect((HOST, PORT)) # 要连接的IP与端口
# s.connect(('127.0.0.1', 6666)) #服务器和客户端都在一个系统下时使用的ip和端口
Flag = True
except socket.error as msg:
print(msg)
s.close() # 关闭连接
Flag = False
while Flag:
try:
temp = bmp.read_temperature()
# Read the current barometric pressure level
pressure = bmp.read_pressure()
# To calculate altitude based on an estimated mean sea level pressure
# (1013.25 hPa) call the function as follows, but this won't be very accurate
altitude = bmp.read_altitude()
# To specify a more accurate altitude, enter the correct mean sea level
# pressure level. For example, if the current pressure level is 1023.50 hPa
# enter 102350 since we include two decimal places in the integer value
# altitude = bmp.readAltitude(102350)
print "Temperature: %.2f C" % temp
print "Pressure: %.2f hPa" % (pressure / 100.0)
#print "Altitude: %.2f\n" % altitude
s.sendall("Temperature: %.2f C\r\n" % temp ) # 发送数据
time.sleep(1) # 休眠3秒
s.sendall("Pressure: %.2f hPa\r\n" % (pressure / 100.0)) # 发送数据
time.sleep(1) # 休眠3秒
except socket.error as msg:
print(msg)
s.close() # 关闭连接
Flag = False
直接运行该文件即可 在本地打印出温度和大气压强相关的信息 同时将采集到的数据上传到相应的IP
本地运行:
pi@raspberrypi:~/Desktop $ python BMP180_test.py
Temperature: 19.00 C
Pressure: 1027.91 hPa
Temperature: 19.00 C
Pressure: 1027.88 hPa
Temperature: 19.00 C
Pressure: 1027.98 hPa
服务器接受数据如下:
按照如上操作 即可实现简单的数据上传功能
但是实际的项目应用肯定是考虑的更加全面 功能也不仅如此 后续看看能不能将采集的数据进行本地存储
如果想添加开机自启动 参考
树莓派 添加一个开机自启动的程序 (7)
http://www.muwenyidao.com/default.aspx?type=post&name=55
相关文章
评论列表(1675) 订阅
禁止评论
虽然不知道说的是什么,但看起来好厉害的样子!
http://www.curry4cheap.com/cheap-athletic-nike-lebron-16-cheap-new-lebrons-midnight-navyuniversity-blue-p-1623.html - Cheap Nike LeBron 16 For Sale
Read More
Cobie Smulders
Www Cytotec Jenerik Priligy Cialis Super Actif Plus <a href=http://bakgol.com>achat viagra pfizer ligne</a> buy accutane no rx Acheter Viagra
Combivent Sale Cialis Professional <a href=http://viaacost.com>viagra</a> Levitra 20mg Prices Lisinopril Mail Order
Levitra Generico In Contrassegno Generic Hydrochlorothiazide Kidney Disease Medicine Low Price Shop <a href=http://etrobax.com>buy cialis</a> Prednisolone Wi
Viagra En Pharmacie Tunisie Priligy Forum Al Femminile <a href=http://ciali5mg.com>canadian pharmacy cialis 20mg</a> Rx Dth 24 B Kamal Kunj Mu
You Might Also Like
http://www.eztook.com - Cheap Nike KD 11 Gym Red
Now Mel is getting restless, taping more newspaper clippings&n
Cialis Sevilla Clomid Avec Internet Best Sildenafil Pills For Sex <a href=http://cheapvia25mg.com>viagra online</a> Acquisto Viagra Slovenia Apri Amoxil
Acticin Elimite Drugs On Line Cialis Prezzo Migliore Keflex For Sinus Infections <a href=http://boijoy.com>commander levitra</a> Priligy In Canada
Online Pharmacy Overnight Delivery <a href=http://cpsmeds.com>cialis tablets for sale</a> Cialis France Pharmacie En Ligne Dosage Dog Uti Keflex Al
Amoxicilline Cialis Mexico <a href=http://gnplls.com>comprar levitra generico en andorra</a> Lioresal Generique En Canada Real Levaquin Ups With Free&nb
Clomid Dianabol Amoxicillin On Line Doctors Cialis Euroclinix <a href=http://cpsmeds.com>where to buy cialis online safely</a> Propecia Engorda Receta&n
Chantix Uses Vardenafil Lioresal Generique 25mg <a href=http://asacdz.com>tadalafil cialis from india</a> Amoxicillin And Urine Cialis 5 Mg Price W
Viagra Apres Manger Viagra Para Hombres <a href=http://brandcial.com>generic cialis overnight delivery</a> Viagra Anonym Bestellen Propecia Nebenwirkungen Le
Cs Online Support24 Prostata Finasteride Propecia <a href=http://tadalaf20mg.com>cialis from canada</a> Sale Isotretinoin Roacutan Website Cheapeast
Levitra Cialis Comparison Cialis Mal Di Gambe <a href=http://orderlevi.com>generic levitra 40 mg no prescription</a> Canadian Drugstore Online
Priligy 60 <a href=http://buycial.com>cheapest cialis 20mg</a> How Do You Take Zithromax Real Propecia Results Male Pattern Baldness
Viagra Professional 200 Canada Pharmacy For Sale Stendra On Line Online Medication For Gonorrhea <a href=http://viacheap.com>viagra online</a> Buy
“What is the best part about being Jerry Seinfeld?”
Apple Byte
http://www.okcillini.com/nike-lebron-16-whitemulticolor-outlet-p-5188.html - Nike LeBron 16&n
Cortar Propecia Water Pills No Prescription Mexico <a href=http://allngos.com></a> Cialis Generique Brevet Venta Kamagra Farmacia Sicher Viagra Kaufen&n
Cialis Es Para Mujeres Woher Kriege Ich Levitra Costo Di Priligy <a href=http://brandciali.com>cialis 5 mg best price usa</a> Cytoxan
Vendite Kamagra In Spagna Outdated Amoxicillin <a href=http://genericcial.com>п»їcialis</a> Cialis Acheter Online
Buy Valtrex In Thailand Progesterone Price Isotretinoin mastercard accepted with free shipping store <a href=http://bpdrugs.com>canadian cialis</a> Prednison
Buy Cheap Nexium <a href=http://adrugo.com>generic cialis overnight delivery</a> Viagra Mente Best Site Buy Viagra Online 133 Cialis Dosaggio Consi
Lithium Carbonate No Prescription <a href=http://sildenaf100mg.com>viagra prescription</a> Cheapest Lasix Amoxicillin And Sushi
Miglior Viagra Naturale Prix Cialis En Pharmacie France <a href=http://drugsed.com></a> Kamagra Oral Jelly Legal In Deutschland
Hello there! <a href=http://propeciabuyonlinenm.com/#order-generic-propecia>buy non generic propecia</a> excellent site.
Propecia Prix 2015 <a href=http://viaonlineusa.com>viagra</a> No Prescription Diflucan Viagra Free Trial Pack
Hello there! <a href=http://propeciabuyonlinenm.com/#where-to-buy-propecia-in-usa>best place to order propecia</a> excellent site.
Hello there! <a href=http://propeciabuyonlinenm.com/#buy-propecia-in-south-africa>buy propecia online prescription</a> very good internet site.
Hi there! <a href=http://propeciabuyonlinenm.com/#buy-propecia-china>buy propecia generic</a> great website.
Cheap Discount Tadalis Sx <a href=http://viaapill.com>online pharmacy</a> Generic Viagra 20 Mg Baisse Prix Kamagra
Venta Cialis Marca <a href=http://cialionline.com>cialis cheapest online prices</a> Cialis 5 Vademecum Cialis Generique Forum
Hello there! <a href=http://canadianonlinepharmacymlp.com/#online>modafinil online pharmacy</a> very good web site.
Hi! <a href=http://canadianonlinepharmacymlp.com/#online>xanax online pharmacy overnight</a> beneficial internet site.
Kamagra Internet <a href=http://corzide.com>viagra</a> Venta De Propecia
Canadian Rx Stendra Avanafil Shipped Ups <a href=http://66pills.com>viagra</a> Cialis 10 O 20 Mg Precios
Hi! <a href=http://canadianonlinepharmacymlp.com/#cialis>online pharmacy no prescription canada</a> excellent web page.
Hi there! <a href=http://canadianonlinepharmacymlp.com/#online>online pharmacy viagra generic</a> great web page.
Howdy! <a href=http://cilaisppl.com/#buy-cialis-usa>where buy cialis</a> good site.
Hi! <a href=http://onlineuspharmacies.party/#where-buy-viagra>fioricet online pharmacy</a> beneficial internet site.
Como Comprar Cialis Online Buy Bactrim Online Overnight Delivery <a href=http://brandcial.com>cialis 40 mg</a> No Rx Cephalexin Propecia Shed Hair&
Hello there! <a href=http://cilaisppl.com/#purchase-cialis-online-no-prescription>buy tadalafil</a> good web page.
Hi there! <a href=http://onlineuspharmacies.party/#buy-generic-viagra>pharmacies online</a> good internet site.
Does Amoxicillin Kill Staph <a href=http://cialcheap.com>buy cialis</a> Pfizer Viagra 100mg Coupon Comprar Kamagra Online
Propecia Website Pharmacy Prevacid Buy One Get One Free <a href=http://corzide.com>viagra</a> Zentel 400mg Cheapeast No Physician Approval
Prednisolone Without Prescription Compra Cialis Barcelona <a href=http://curerxshop.com>buy generic cialis online</a> Fluoxetine Discount Cheapeast Cialis Generic
Achat Viagra Pharmacie En Orleans Vente Nolvadex <a href=http://orderciali.com>cialis 5 mg</a> Keflex Dosage For Dental Abscess Viagra Cialis Gunst
Hi! <a href=http://cilaisppl.com/#tadalafil>buy cialis online</a> excellent website.
Hi there! <a href=http://onlineuspharmacies.party/#buy-viagra-no-prescription>costco online pharmacy prices</a> excellent web page.