文章目錄
- 一、簡介
- 二、詳細內容
- 1、硬體連接
- 2、串口初始化
- 3、樹莓派minicom除錯
- 4、C程式編譯
- 5、TCP/IP通信
一、簡介
??本文是對SIM7020C的初步使用說明,通過連接至樹莓派,通過python代碼控制,SIM7020C是一款具有NB-IoT(窄帶物聯網)功能的樹莓派擴展板,具有低功耗、低成本、廣覆寫等優點,適用于新型的智能儀表和遠程控制等物聯網應用,

二、詳細內容
1、硬體連接

??直接摁上就可以,然后將天線轉出

2、串口初始化

??關于串口的配置,這里我并沒有使用官網提供的方法,而是通過樹莓派使用mini串口與外部進行通信該篇博客,將/dev/ttyAMA0與/dev/ttyS0替換了位置

3、樹莓派minicom除錯

??所以這里minicom除錯也相應地改變了,輸入下列指令,然后正常操作即可
minicom -D /dev/ttyAMA0

4、C程式編譯


??按照以上步驟,我并沒有完成編譯,一開始是缺少aclocal-1.13,這個問題通過執行:autoreconf -vfi ,再重新編譯,就可以解決,但是會報出其他問題,于是就放棄了這種方式,采用了python測驗

5、TCP/IP通信
#!/usr/bin/python
import serial
import time
ser = serial.Serial('/dev/ttyAMA0',115200)
# Open Serial
def ser_init():
if ser.isOpen == False:
ser.open() # 打開串口
ser.flushInput()
rec_buff = ''
# Execute AT Command by SIM7020C
def send_at(command,back,timeout):
rec_buff = ''
ser.write((command+'\r\n').encode())
time.sleep(timeout)
if ser.inWaiting():
time.sleep(0.1 )
rec_buff = ser.read(ser.inWaiting())
if rec_buff != '':
if back not in rec_buff.decode():
print(command + ' ERROR')
print(command + ' back:\t' + rec_buff.decode())
return 0
else:
print(rec_buff.decode())
return 1
else:
print(command + ' no responce')
return 0
# Creat a Socket Connection
def send_init():
if True == send_at('AT+CSOC=1,1,1','OK',1):
print('Created TCP socket id 0 Successfully!')
conn = send_at('AT+CSOCON=0,2222,\"192.168.1.1\"','OK',2)
return conn
# Close Socket Connection
def send_close():
send_at('AT+CSOCL=0','OK',1)
send_at('AT+CSOCON?','OK',1)
print('Close Socket')
if __name__ == "__main__":
try:
ser_init()
conn = send_init()
while conn == True:
send_at('AT+CSOSEND=0,0,\"Waveshare Send to Socket id 0 using TCP\"','OK',2)
send_close()
except KeyboardInterrupt:
if ser != None:
ser.close()
if ser != None:
ser.close()
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/304878.html
標籤:其他
