定义从Raspberry(使用4G modedm[Quectel ec25])到Linux Socket服务器的TCP IP数据传输协议

2024-06-09 05:48:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个RPi 4+Sixfab Base HAT+Quectel EC25 4G LTE调制解调器+Picam,我正在尝试开发一个程序,从Picam拍摄照片,并使用TCP/IP协议通过4G发送照片,然后在Linux Socket服务器上接收和显示照片

我对此没有太多经验,也看过一些套接字编程信息,但并不完全适合我,因为我使用的是Quectel 4G调制解调器,而不是wifi或以太网,这意味着我不能使用套接字。函数,但仅限于命令

到目前为止,我可以用4G从Rpi发送一个用base64编码的20x20 png小图像,并在socket服务器中接收,但无法重建小图像

但是如果数据变大,我需要定义一个协议(文件大小、开始-结束等)。我见过一些定制协议,但它们仅用于套接字服务器,不包含4G调制解调器的使用。如果有人能给我指引正确的方向,我将不胜感激

if ser.isOpen(): # if modem is open
try:
        ser.flushInput() 
        ser.flushOutput()

        BG96 = bg96_init()  # initialize function for the Modem

        i = 0
    encoded = ""
        #start = time.time()
        while BG96:# 
                if i==0:# does something the first time but not relevant here << 
            print(i)
        encoded = base64.b64encode(open('testingimg.png', 'rb').read())
                print("Data size to send to 4G module:" , sys.getsizeof(encoded))
        print("The Image String: " , encoded)
        bg96_msg(encoded) # This is a function that sends the data via TCP with AT commands 

        encoded=""
        
        ser.flushInput() 
        ser.flushOutput()
        i = i+
        time.sleep(0.33)

Tags: the服务器协议调制解调器iftimepng照片