Home/Support/Support Forum/how to transfer image from one raspberrypi3b+ to other using xbee?

how to transfer image from one raspberrypi3b+ to other using xbee?

0 votes
hardware setup:
connected two xbee modules to two raspberrypi, configured one xbee as coordinator(receiver) and the other as router(sender).
we are able to send text file over xbee transparent mode.
problem:
we are unable to send complete image file over this setup. below is the code used for sending and receiving image.
on the receiving side we are able to see the garbage (may be image received),but unable to view it in any image viewer.here we are facing error:fatal error reading jpg image file.
error:interpreting jpeg image file (not a jpeg file:starts with 0x00 0xd6)
can someone help us in doing this as soon as possible.
thanks in advance.

python code sender side:

#from twilio.rest import Client
from gpiozero import MotionSensor
from picamera import PiCamera
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
import datetime
import smtplib
import time
import serial


#import serial
import RPi.GPIO as GPIO
import os, time

#GPIO.setmode(GPIO.BOARD)

# Email Addresses
fromAddr = 'abc@gmail.com'
toAddr = 'def@gmail.com'

#Motion Sensor and Camera Initialized
PIRSensor = MotionSensor(14)
camera = PiCamera()

# Variable to Exit while loop
Tripped = True

#wait five seconds
time.sleep(2)

while Tripped:
if PIRSensor.motion_detected:
print("Motion Detected")

timeCaptured = '/home/pi/Desktop' + datetime.datetime.now().strftime('%Y-%m-%d%H:%M:%S') + '.jpg'
camera.rotation = 180
#camera.start_preview()
camera.capture(timeCaptured)
timerecorded = '/home/pi/Desktop' + datetime.datetime.now().strftime('%Y-%m-%d%H:%M:%S') + '.h264'
camera.start_recording(timerecorded)
time.sleep(5)
camera.stop_recording()
#camera.stop_preview()
print("Image Captured")
print("video recoded")


####xbee tranfer
ser = serial.Serial('/dev/ttyUSB0', 9600,timeout=.5)
fc= '/path/xbee.jpg'
File = open(fc,'r')
#while True:
line = ser.readline()
a= File.read()
print(str(a))
ser.write(str(a))
###xbee
#########email
#Create the Message
msg = MIMEMultipart()
msg[ 'Subject'] = 'Intruder'
msg = fromAddr
msg = toAddr

#Attach the file
File = open(timeCaptured, 'rb')
img = MIMEImage(File.read())
File.close()
msg.attach(img)

username = 'abc@gmail.com'
password = '*****'

server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromAddr, toAddr, msg.as_string())
#message = client.messages.create(body="HEY SOMEONE ENTERED..PLEASE CHECK YOUR MAIL",from_='+19587463210',to='+919876543210')
server.quit()

print("Email Sent")
#print("sms sent")
# print("msg sent to:"+message.to)
# print(message.to)
#camera.close()



code on receiving end::

import serial
import os
import datetime
import smtplib
import time
import mysql.connector
db = mysql.connector.connect(host="localhost", user="root", password="2019", db="test")
cursor = db.cursor()

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()
file = open ('tezt.txt','r')
content= file.read()

sql = """LOAD DATA LOCAL INFILE '/home/pi/images.png' INTO table filetry"""
print ("data inserted")
cursor.execute(sql,(content))
db.commit()
db.commit()
db.close()
asked Jul 9 in IEEE 802.15.4 by prahari New to the Community (0 points)

Please log in or register to answer this question.

...