Rafael.Ferreira
Posts: 4
Joined: Tue Nov 26, 2019 2:19 pm

[Pi 4] Send image through serial

Tue Dec 03, 2019 4:58 pm

Hello,

I have a question, I'll have a RPi 4 installed with cameras that take pictures every hour and then sends it via Serial Radio to another station (Local and distance offer me no other viable choice),, how can send *jpg over a serial port on the RPi and receive on the other end on a Windows PC??

Please help, this matter is driving me insane.

User avatar
topguy
Posts: 5959
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: [Pi 4] Send image through serial

Tue Dec 03, 2019 8:23 pm

What are the stats for your radiolink ?
- Is it two-way communication ? ( if not this is going to be rather difficult )
- What is the bandwidth/speed ? ( bits per second )

Back in the days when BBS was a thing we use special filetransfer protocols called Xmodem/Ymodem and Zmodem.

On the linux end you have commands : https://linux.die.net/man/1/sz
And on windows you have terminal programs that can support the same protocols. ( ExtraPutty , SyncTERM )

There is also the option to use the PPPD protocol between the two machines, which is basically internet dial-up which we used before broadband.
This would set up a network connection between the Pi and the PC and then you could use standard internet protocols for transferring the files.
Part solution here: https://www.instructables.com/id/Connec ... sing-UART/

Rafael.Ferreira
Posts: 4
Joined: Tue Nov 26, 2019 2:19 pm

Re: [Pi 4] Send image through serial

Thu Dec 05, 2019 2:36 pm

Thanks for your reply, radio is listening to signal and sending straight to a webserver.

I did manage to accomplish the task tho, I converted the images to hex, sent the hexes though serial port, collected the hexes and remounted the image on clinet-side.

I am having now a really smaller problem on the task. Sometimes the radio scrambles my receiving end, I get the messages out of order and I'm failing to use a number as an indicator inside the coding.

Code: Select all

import serial
import time


s = serial.Serial("/dev/ttyUSB0")

i = 1

f = open('/home/pi/camlog/cam1.txt', 'rb')

while True:
    piece = f.read(512)  
    if not piece:
        break
    s.write('CAM1P')
    s.write(i)
    s.write('_')
    s.write(piece)
    #time.sleep(30)
    s.write('\r\n')
    i += 1
For some reason, i as an integer, isn't sent by serial, I have no idea why or how to go around this.

User avatar
topguy
Posts: 5959
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: [Pi 4] Send image through serial

Thu Dec 05, 2019 4:24 pm

Explain to us how you want the line to look.

The integer 123 is not converted to the string "123" by the s.write() you have to do that first.

Return to “Media centres”