Hi,
Im a complete noob to programming really apart to finding small bits of code, playing with it and trying to understand it.
At the moment i have an esp with Nodemcu FW.
I have the esp subscribed to my mqtt account and receiving feed data between 0.00 and 15.00.
I am trying to get the code to turn on outputs at 5 different levels as the values received increase from 0-15.
The problem i seem to be having is my compare string appears to only be taking note of the 1st digit. (e.g. id 3 if 31 is received). If 31 is received it would turn on my first two outputs but not the others. Where as if 9 is received is would turn 4 of the 5 outputs on.
I would really appreciate some help, I’ve spent hours trolling through the web without finding anything i can truly understand.
Regards
Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt.readSubscription(5000))) {
if (subscription == &uv_index_feed) {
Serial.print(F("Got uv index: "));
Serial.println((char *)uv_index_feed.lastread);
} else if(subscription == &errors) {
Serial.print(F("ERROR: "));
Serial.println((char *)errors.lastread);
} else if(subscription == &throttle) {
Serial.println((char *)throttle.lastread);
} if (strcmp((char *)uv_index_feed.lastread,"0" ) >= 0) {
digitalWrite(2, LOW);
} if (strcmp((char *)uv_index_feed.lastread,"3") >= 0) {
digitalWrite(13, LOW);
} if (strcmp((char *)uv_index_feed.lastread,"3") < 0) {
digitalWrite(13, HIGH);
} if (strcmp((char *)uv_index_feed.lastread,"6") >= 0) {
digitalWrite(4, LOW);
} if (strcmp((char *)uv_index_feed.lastread,"6") < 0) {
digitalWrite(4, HIGH);
} if (strcmp((char *)uv_index_feed.lastread,"8") >= 0) {
digitalWrite(5, LOW);
} if (strcmp((char *)uv_index_feed.lastread,"8") < 0) {
digitalWrite(5, HIGH);
} if (strcmp((char *)uv_index_feed.lastread,"11") >= 0) {
digitalWrite(14, LOW);
} if (strcmp((char *)uv_index_feed.lastread,"11") < 0) {
digitalWrite(14, HIGH);
}
}
.
Moderator edit: hours looking for a solution, but not a couple of minutes reading the forum posting guidelines?