In a nutshell, I have two particles, one reading temperature from Dallas DS18B20 One-Wire temperature sensor and publishing that data, and another that is subscribing to the data and should be turning on/off LED’s based on the “if” statements for the data. However, my subscribe particle is getting VERY weird data and is constantly just turning on one LED from it. I was wondering if anyone could help me figure out why.
The first particle publishing the temperature data has code that is almost an exact clone of the Temp Logger Particle Tutorial found Here. The only changes are the publishing data:
String temperature = String(fahrenheit);
Particle.publish("bfurlong_current_temp", temperature, PUBLIC);
delay(10000);
}
Here is what it looks like on the console:
Next is my Subscribe particle. My professor helped me a lot with this but while it does compile, it does not work and seems to be getting a constant 536895503 data string. I found this number by converging on it trying to find what number I was getting. Here is the code and explanations for it.
void setup()
// These Pins all have LED's on them.
{
pinMode(D0, OUTPUT);
pinMode(D7, OUTPUT);
pinMode(D2, OUTPUT);
Particle.subscribe("bfurlong_current_temp", myHandler);
}
// My professor told me I needed this empty loop in order to run.
void loop () {
}
void myHandler(const char *event, const char *data)
//These are all if statements only because if else did not work.
//To prevent LED's from coming on when they shouldn't,
//I set them to LOW.
//My professor told me that int(data) would suffice comparing the temp data.
{
if(int(data)<=74) {
digitalWrite(D7,HIGH);
digitalWrite(D0,LOW);
digitalWrite(D2,LOW);
}
if((int(data)>74)&&(int(data)<85)) {
digitalWrite(D2,LOW);
digitalWrite(D0,HIGH);
digitalWrite(D7,LOW);
}
if(int(data)>=85) {
digitalWrite(D7,LOW);
digitalWrite(D0,LOW);
digitalWrite(D2,HIGH);
}
}
It will only turn on the final LED and keep it on because, again, it seems to be getting 536895503. Temperature change does not seem to affect this string. Anybody have any clues as to why it’s doing this or how I could make my code read it? Thanks in advance.