"" was not declared in this scope

I have a number of error messages popping up and I’m wondering somebody could give me a pointer to solving them.

Error Build error: expected primary-expression before ‘)’ tokene 127:12
Error GCC expected primary-expression before ‘)’ token 127:12
Error Build error: expected primary-expression before ‘;’ tokene 149:39
Error GCC expected primary-expression before ‘;’ token 149:39
Error Build error: expected unqualified-id before ‘{’ tokene 341:3
Error GCC expected unqualified-id before ‘{’ token 341:3
Error Build error: expected unqualified-id before ‘)’ tokene 348:17
Error GCC expected unqualified-id before ‘)’ token 348:17

Compiling .pioenvs\esp32dev\src\main.o
src\main.cpp:339:54: error: macro “dewPointFast” passed 2 argum
ents, but takes just 0
double dewPointFast(double celsius, double humidity)

I have tried adding
#define dewPointFast() that helped but didn’t work so then tried
#define dewPointFast(temp,humid) didn’t work so then tried
#define dewPointFast(celsius,humidity) that was a bit better but put up an error in the code
dPt = dewPointFast(celsius,humidity);
error: expected primary-expression before ‘;’ token

I have done similar things with the error bmp_read and getting very frustrated not knowing exactly what it’s asking for.

I will try uploading the whole programme

#include <Arduino.h>
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <Wire.h>
#include <Adafruit_BMP280.h>
#include <DHT.h>

#define bmp_read
#define dewPointFast(celsius,humidity)
//#define bmp_read
#define LED_BUILTIN 15
Adafruit_BMP280 bme;
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
const char* ssid = “BTHub5-RKSM”;
const char* password = “**********”;
WiFiServer server(80);
String theme = “darkly”;
#define LED_BUILTIN2 2
int val=0;
// DHT Sensor
const int DHTPin = 16;
// Initialize DHT sensor.
DHT dht(DHTPin, DHTTYPE);

// Temporary variables
static char celsiusTemp[7];
static char fahrenheitTemp[7];
static char humidityTemp[7];

// Client variables
char linebuf[80];
int charcount=0;
float dht_t,dht_h,dht_f;
float bmp_p,bmp_t,bmp_a;
float hif,hic,h,f,dPt;
float temp2;
int lightpin = A0;
int lightv = 0;
int light2;
float humid,temp,fahr;

void setup() {
dht.begin();
Serial.begin(115200);
Serial.println(“Booting”);
//WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
//delay(1000);
//IPAddress Ip(192, 168, 1, 202);
// IPAddress NMask(255, 255, 255, 0);
//WiFi.softAPConfig(Ip, Ip, NMask);
//IPAddress myIP = WiFi.softAPIP();
//Serial.print("IP address: ");
//Serial.println(myIP);

while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println(“Connection Failed! Rebooting…”);
delay(1500);
ESP.restart();
}
server.begin();

// Port defaults to 3232
// ArduinoOTA.setPort(3232);

// Hostname defaults to esp3232-[MAC]
// ArduinoOTA.setHostname(“myesp32”);

// No authentication by default
// ArduinoOTA.setPassword(“admin”);

// Password can be set with it’s md5 value as well
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
// ArduinoOTA.setPasswordHash(“21232f297a57a5a743894a0e4a801fc3”);

ArduinoOTA
.onStart( {
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = “sketch”;
else // U_SPIFFS
type = “filesystem”;

  // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
  Serial.println("Start updating " + type);
})
.onEnd([]() {
  Serial.println("\nEnd");
})
.onProgress([](unsigned int progress, unsigned int total) {
  Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
})
.onError([](ota_error_t error) {
  Serial.printf("Error[%u]: ", error);
  if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
  else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
  else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
  else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
  else if (error == OTA_END_ERROR) Serial.println("End Failed");
});

ArduinoOTA.begin();

Serial.println(“Ready”);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

pinMode(LED_BUILTIN, OUTPUT);
pinMode(LED_BUILTIN2, OUTPUT);
if (!bme.begin()) {
Serial.println(“Could not find a valid BMP280 sensor, check wiring!”);
while (1);
}

}

void loop() {
// ArduinoOTA.handle();
ArduinoOTA.handle();
for(int i = 0; i< 15; i++){
delay(200);
ArduinoOTA.handle();}

bmp_read();
lightv=analogRead(lightpin);
light2=lightv/10;
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
humid = dht.readHumidity();
// Read temperature as Celsius (the default)
temp = dht.readTemperature();
temp2=temp*2;
// Read temperature as Fahrenheit (isFahrenheit = true)
fahr = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(humid) || isnan(temp) || isnan(fahr)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}

// Compute heat index in Fahrenheit (the default)
hif = dht.computeHeatIndex(fahr, humid);
// Compute heat index in Celsius (isFahreheit = false)
hic = dht.computeHeatIndex(temp, humid, false);
dPt = dewPointFast(celsius,humidity);
Serial.println(“*************************”);
Serial.print("Dew PointFast (°C): ");
Serial.println(dPt);
Serial.print("Temperature (°C) : ");
Serial.println(temp, 2);
Serial.print("Temperature (°F) : ");
Serial.println((float)fahr, 2);
Serial.print("Humidity (%) : ");
Serial.println(humid, 2);
Serial.print(“Heat Index : “);
Serial.print(hic);
Serial.print(” (C) “);
Serial.print(hif);
Serial.println(” (F)”);
Serial.print(“Light (%) : “);
Serial.println(lightv);
Serial.println(””);
Serial.print("T: “);
Serial.print(bmp_t,2);
Serial.print(” P: “);
Serial.print(bmp_t,2);
Serial.print(” A: ");
Serial.print(bmp_a,2);

WiFiClient client = server.available();
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println(“Connection: close”); // the connection will be closed after completion of the response//

client.println();
client.println(“”);

client.println(“”);

client.println(“”);
client.println(“”);

client.println(“ESP8266 & DHT22 Sensor LoRa ”);

client.println(“\n”);

client.println(“

”);
client.println(“
”);
client.println(“
”);
client.println(“

ESP8266 & DHT22 Sensor LoRa

”);
client.println(“
”);
client.println(“
”);
client.print(“Humidity (%) : “);
client.println(humid, 2);
client.print(“Temperature (C) : “);
client.println(temp, 2);
client.print(“Temperature (F) : “);
client.println((float)fahr, 2);
client.print(“Heat Index : “);
client.print(hic);
client.print(” (C) “);
client.print(hif);
client.println(” (F)”);
client.print(“Dew PointFast (C) : “);
client.println(dPt);
client.print(“Light (%) : “);
client.println(lightv);
client.println(”
”);
client.println(”
”);
client.println(”
”);
client.println(”
”);
client.println(””);
client.println(“”);

client.println(“”);
client.println(“”);
client.println(“* {box-sizing: border-box}”);

client.println(“.container {”);
client.println(“width: 100%;”);
client.println(“background-color: #1c1c23;”);
client.println(“}”);

client.println(“.skills {”);
client.println(“text-align: center;”);
client.println(“padding-right: 20px;”);
client.println(" line-height: 20px;“);
//client.println(“color: white;”);
client.println(”}");

client.print(“.html {width: “);
client.print(humid, 2);
client.println(”%; background-color: #4CAF50;}”);

client.print(“.css {width: “);
client.print(temp2, 2);
client.println(”%; background-color: #2196F3;}”);

client.print(“.js {width: “);
client.print(light2);
client.println(”%; background-color: #f44336;}”);

client.println(“”);
client.println(“”);
client.println(“”);

client.println(“

Humidity

”);
client.println(“
”);
client.print(“
”);
client.print(humid, 2);
client.println(“%
”);
client.println(“
”);

client.println(“

Temperature

”);
client.println(“
”);
client.print(“
”);
client.print(temp, 2);
client.println(“C
”);
client.println(“
”);

client.println(“

Light

”);
client.println(“
”);
client.print(“
”);
client.print(lightv);
client.println(“%
”);
client.println(“
”);

/*
//client.println(“{”);
//client.println(“<background-color: lightblue;”);
//client.println(“}”);
client.println(“”);
client.println(“#myProgress {”);
client.println(“width: 100%;”);
client.println(“background-color: #ddd;”);
client.println(“}”);

client.println(“#myBar {”);
client.print(“width: “);
client.print(temp2, 2);
client.println(”%;”);

client.println(“height: 30px;”);
client.println(“background-color: #4CAF50;”);
client.println(“text-align: center;”);
client.println(“line-height: 30px;”);
client.println(“color: white;”);
client.println(“}”);

client.println(“”);
client.println(“”);

client.println(“

JavaScript Progress Bar

”);
client.println(“
”);
client.print("
“);
client.print(temp,2);
client.println(” C
“);
client.println(”
“);
*/
client.print(”\n");
}

double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double t = (a * celsius) / (b + celsius) + log(humidity*0.01);
double Td = (b * t) / (a - t);
return Td;
}
void bmp_read(){
// delay (500);
if (!bme.begin()) {
Serial.println(“Could not find a valid BMP280 sensor, check wiring!”);
while (1);
}
bmp_t=(bme.readTemperature());
bmp_t=bmp_t-1.65;
bmp_p =(bme.readPressure());
bmp_p=bmp_p/100;
bmp_a=(bme.readAltitude());
//Serial.print("T: ");
}

This is C++ error and has nothing to do with platformio. The problem you have is that you have the function double dewPointFast(double celsius, double humidity) but you somehow defined it as an empty macro mapping to nothing. Remove your macro definitions and instead put the function declarations there. Remember that the Arduino IDE automatically forward-declares all function at the beginning of the sketch. Platform-IO however does not do this, it just compiles it as regular C++ code, no pre-processing done.

In short: Remove #define dewPointFast... and #define bmp_read().. and put double dewPointFast(double celsius, double humidity); and void bmp_read(); declarations after the includes.

Thank you for coming back so quickly

I have now changed the code to double dewPointFast(double celsius, double humidity)
and it still comes up with the error: expected constructor, destructor, or type conversion before double.

Error GCC expected initializer before ‘double’ 11:1
Error Build error: expected initializer before 'double’e 11:1
Error GCC ‘bme’ was not declared in this scope 112:8
Error Build error: ‘bme’ was not declared in this scopee 112:8
Error GCC ‘bmp_read’ was not declared in this scope 127:12
Error Build error: ‘bmp_read’ was not declared in this scopee 127:12
Error Build error: ‘celsius’ was not declared in this scopee 149:22
Error GCC ‘celsius’ was not declared in this scope 149:22
Error Build error: ‘humidity’ was not declared in this scopee 149:30
Error GCC ‘humidity’ was not declared in this scope 149:30
Error Build error: ‘dewPointFast’ was not declared in this scopee 149:38
Error GCC ‘dewPointFast’ was not declared in this scope 149:38
Error Build error: ‘bme’ was not declared in this scopee 350:10
Error GCC ‘bme’ was not declared in this scope 350:10
Error Build error: ‘bme’ was not declared in this scopee 354:11
Error GCC ‘bme’ was not declared in this scope 354:11

Program now :
void bmp_read()
double dewPointFast(double celsius, double humidity)
//#define bmp_read

In C++. you need to end a function declaration with a semicolon, as I have posted it above. Add ; at the end of both declarations and report again.

Well there’s less errors this time:

Error Build error: ‘celsius’ was not declared in this scopee 149:22
Error GCC ‘celsius’ was not declared in this scope 149:22
Error Build error: ‘humidity’ was not declared in this scopee 149:30
Error GCC ‘humidity’ was not declared in this scope 149:30

I thought this would declare them:
// Temporary variables
static char celsiusTemp[7];
static char fahrenheitTemp[7];
static char humidityTemp[7];

thank you for your help again

Now the problem is that you do a function call to this dewPointFast() function with variables which do not exist. Now I can only guess what you meant to code there.

You have


for(int i=0; i < 15; i++) {
   humid = dht.readHumidity();
   temp = dht.readTemperature();
  //..
}
//...
//error: celsius and humidity are never declared
dPt = dewPointFast(celsius,humidity); 

You could use your temp and humid variables you have gotten before from your DHT sensor. So you could exchange the dPt = .. line with

dPt = dewPointFast(temp,humid); 

I can’t tell you if this the intended behaviour though. You are the programmer of this sketch and should know what you want to compute with what values.

1 Like

Sorry for the delay, and thank you again for all your help.
The Arduino held your hand a lot, on the other hand platformIO is showing you the real way of working.
The problem I have is realising that the Arduino IDE is not really c
on the other hand platformIO I assume is.

The problem being I do like platformio better than the Arduino
any suggestions for helping us migrate from one to the other?

http://docs.platformio.org/en/latest/faq.html#convert-arduino-file-to-c-manually