First post but I’ve been tinkering with these things for a while. Must admit that my expertise is more medical than electrical.
I can’t get this to compile for some reason, and despite scouring the internet, can’t figure it out. Any pointers? It works fine if I just publish on a loop, so I’m missing something in the if / else syntax construction I’ve now added.
That code looks syntactically correct to me, but without seeing the rest of the source code in your project it is hard to know for sure. Is that the entire file? Where are distance and percentage declared, for example? Perhaps you could shared the entire source file?
Oh, i didn't noticed the first time, this is a bit screwed up. the right syntax to concatenate strings together is using the overridden "+" operator, like this:
Particle.publish("saltLevel", String(percentage)+"%", 60, PRIVATE);