I would like to define the variables for notifications, I am planning to add multiple sensors to one device but don’t want to trawl the entire code to make the changes if needed.
Not sure how to explain it and probably why I can’t find it in searches.
Note… I am not a programmer
Should I use something other than const char*
Please see the code below which @khoih helped with.
This part gives the error below
if (temp_0 >= tempHIGH1 && !notified)
/*****************Start Temp Settings******************/
//Sensor1
const char* tempHIGH1 = "32";
const char* tempOKmax1 = "31";
const char* tempOKmin1 = "27";
const char* tempLOW1 = "26";
//Sensor 2
const char* tempHIGH2 = "9";
const char* tempOKmax2 = "8";
const char* tempOKmin2 = "3";
const char* tempLOW2 = "2";
/*****************End Temp Settings******************/
//void sendSensor
//etc. etc.
//DS18B20 Notify
if (allowNotify)
{
//Notifications 1st try
if (temp_0 >= tempHIGH1 && !notified)
{
notified = true;
Blynk.notify ("Alert - Temperature is", temp_0, "C!");
Blynk.email(emailMe, emailsubject, "Alert - Temperature over 32C!");
timer.setTimeout(600000L, resetNotified); // 10 min between messages 600000L = 10 Min 60000L = 1 min
}
else if ((temp_0 < tempOKmax1) && (temp_0 > tempOKmin1))
{
notified = false;
}
else if (temp_0 <= tempLOW1 && !notified)
{
notified = true;
Blynk.notify("Alert - Temperature under 27C!");
Blynk.email(emailMe, emailsubject, "Alert - Temperature under 27C!");
timer.setTimeout(600000L, resetNotified); // 10 min between messages
}
}
I am getting this error
ISO C++ forbids comparison between pointer and integer [-fpermissive]
You have a typing issue. A variable of the type “char” contains just that, characters. In your if statement you are doing a compare with a mathematical operator (bigger then >=) and you can’t say that “a is bigger than 8”.
Therefor, if you define the type of your tempHIGH1 for example as:
const int tempHIGH1 = 32;
it should probably work, because the datatype of the int variable is actually a number you can do math on.
Oh, and it’s probably a char* because you want to display it right? You can concatenate a int with all sorts of other types:
String blehblehbleh = "temperatur high is: " + tempHIGH1;
Haven’t checked that, but it should work. Otherwise there is toString() function which will do the job.
Awesome! Thanks everyone, all three verified, just need to test them.
Thanks for this tip!
I have another question, maybe it should be a new topic…?
If there are no values (nan) going to blynk for say 5 minutes, could a notification be sent? This would be if the device is online and connected to blynk, but the sensor is faulty.
You’d handle that in your code.
If you receive a NAN from your sensor then set a flag and start a timer. If you then receive a proper reading reset the flag and cancel the timer, otherwise when the timer expires send a message that the sensor is faulty.
Hey, is it possible to define the number values with a slider widget for the notifications?
If so could someone please point me in the right direction? And which of the three options would work better for this?
I want to know if this can be controlled from the blynk app.
So if one slider is set at 9 (tempHIGH2) and the other at 2 (tempLOW2), notifications would be sent above or below but not for the values in-between.
The sliders selects the (tempHIGH2) and (tempLOW2) values and I guess with math… the in-between values could be calculated but I do not know how to achieve this.
These values would then be defined and used for the notifications.
The code you linked to is fine, except for one thing, which may catch you out. The code contains this line, which gets the value from the widget and assigns it to the variable pinValue…
int pinValue = param.asInt();
If you simply replace pinValue with tempHIGH2 so that it looks like this…
int tempHIGH2 = param.asInt();
then it won’t work as you expect it to. The reason being that by having “int” in front of the variable name tempHIGH2 means that you’re creating a local version of the tempHIGH2 variable and the value that you assign using the slider only exists within the BLYNK_WRITE(Vx) function.
It should actually look like this:
tempHIGH2 = param.asInt();
so that the value that comes from your slider will be assigned to the global variable that you assigned at the top of the sketch, not a local copy of that variable.
If you want to learn more about this then google “variable scope”.
This code:
String blehblehbleh = "temperatur high is: " + tempHIGH1;
Is trying to add an integer onto the end of a string. The integer needs to be converted into a string first before you can do this…
String blehblehbleh = "temperatur high is: " + String(tempHIGH1);
To change a topic’s heading (to “solved” for example) you scroll to the top of the topic, click the pencil icon to the right of the topic title, choose the category you want from the drop down box and click the icon to apply.
Thanks a lot @PeteKnight ! Will get to testing soon
The pencil you referred to is missing from there now, when I clicked it this morning, it displayed an error stating “you are not allowed to edit this post”
I used this and is working perfectly to show the current temperature within the notification
Blynk.notify("Alert - Temperature in C is: " + String(temp_0));
You were right it didn’t work, and I still cannot get it to work yet. In the serial monitor, it does show the slider value but the notifications are just coming in as if there are no variables set to send the notification, I think the way I define it globally is wrong, I will keep playing with it and let you know.
On another subject and another math issue I have, is to send the daily average, min and max once a day to a pin connected to the report widget but don’t know how to do the math for average, min and max in coding.