while (1)
{
if (radio.available())
{
uint8_t got = radio.read(&p, PKT_SIZE);//error line
sp("Got pkt: ");
// for (int i = 0; i < got; i++)
// Serial.print((char)p*);*
sp(" ");*
for (int i = 0; i < got; i++)*
{*
_ Serial.print(p*, HEX);_
_ sp(" ");_
_ }_
_ spl("");_
_ }_ if (Serial.available() > 0)
_ {_
_ p[0] = 'P';_
_ p[1] = 'W';_
_ p[2] = 'N';_
_ p[3] = Serial.read();_
_ sp("Sending PWN");_
_ // Serial.println((char)p[3]);_
_ radio.stopListening();_
_ radio.write(&p, 4);_
_ radio.startListening();_
_ }_
_ }_
_}_
_……………………………………*_ Error: Arduino:1.6.5 (Windows 7), Board:"Arduino Uno" keysweeper_mcu_src.ino: In function 'void backtrace(uint8_t)': keysweeper_mcu_src:916: error: void value not ignored as it ought to be void value not ignored as it ought to be I hope someone can help me solve this problem,THANKS FOR ALL!!!
If the error message really is referring to this statement:
uint8_t got = radio.read(&p, PKT_SIZE);
then what it means is that the radio.read() function is declared (in RF24.h) to return void (i.e. not return anything) but that your code is trying to store this non-existent return value in "got" - (it's nothing to do with &p).
As written, the original program is expecting that read() is going to return the number of characters that were read.
The version of RF24.h that I have, declares read() to return a boolean value!
Find RF24.h in your Arduino library and see how read is declared.
#el_supremo Hi,Pete.Thanks very much for your help!
As we can see, the following statement is "for (int i = 0; i < got; i++)",i don't know how to correctly assign to "got"(or modify the program to make it run).Could you give me some suggestions? Thank you!
I suggest that you re-read all the responses. Note that they all contain variations on the phrase "depending on the version of XXX.h that you have". So, YOU need to tell us EXACTLY which version you have. How can you expect us to guess?
@return True if the payload was delivered successfully false if not
*/
................................................................................................
When I compile the code again,it gives me the error "void value not ignored as it ought to be "Meanwhile,
I check the RF24.h, I also find the sentence " @return Payload length of last-received dynamic payload"was marked in red.
When I compile the code again,it gives me the error "void value not ignored as it ought to be "
Because that code clearly says that the read() method does not return a value.
I check the RF24.h, I also find the sentence " @return Payload length of last-received dynamic
Well, I can't, since you didn't post the complete file.
So,how can I modify my program to correct errors?
Stop trying to store the non-existent return value in a variable.
Now, clearly the next question is going to be "But how to I get a value for got?". And the answer is provided in the snippet:
* The maximum size of data written is the fixed payload size, see
* getPayloadSize(). However, you can write less, and the remainder
* will just be filled with zeroes.
So, all you need to do is call strlen() with the array that you populated using the read() method (possibly with a cast, if the array type is not char) and store the returned value in got.
el_supremo:
The RF24 code works in packets. Either it succeeds in reading a complete packet or it fails which is why it returns a boolean result.
Change this:
uint8_t got = radio.read(&p, PKT_SIZE);
to this:
uint8_t got = 0;
if(radio.read(&p, PKT_SIZE))got = PKT_SIZE;
Pete
That will not work, for the same reason the original code will not work. It assumes radio.read() returns some return value, which it does not!
You're right Ray.
He says that his version is from GitHub - maniacbug/RF24: Arduino driver for nRF24L01 which returns boolean. But he also says "From RF24.h,I find the function" which is void.
Looks like the problem is that he has at least two different versions of RF24.h installed.
@Eyolk
You need to remove the version of RF24 which declares the read to return void. Move whichever directory it is in to somewhere outside your Arduino directories so that the IDE won't find find it. Then try compiling again.
What happened was in the older RF24 library radio.read() used to return a boolean value. But later modified RF24 libraries changed it so it didn't return anything.
@el_supremo I'm so grateful to you,Pete! I follow the solutions you give,
In RF24.h,I change this
void read( void* buf, uint8_t len );
to this
bool read( void* buf, uint8_t len );
and finally the whole program works!! Cheers!
The crux of the problem is the "read()"in RF24.h from https://github.com/maniacbug/RF24.git,which is void rather than boolean.
It almost takes me the whole day to solve this problem .
Thanks for all your sincere help!@Vaclav@el_supremo@PaulS@RayLivingston
In the code at that link, read() is declared boolean in both RF24.h and RF24.cpp
Even if you changed read() from void to bool in RF24.h, I don't see how it compiled unless you also changed the return type of read() in RF24.cpp. Unless perhaps your RF24.h and RF24.cpp are from different versions.
But, it's working, so no worries
Not bloody likely! Simply changing the prototype in the .h file cannot possibly actually FIX the problem! The function still has to actually RETURN something, which means modifying the .cpp file.
@return True if the payload was delivered successfully false if not
*/
................................................................................................
When I compile the code again,it gives me the error "void value not ignored as it ought to be "Meanwhile,
I check the RF24.h, I also find the sentence " @return Payload length of last-received dynamic payload"was marked in red.
So,how can I modify my program to correct errors?
Eyolk: #PaulS I'm sorry for the inconvenience caused by me.Thank you for your remind,I'll reply more specifically and carefully.
@return True if the payload was delivered successfully false if not
*/
................................................................................................
When I compile the code again,it gives me the error "void value not ignored as it ought to be "Meanwhile,
I check the RF24.h, I also find the sentence " @return Payload length of last-received dynamic payload"was marked in red.
So,how can I modify my program to correct errors?
Eyolk: #PaulS I'm sorry for the inconvenience caused by me.Thank you for your remind,I'll reply more specifically and carefully.
@return True if the payload was delivered successfully false if not
*/
................................................................................................
When I compile the code again,it gives me the error "void value not ignored as it ought to be "Meanwhile,
I check the RF24.h, I also find the sentence " @return Payload length of last-received dynamic payload"was marked in red.
So,how can I modify my program to correct errors?
return True if the payload was delivered successfully false if not
It is . or should be, known that programmers / software engineers are fond NOT to comment their code,
worse yet comment it incorrectly. That is the reality.
When it doubt , flush it out AKA READ the actual code , that is what the compiler goes by anyway.
As far as fixi'n your code - if you are interested how may "records" ( whatever that is) was received I am willing to bet that there is ANOTHER API which tells you that.
It is unfortunate that similar "libraries" have same function declared differently.
Even if the function returned bool - it is relatively worthless for function reading records.
"Smart" function would return number of records etc etc.
Back to the OP - the code was evaluating "void" return and if you really need to have a return YOU have to modify both - the function declaration and definition, not just the declaration.
The function still has to actually RETURN something, which means modifying the .cpp file.
Yeah, exactly. But apparently it did fix it. So either the OP also fixed it in the .cpp and didn't mention it, or the .cpp was already correct but he had the wrong version of the .h file.
Neither option is satisfactory.
In the former case, just changing the read() in .cpp from void to bool would still not fix the code.
In the latter case, having mixed versions of a library is also problematic.
el_supremo:
Yeah, exactly. But apparently it did fix it. So either the OP also fixed it in the .cpp and didn't mention it, or the .cpp was already correct but he had the wrong version of the .h file.
Neither option is satisfactory.
In the former case, just changing the read() in .cpp from void to bool would still not fix the code.
In the latter case, having mixed versions of a library is also problematic.
Pete
If the function implementation did have a return type other than void, the compiler would generate an error for the prototype which indicated a return type of void. If the function did not return a value, the compiler would also generate an error for the prototype. Far more likely, the OP thinks it works, but it really does not, which will come back and bite him in the a$$ as some point...