物联网:用Python传送温湿度信息到AWSIoT

 行业新闻     |      2021-07-18 08:13
本文摘要:与IoT涉及到的云端服务为数众多,比如:ThingSpeak、WoT.City、AWS、IBMBluemix、MediaTekMCS、GoogleFirebase等,并在利用这种云端服务可在对数据信息进行大数据可视化、数据统计分析与其他的运用于,而文中用Python将利用RaspberryPi搜集到的温度湿度信息传送到AWSIoT。

芭乐app最新版本下载官网

与IoT涉及到的云端服务为数众多,比如:ThingSpeak、WoT.City、AWS、IBMBluemix、MediaTekMCS、GoogleFirebase等,并在利用这种云端服务可在对数据信息进行大数据可视化、数据统计分析与其他的运用于,而文中用Python将利用RaspberryPi搜集到的温度湿度信息传送到AWSIoT。情景原材料与打算1.打算RaspberryPi3ModelB单片机开发板2.打算MicroSD(已加装Raspbian)3.将MicroSD取下到RaspberryPi中4.原著好互联网5.加装GrovePi 6.加装Grove–TemperatureandHumiditySensor(D4)7.加装GROVE-LCDRGBBACKLIGHT(I2C-2)8.加装IDE(SublimeTextorVisualStudioCode)Sensor,LCD,GrovePi 与RaspberryPi相接如下图AWSIoT尾端Step1.到AWS网址申报人账户Step2.登陆AWS网址Step3.页面ServicesAWSIoTStep4.页面CreatearesourceStep5.页面Createathing輸出thingNameCreateStep6.页面不久建立的thingStep7.页面ConnectadeviceStep8.页面Node.jsGeneratecertificateandpolicyStep9.iTunesprivate与publickeysStep10.页面ConfirmconnectingStep11.页面ReturntoThingDetailRaspberryPi尾端Step1.利用Python载入温度湿度信息并传送到AWSIoT#****************************************************#ImportPackage#****************************************************importtimeimportdatetimeimportpaho.mqtt.clientaspahoimportjsonimportsslimportsyssys.path.append(/home/pi/rpi/code/Package)importgrovepifromgrove_rgb_lcdimport*#****************************************************#SetPinNo,AWSConfig#****************************************************sensor=4blue=0#TheBluecoloredsensor.white=1#TheWhitecoloredsensor.connflag=False#****************************************************#SetAWSConnection#****************************************************defon_connect(client,userdata,flags,rc):globalconnflagconnflag=Trueprint(Connectionreturnedresult: str(rc))defon_message(client,userdata,msg):print(msg.topic str(msg.payload))mqttc=paho.Client()mqttc.on_connect=on_connectmqttc.on_message=on_messageawshost=a3iprlpgye4dmu.iot.us-west-2.amazonaws.comawsport=8883clientId=sensorDatathingName=sensorDatacaPath=./root-CA.crtcertPath=./000cd28455-certificate.pem.crtkeyPath=./000cd28455-private.pem.keymqttc.tls_set(caPath,certfile=certPath,keyfile=keyPath,cert_reqs=ssl.CERT_REQUIRED,tls_version=ssl.PROTOCOL_TLSv1_2,ciphers=None)mqttc.connect(awshost,awsport,keepalive=60)mqttc.loop_start()#****************************************************#PublishAWS#****************************************************whileTrue:[temp,humidity]=grovepi.dht(sensor,blue)print(temp=%.02fChumidity=%.02f%%%(temp,humidity))t=time.time();date=datetime.datetime.fromtimestamp(t).strftime(%Y%m%d%H%M%S)ifconnflag==True:mqttc.publish(topic/sensorData,json.dumps({time:date,temperature:temp,humidity:humidity}),qos=1)else:print(waitingforconnection...)time.sleep(1)Step2.将PythonCode与Keys传送到RaspberryPiStep3.执行不久遍及RaspberryPi中的Python编码,python檔名.pyStep4.。


本文关键词:物,芭乐app最新版本下载官网,联网,用,Python,传送,温湿度,信息,到,AWSIoT

本文来源:芭乐app最新版本下载官网-www.shunshunxing.com