Ds18b20 Syntax error

Hello.
What is wrong?
I am trying to connect the display to BLYNK

Error:

C:\Users\xxx\Desktop\sketch_feb11a\sketch_feb11a.ino: In function ‘void temperatura()’:

sketch_feb11a:115: error: ‘getTemp’ was not declared in this scope

float temperature = getTemp();

exit status 1
‘getTemp’ was not declared in this scope

#include <SimpleTimer.h>
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C  lcd(0x27,2,1,0,4,5,6,7);
#define BACKLIGHT_PIN 3
#define ONE_WIRE_BUS 2        // This is the ESP8266 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DeviceAddress tempSensor1 = { 0x28, 0xFF, 0xD5, 0x1B, 0x80, 0x16, 0x05, 0x73 }; // Adres temperatury #1
DeviceAddress tempSensor2 = { 0x28, 0xFF, 0x72, 0x55, 0x80, 0x16, 0x05, 0xE4  }; // Adres temperatury #2


char auth[] = "xxxx";  // Kod BLYNK
char ssid[] = "xxxx";  // Login WIFI
char pass[] = "";    // Hasło WIFI 

SimpleTimer timer;
int pin = D2; // Pin cyfrowy krancówka
WidgetLED led1(V3); // Pin wirtualny krancowy
int pin2 = D3; // Pin cyfrowy krancówka
WidgetLED led2(V4); // Pin wirtualny krancowy
int pin3 = D4; // Pin cyfrowy krancówka
WidgetLED led3(V5); // Pin wirtualny krancowy 

int tempC1, tempC2;         // Variables for storing temperatures
BLYNK_CONNECTED() {
    Blynk.syncAll();
}
void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  while (Blynk.connect() == false) {
    // Wait until connected
    lcd.begin (16,2);
 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
 lcd.setBacklight(HIGH);

  lcd.setCursor(0, 0);
  lcd.print("Temp:");
    lcd.setCursor(11, 0);
  lcd.print(" ");
  lcd.write(0xDF);                    // Znak stopnia
  lcd.print("C ");
  }

  sensors.begin();
  timer.setInterval(1000L, brama1); //Sprawdzanie stanu
  timer.setInterval(1000L, brama2); //Sprawdzanie stanu
  timer.setInterval(1000L, brama3); //Sprawdzanie stanu
  sensors.setResolution(tempSensor1, 9);   // More on resolutions: http://www.homautomation.org/2015/11/17/ds18b20-how-to-change-resolution-9101112-bits/
  sensors.setResolution(tempSensor2, 9);
  // These timers are used so that data does not flood Blynk
  timer.setInterval(5000L, sendSensor1);  //  Czas pomiaru temperatury #1
  timer.setInterval(5000L, sendSensor2);  //  Czas pomiaru temperatury #2
}

void loop()
{
  Blynk.run();
  timer.run();
}



void sendSensor1() {
  sensors.requestTemperatures();                // Polls the sensors
  tempC1 = sensors.getTempC(tempSensor1);  // C - celsjusza / F - fahrenheita

  Blynk.virtualWrite(1, tempC1);  // 1 Pin wirtualny 
}

void sendSensor2() 
{
  sensors.requestTemperatures();
  tempC2 = sensors.getTempC(tempSensor2);

  Blynk.virtualWrite(2, tempC2);  // 2 Pin wirtualny 
}
  void brama1()
{
if(digitalRead(pin) == 1){
  led1.on();
}
else{
  led1.off();
}
}
void brama2()
{
if(digitalRead(pin2) == 1){
  led2.on();
}
else{
  led2.off();
}
}
void brama3()
{
if(digitalRead(pin3) == 1){
  led3.on();
}
else{
  led3.off();
}
}
void temperatura()
{
float temperature = getTemp();
  Serial.println(temperature);
  lcd.setCursor(6, 0); 
  lcd.print(temperature);

  
  delay(1000); //just here to slow down the output so it is easier to read
  
}
>

The compiler does not recognise the term getTemp, because is is not valid syntax for the library you are using.

Probably should be getTempC() or getTempF() Hard to say for sure without more digging and testing… but I will leave that for you.

I’m guessing you’ve kludged this code together from a variety of sources, without really understanding what you’re doing?

You have two global variables defined called tempC1 and tempC2. You’re reading the values from the two temperature sensors and storing the results in these two variables.

If you want to write one (or both) of these values to the display then don’t bother taking another reading, simply write the stored value(s) to the display.

The other issue you have is that you’ve declared these two global variables as integers rather than float variables. This means that you’re working with whole numbers rather than numbers with something after the decimal point. With temperature values you probably want to be displaying numbers that have one digit after the decimal point.
So, change these two global variables to float types, then once you’ve taken a reading round the results to one decimal place before doing anything else with them.

Pete.

3 Likes