I've two xBee Pro S2C module. I'm trying to send a image from Windows PC to Raspberry Pi with xBee modules. I configured my xBees for API mode and i can receive/send AT text messages with Python codes.
I want to send a image from my PC to Raspberry Pi Model 3 B+
I also checked this subject: http://cms.digi.com/support/forum/70518/transfer-image-between-xbee-modules-connected-raspberry-each
I made some changes and tried codes below.
PC side(sender) ###########################
ser = serial.Serial('COM6', 9600,timeout=.5)
fc= 'xbee.jpg'
File = open(fc,'r')
#while True:
line = ser.readline()
a= File.read()
print(str(a))
ser.write(str(a))
#############################
Raspberry Pi side (receiver) #############################
ser = serial.Serial('/dev/ttyUSB0', 9600,timeout=.5)
while True:
incoming = ser.readline().strip()
file = open ('images.png','wb')
print (incoming)
file.write(incoming)
file.close()
content= file.read()
#################################
Then i got a error:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 240: character maps to <undefined>
Also an idea came to my mind. I made a script converts an image to base64 code and saves as a .txt file. I changed "images.png" as "test.txt". There is no error occured but also there is no .txt file created on my raspberry pi.
Thats really important for me. Please help.
UPDATE
I've tried this code also: https://github.com/MortadhaDhkar/zigbee-file-transfer
There is no error occured. But also file don't receive to Raspbbery Pi. Sender.py out put is:
Sending Header...
Sending File...
Done
strip()might mess the original byte order, breaking the image. Additionally, it looks like you're reading a JPG ("xbee.jpg") and writing a PNG ("images.png"). Note that these are different image codecs. If you want to send the images a string, perhaps encode/code to Base64 (and pay attention to strip()/etc.) ? Alternatively you could decode the image into a flat array of r,g,b values and send that as bytes ? - George Profenzaincomingin thewhileloop instead of appending. If the image is large it will take a long time to transmit at 9600 bauds per second. Looking at the image size in bytes and dividing by the baud rate will give you an idea how that will take to transfer. - George Profenza