nextion
nextion copied to clipboard
Library gives errors. Nextion::ack()
I get the following error when trying to use the library. Nextion.cpp: In member function 'boolean Nextion::ack()': Nextion.cpp:119:1: error: control reaches end of non-void function [-Werror=return-type] 119 | }//end | ^ This only happens when using the latest ESP8266 software
I'm getting the same error as well now. Was working fine but then poof, started to fail. Also using an ESP8266 and I hadn't played with this code in a while, so I suspect it's also because I updated the ESP libraries. Alternatively, it could be due to the Arduino IDE being more restrictive during compiling.... I temporarily fixed it as follows (added return true; near the end of the function in Nextion.cpp. However, I don't know if it's correct to return True or False if nothing evaluates in the function:
boolean Nextion::ack(void){
/* CODE+END*/
uint8_t bytes[4] = {0};
nextion->setTimeout(20);
if (sizeof(bytes) != nextion->readBytes((char *)bytes, sizeof(bytes))){
return 0;
}//end if
if((bytes[1]==0xFF)&&(bytes[2]==0xFF)&&(bytes[3]==0xFF)){
switch (bytes[0]) {
case 0x00:
return false; break;
//return "0"; break;
case 0x01:
return true; break;
//return "1"; break;
/case 0x03:
return "3"; break;
case 0x04:
return "4"; break;
case 0x05:
return "5"; break;
case 0x1A:
return "1A"; break;
case 0x1B:
return "1B"; break;///
default:
return false;
}//end switch
}//end if
return true; //Added DJA
}//end
I just downgraded the ESP8266 core to the last of version 2 and it cured it. I hadn’t used it for years either so when I did use it ESP8266 was version 2
The problem is caused by the boolean Nextion::ack(void){
function which starts at line 90.
The compiler expects a Boolean value to be returned, but all of the return
commands are located within if
statements. If none of the if
statements evaluate as true
then nothing will be returned, and the compiler doesn't like this possibility.
The solution is to add an additional return
command at the end of this function.
I'd also suggest changing the leftover return 0;
command to a return false;
like this...
boolean Nextion::ack(void){
/* CODE+END*/
uint8_t bytes[4] = {0};
nextion->setTimeout(20);
if (sizeof(bytes) != nextion->readBytes((char *)bytes, sizeof(bytes))){
//return 0; // <<< THIS LINE COMMENTED OUT
return false; // <<< THIS LINE ADDED
}//end if
if((bytes[1]==0xFF)&&(bytes[2]==0xFF)&&(bytes[3]==0xFF)){
switch (bytes[0]) {
case 0x00:
return false; break;
//return "0"; break;
case 0x01:
return true; break;
//return "1"; break;
/*case 0x03:
return "3"; break;
case 0x04:
return "4"; break;
case 0x05:
return "5"; break;
case 0x1A:
return "1A"; break;
case 0x1B:
return "1B"; break;//*/
default:
return false;
}//end switch
}//end if
return false; // <<< ADD THIS RETURN COMMAND
}//end
This fixes the "Failed to compile for
Pete,