Reputation: 13
I am currently using a Raspberry Pi 4 to send and receive data in Python from sensors, DHT22, AS312 etc. My main issue is when I receive an image here is the abstraction (note paths seen here aren't real ones).
import time
import serial
import pandas as pd
import numpy as np
import threading
from memory_mangment import sensor_data
class Transceiver:
def __init__(self,data):
self.transceive=serial.Serial(port='/dev/tty50',
baudrate=9600,
parity=serial.Parity_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1)
self.message="Hello world! "
self.data=data
self.txt_fname="/path/to/txtfile.txt"
self.png_fnam="/path/to/pngfile.png"
self.csv_fname=sensor_data().fname
self.recived=self.transceive.in_waiting
self.event=threading.Event()
def Transmit_test_png_file(self):
"""Transmit a PNG file"""
with open(self.png_fname, 'rb') as f:
data = f.read()
self.transceive.write(data)
def Receive_test_png_file(self):
"Receive a PNG file"""
self.transceive.attachInterrupt(self.serial_interrupt)
if self.event.is_set():
data_read = self.transceive.readlines()
This is my main issue: it will print" [b'\x89PNG\r\n', b'\x1a\n', b'\x00\x0 ... " etc. If you don't have a radio module here is a way to replicate my issue:
import cv2
img_fname=r"/path/to/testfile.png"
with open(img_fname,'rb') as f:
data=f.readlines()
I'm wondering if I can use cv2.imdecode
to decode this. I have looked at some of the flags, just wondering if anyone had any recommendations on flags I can use to decode this or if there's an easier way of doing this. Let me know (note: I know some).
Upvotes: 0
Views: 51
Reputation: 6213
Unless your PNG image is under ~240 bytes total, it will not be transmitted in full. The maximum number of bytes that can be transmitted in a LoRa packet is 256, and that includes the overhead.
If you want to have a fighting change to get that image, you need to split it in chunks, add a header (xx/yy chunk xx out of yy chunks), and send them one by one, with a pause in between chunks (keep in mind also the fair use rule, usually 1% airtime).
But seriously, LoRa is not suitable for transmission of heavy payloads like images.
Upvotes: 0