1、Usb轉RS232串口線驅動安裝:群華農天霸里面的文件CH340驅動
2、GPRS-DTU配置:在http://www.comway.com.cn/doc.asp上下載資料
(1) 看COMWAY GPRS DTU配置軟件V4.01使用說明,配置好連接的服務器地址,端口
3、將串口發送給GPRS模塊的數據顯示出來
(1) 購買一個服務器,購買一張上網卡
(2) 按照2的要求配置好GPRS
(3) 給GPRS模塊上電,在服務器上運行端口監聽程序(Python,Java,c++都可以)
如下所示:
import socket,select s = socket.socket() #host = socket.gethostname() host = '' print(host) port = 8000 //這里端口配置8000 s.bind((host,port)) s.listen(5) inputs = [s] while True: rs,ws,es = select.select(inputs,[],[]) for r in rs: if r is s: c,addr = s.accept() inputs.append(c) print(addr) else: try: data = r.recv(1024) disconnected = not data except: disconnected = True if disconnected: inputs.remove(r) else: print(data)
(4) 在服務器上運行這個程序,通過串口給GPRS-DTU發送數據時,會在服務器上顯示
串口端(ATKXCOM) 服務器端(Xshell)
4、創建數據庫
下載MySQL數據庫並且安裝,然后把Python關聯數據庫
python關聯數據庫
安裝依賴包 :conda install mysqlclient 測試:import MySQLdb 不會報錯。
測試一個小程序:用Python訪問數據庫(前提是先要用SQL語句創建好一個數據庫)
import MySQLdb try: conn = MySQLdb.connect( host='127.0.0.1', user='root', passwd='root', db='db1', port=3306, charset='utf8' ) cursor = conn.cursor() cursor.execute('select * from t1') result=cursor.fetchall() for data in result: print(data) conn.close() #關閉連接 except MySQLdb.Error as e: print('Error:%s'%e)
運行結果:
5、將數據導入數據庫
視頻有講解
6、將數據庫中的文件顯示到網頁上來
首先用Python打開url_for,加載靜態文件時,參考博客https://blog.csdn.net/qq_39974381/article/details/80841140,
然后.css文件可能不會起作用,這個是瀏覽器的編碼問題,下載擴展程序,然后復位瀏覽器的編碼。
7、用Python加載網頁是不能用index.css,否則很難查到錯誤出在index.css上