esp32-cam NRF24l01 image transfer

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
aardbei
Posts: 2
Joined: Sun Dec 29, 2019 5:07 pm

esp32-cam NRF24l01 image transfer

Post by aardbei » Sun Dec 29, 2019 6:09 pm

Hello Developers,

i have micropython running on an ESP32-Cam and a ESP32 Olimex POE.
Goal is to grab an image from the ESP32-Cam and transfer that with the NRF24L01
to the ESP32 Olimex POE what is acting as a MQTT gateway and transfer that
image to an MQTT broker for further processing.

When i install the NRF24L01.py and NRF24L01test.py and run the nrf24l01test.master() and
slave() all is working so the basic communication is there.

now on the ESp32-Cam i create a bytearray split the cam buffer into 32 bytes pack them into the
bytearray and send them.

When i directly print the nrf.recv() buffer on the olimex the only thing what i receive is
b'\x00\x00\x00\x00\x00\x00\x00\x00'

So my question is how do get the binary image data correctly to the other side? Assuming
the error is in the struct.pack.

Regards,
Hans

Code: Select all

import sys
import ustruct as struct
import utime
import camera
import uctypes
from machine import Pin, SPI
from nrf24l01 import NRF24L01
from micropython import const

#Init Cam
camera.init()
buffer = camera.capture()
---- snip
 ----
def master():
    csn = Pin(cfg['csn'], mode=Pin.OUT, value=1)
    ce = Pin(cfg['ce'], mode=Pin.OUT, value=0)
    if cfg['spi'] == -1:
        spi = SPI(-1, sck=Pin(cfg['sck']), mosi=Pin(cfg['mosi']), miso=Pin(cfg['miso']))
        nrf = NRF24L01(spi, csn, ce, payload_size=8)
    else:
        nrf = NRF24L01(SPI(cfg['spi']), csn, ce, payload_size=8)

    nrf.open_tx_pipe(pipes[0])
    nrf.open_rx_pipe(1, pipes[1])
    nrf.start_listening()
   
   data=bytearray(32)
   chunk = [buffer[i:i+32] for i in range(0, len(buffer), 32)]
   try:
       for part in chunk:
           payload = (struct.pack('<s', data, part))
           nrf.send (payload) 
    except OSError:
       pass
----- snip----

User avatar
pythoncoder
Posts: 3935
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: esp32-cam NRF24l01 image transfer

Post by pythoncoder » Mon Dec 30, 2019 6:51 am

I'm puzzled by your code. As far as I can see the data array is never populated so will always contain 0. It seems you're sending 32 bytes of zero followed by a single byte from chunk. Since the NRF24l01 can only send 32 bytes, you're receiving zeros.

I suggest using print statements on the transmitter so that, as you adapt your code, you can see what you're sending. Or prototype the data formatting on another MicroPython host so that it's debugged before you host it on your transmitter.
Peter Hinch

aardbei
Posts: 2
Joined: Sun Dec 29, 2019 5:07 pm

Re: esp32-cam NRF24l01 image transfer

Post by aardbei » Mon Dec 30, 2019 6:14 pm

Hi Peter,

Thanks for your answer!
You're right. A print of the payload shows me b'\x00\x00\x00\x00\x00\x00\x00\x00'.

i'll try to find a good way and post the solution when i have it :)

Regards,
Hans

Post Reply