BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Define variables for temperature notifications

Good Day,

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]

Thanks for any help

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.

1 Like

If you want decimal places in your temperature readings then go for float variable types. Otherwise use int variable types.

Neither type require quotation marks when assigning values.

Pete.

2 Likes

The other way is to use #define for constant variables, such as:

#define tempHIGH1          32
#define tempOKmax1         31
#define tempOKmin1         27
#define tempLOW1           26
//Sensor 2
#define tempHIGH2          9
#define tempOKmax2         8
#define tempOKmin2         3
#define tempLOW2           2
1 Like

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.

Pete.

Thanks everyone, all 3 suggestions worked perfectly!

1 Like

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 think you’d need to elaborate on what you’re trying to achieve.

Pete.

Thank you for your quick response

float tempHIGH2 = 9;
float tempOKmax2 = 8;
float tempOKmin2 = 3;
float tempLOW2 = 2;

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.

Does that explain my question better?

Please point me in the right direction

Actually I think I found it, and may be able to make it work…

I am unable to mark this topic as solved, do you have a workaround?

How would one add the current temp <temp_0> in the notify message? The above format gives an error. I tried using ([{ within and after the “ “

Thanks for any advice!

I’ll answer a few things in one go…

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 :heavy_check_mark: icon to apply.

Pete.

Thanks a lot @PeteKnight ! Will get to testing soon :wink:

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”

Okay, I’ve bumped your forum trust level up a notch, which should allow you to change the category of the project.

Pete.

Thanks, @PeteKnight, I can edit the post again.

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.

Thanks for all the advice

If you share your full code then we’ll take a look.

Pete.

Thanks,

  1. I think I found my problem and it has nothing to do with the slider… the same issue I had before… my logic
 if (temp_0 >= tempHIGH3 && !notified)
    {
      notified = true;
      Blynk.notify ("Alert - Temperature in C is: " + String(temp_0));
      timer.setTimeout(600000L, resetNotified); // 10 min between messages 600000L = 10 Min 60000L = 1 min
    }
    else if ((temp_0 < tempHIGH3) && (temp_0 > tempLOW3))
    {
      notified = false;
    }
    else if (temp_0 <= tempLOW3 && !notified)

So unless I use 4 sliders I will not be able to achieve the correct results because I do not know how to do (code) the math.

This:

 else if ((temp_0 < tempHIGH3) && (temp_0 > tempLOW3))

Needs to change to this:

else if ((temp_0 < tempOKmax3) && (temp_0 > tempOKmin3))

The math should be:

tempHIGH3 (minus) - 1 = OKmax3
tempLOW3 (plus) + 1 = OKmin3
  1. 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.

Can you explain a bit more about the logic of these 4 temperature values, in plain English, not in pseudo code?

Pete.

post your full code also, not just chunks.

i have a min/max code that could work…

float rawSensor1;
float tempMinSensor1;
float tempMaxSensor1;
float newTempSensor1;
int resetMinMax;

BLYNK_WRITE(V3)   // reset min/max temps
{
  resetMinMax = param.asInt();
  if (resetMinMax == 1)
  {
    Blynk.virtualWrite(V5, 0);
    Blynk.virtualWrite(V11, 0);
  }
}

void readSensorFunction1()// this function gets the temps from the DS18B sensors
{
  sensor1.requestTemperatures();
  rawSensor1 = sensor1.getTempCByIndex(0);
  newTempSensor1 = rawSensor1;
  Blynk.virtualWrite(V21, rawSensor1);

  if (resetMinMax == 1)
  {
    tempMinSensor1 = 50;
    tempMaxSensor1 = 0;
  }
  if (tempMinSensor1 <= newTempSensor1)
  {
    tempMinSensor1 = tempMinSensor1;
  }
  else if (tempMinSensor1 > newTempSensor1)
  {
    tempMinSensor1 = newTempSensor1;
    Blynk.virtualWrite(V5, tempMinSensor1);
  }
  if (tempMaxSensor1 >= newTempSensor1)
  {
    tempMaxSensor1 = tempMaxSensor1;
  }
  else if (tempMaxSensor1 < newTempSensor1)
  {
    tempMaxSensor1 = newTempSensor1;
    Blynk.virtualWrite(V11, tempMaxSensor1);
  }
}