資源簡介
# 微信小程序-樹莓派照片監控
### 說明:
實現樹莓派照片監控功能,特色:
- 小程序和服務器使用webSocket通信
- 樹莓派和服務器使用mqtt通信

代碼片段和文件信息
#?-*-?coding:?utf-8?-*-??
#?樹莓派照片監控
#?作者:劉焱旺
#?官網:www.getweapp.com
#?QQ群:499859691
#?調試過程中有任何問題歡迎和我們聯系
import?paho.mqtt.client?as?mqtt
import?json
from?qiniu?import?Auth?put_file?etag?urlsafe_base64_encode
import?qiniu.config
import?os?time
#需要填寫你的服務器IP
ip?=?‘xxx‘
#需要填寫你的?Access?Key?和?Secret?Key
access_key?=?‘xxx‘
secret_key?=?‘xxx‘
#構建鑒權對象
q?=?Auth(access_key?secret_key)
#需要填寫你的空間
bucket_name?=?‘xxx‘
#需要填寫你的空間域名
base?=?‘http://xxx‘
#照片緩存
cache?=?‘‘
lastUpdated?=?0
#生成上傳?Token,可以指定過期時間等
token?=?q.upload_token(bucket_name?None?3600)
def?upload(localfile):
????ret?info?=?put_file(token?None?localfile)
????return?ret
#?連接成功回調函數
def?on_connect(client?userdata?flags?rc):
????print(“Connected?with?result?code?“?+?str(rc))
????client.subscribe(“CAMERA/PHOTO“)
#?消息推送回調函數
def?on_message(client?userdata?msg):
????global?base?cache?lastUpdated
????print(msg.topic+“?“+str(msg.payload))
????if?int(time.time())????? client.publish(‘CAMERA/PHOTO/BACK‘?‘{“id“:“‘+str(msg.payload)+‘“?“path“:“‘+cache+‘“}‘)
???? return
????r?=?os.system(‘fswebcam?-r?640*480?imagex01.jpg‘)
????ret?=?upload(‘./imagex01.jpg‘)
????print?ret[‘hash‘]
????cache?=?base+ret[‘hash‘]
????lastUpdated?=?int(time.time())
????client.publish(‘CAMERA/PHOTO/BACK‘?‘{“id“:“‘+str(msg.payload)+‘“?“path“:“‘+base+ret[‘hash‘]+‘“}‘)
if?__name__?==?‘__main__‘:
????client?=?mqtt.Client()
????client.on_connect?=?on_connect
????client.on_message?=?on_message
????
????try:
????????#?請根據實際情況改變MQTT代理服務器的IP地址
global?ip
????????client.connect(ip?1883?60)
????????client.loop_forever()
????except?KeyboardInterrupt:
????????client.disconnect()
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-02-07?02:38??weapp-berrypi-photo-master\
?????文件?????????578??2017-02-07?02:38??weapp-berrypi-photo-master\README.md
?????目錄???????????0??2017-02-07?02:38??weapp-berrypi-photo-master\berrypi\
?????文件????????1907??2017-02-07?02:38??weapp-berrypi-photo-master\berrypi\mqtt.py
?????目錄???????????0??2017-02-07?02:38??weapp-berrypi-photo-master\client\
?????文件????????1030??2017-02-07?02:38??weapp-berrypi-photo-master\client\app.js
?????文件?????????271??2017-02-07?02:38??weapp-berrypi-photo-master\client\app.json
?????文件?????????204??2017-02-07?02:38??weapp-berrypi-photo-master\client\app.wxss
?????目錄???????????0??2017-02-07?02:38??weapp-berrypi-photo-master\client\pages\
?????目錄???????????0??2017-02-07?02:38??weapp-berrypi-photo-master\client\pages\index\
?????文件????????1477??2017-02-07?02:38??weapp-berrypi-photo-master\client\pages\index\index.js
?????文件???????????2??2017-02-07?02:38??weapp-berrypi-photo-master\client\pages\index\index.json
?????文件?????????175??2017-02-07?02:38??weapp-berrypi-photo-master\client\pages\index\index.wxm
?????文件?????????268??2017-02-07?02:38??weapp-berrypi-photo-master\client\pages\index\index.wxss
?????目錄???????????0??2017-02-07?02:38??weapp-berrypi-photo-master\client\pages\logs\
?????文件?????????318??2017-02-07?02:38??weapp-berrypi-photo-master\client\pages\logs\logs.js
?????文件??????????56??2017-02-07?02:38??weapp-berrypi-photo-master\client\pages\logs\logs.json
?????文件?????????194??2017-02-07?02:38??weapp-berrypi-photo-master\client\pages\logs\logs.wxm
?????文件?????????114??2017-02-07?02:38??weapp-berrypi-photo-master\client\pages\logs\logs.wxss
?????目錄???????????0??2017-02-07?02:38??weapp-berrypi-photo-master\client\utils\
?????文件?????????481??2017-02-07?02:38??weapp-berrypi-photo-master\client\utils\util.js
?????目錄???????????0??2017-02-07?02:38??weapp-berrypi-photo-master\server\
?????文件????????1234??2017-02-07?02:38??weapp-berrypi-photo-master\server\berrypiServer.js
- 上一篇:hcgconv 游戲解包工具
- 下一篇:abaqus_material.zip
評論
共有 條評論