Compilation errors in Tutorial#4 - Temperature Logger

Hello,

I am trying to compile the code of the Tutorial#4 - Temperature Logger (https://docs.particle.io/tutorials/topics/maker-kit/#code) but I get the following errors, which do not make sense to me. Could you please help?

sensors.cpp: In function ‘void loop()’:
sensors.cpp:204:56: error: expected primary-expression before ‘||’ token
celsius = (float)data[2] + (float)data[1] * 0.03125;
^

sensors.cpp:204:73: error: expected ‘;’ before ‘{’ token
celsius = (float)data[2] + (float)data[1] * 0.03125;
^

make[1]: *** […/build/target/user/platform-6sensors.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.

Regards,
Panos

When I copied the code from that tutorial, I got similar errors (but with different line numbers), that were due to missing parentheses. This line (~16 lines from the bottom),

 if(((celsius <= 0 && celsius > -1) && lastTemp > 5)) || celsius > 125 {

should be,

 if((((celsius <= 0 && celsius > -1) && lastTemp > 5)) || celsius > 125) {

Notice two additional parentheses; one at the beginning after if, and one at the end before the curly brace.

1 Like

When you get error messages that seem to make no sense, look at the line numbers in the original code, since the code excerpt quoted in the error message is often off by a few lines.

Many thanks. That worked!!