I have built the arduino 433MHz receiver Bill demonstrated a little while ago but I have a different module (8pins) but it seems to work.
What I would like to do is modify the code in some way so that knowledge of the buffer size is not needed. I have some devices which use 433MHz to communicate and I would like to eavesdrop on them to figure out how they work etc.
Any suggestions?
If you need variable size storage you will need to use dynamic memory allocation i.e. malloc, calloc functions from the standard library. I have heard the uno because of its small ram size (appox 2k bytes) does not do well using those functions. You may have to step up to an esp32 or stm32 which have a lot more ram.
Thank you @noweare
More homework. I don't know malloc and calloc so I'll read up on them.
I'll try the uno first and hope I can trim it enough to fit. Once I know the buffer sizes of my devices, I can forget malloc and hard-code them and then take it from there with my experiments.
I was intending to get a mega and an esp32 soon, so maybe my hand is being forced. Thanks again.
More homework. I don't know malloc and calloc so I'll read up on them.
Look up the C++ 'new' and 'delete' operators too, for dynamic memory management.
Cheers!
Aw! Even more homework. 🤔
Thanks 👍
I am looking in https://www.arduino.cc/reference/en/ but cannot find any of the keywords there.
Is there a better site to use?
This might be a good place to start your search for C++ commands not specified in the Arduino Language Reference.
Malloc, calloc etc... are from the C standard library, you will not find them in the arduino reference section. If you want to practice with how to use them I would recommend using an IDE like CodeBlocks or Eclipse set up for C/C++, not the arduino IDE. It will save you time, plus those environments normally have a debugger so you can step through your code. Once you understand then try it in the arduino IDE.
@revver11 Yeah, I have about 4 unfinished projects I need to button up. Hard for me to
focus on one thing.
What I would like to do is modify the code in some way so that knowledge of the buffer size is not needed.
I agree with the comments other have posted on learning more about memory management in C, C++.
Still, given the issue as you outlined it, what I would do is specify a buffer, just a regular buffer like in the example code, that is "big enough." In the context of the 433 MHz devices you mentioned, I would say 60 or 100 characters is more than enough. The C string ends with a null byte, a zero.
So the garage door opener, little weather station across the street, who just happens to also be running Bill's sketch for temperature and humidity, the other IoT commands, all of them are probably quite short. Try it.
What's the worst that could happen? It receives a couple messages, then a too-long message overflows the buffer and crashes the Arduino? When my components arrive, I'm going to try this myself. I find my neighborhood is quite crowded with WiFi, always from 12 to 30 other SSIDs competing with me. So I wondered if 433 MHz would work for some applications.
Good luck!
In theory, theory and practice are the same.
In practice, they're different.