I have been working on streaming data from OpenMv to NodeMcu.
I did manage to establish a protocol between OpenMv and Nodemcu to send a request from NodeMCU to OpenMv in order to start sending data.
But the data will be started with 4 packed bytes, representing the size of the image. Is there any idea how can I unpack these 4 bytes to reach the size of the image on the NodeMcu as I do need the size of the image in order to implement a flow control mechanism.
You just treat the 4 bytes as an int.
int x = 0; x |= byte3 << 24; x |= byte2 << 16; x |= byte1 << 8; x |= byte0 << 0;
x now has the value in in. Please read this: https://www.cs.cmu.edu/afs/cs/academic/class/15213-s09/www/lectures/02-bits-kesden.pdf
Both processors are little endian. Working with Bytes | The Things Network
Many thanks for the response. It works fine.
I am just wondering if the obtained number is the size of the image in bytes?
For instance, if obtained 2048 as the size of the image should I create a byte array with the size of 2048 to store this image? Am I right?
The Arduino Uno has not memory onboard really so if you are using that you lost likely won’t be able to do much. If you are using an arm based one you might be able to handle an image size. Mmm… Nodemcu is the esp32 right? That has plenty of ram.
Anyway, if you sent the length of the image to the Arduino then that’s the image size in bytes. So, yes, you write the image to the byte array. Note that jpeg images are variable size.
Do this, allocated a fixed buffer as big as you can make it. Write the received image to it as long as the image is less than the max buffer size. If it’s bigger just toss the bytes after reading them. This should let you safely received images.
Yes, It is an ESP32 nodemcu board and I think it has sufficient ram to store a low-quality image, but I still have a problem.
The problem is the length of sent data is not as same as the size of the image.
For instance, I got 1487 as the size of the image but just 628 bytes have been received by NodeMCU. I am not sure what is wrong?!
Code? And if possible please post the part that has the issue and not everything.
For future post… Please remember this is a forum where I’m answering questions. If you can post them in a way where I might be able to answer it quickly that helps