unexpected unqualified-id before '{' token

I am new to the forum and unfortunately I have a limited knowledge of the C/C++ languages. My programming experiences date back to the days of Fortran so this is new ground for me.

I am attempting to develop a data logging system to monitor my greenhouse using two one wire devices, two humidity sensors and a real time clock storing the data to a SD card. I have successfully developed the code sets to read the one wire temperature sensors, to read the humidity sensors, to store the readings SD card and to get the time from the real time clock as separate code sets. The combined codes for reading the one wire sensors, humidity sensors and storing the reading to a SD card compiles and works as designed.

When I add the real time clock code set to the working combined code set and attempt to compile it I keep getting an “unexpected unqualified-id before ‘{’ token” error. I have attached a screen shot showing the error and a listing of the combined code.

Any assistance in helping me find what is causing the error will be most appreciated.

Dan

Okay, screen shots stink.
Use the code tag button </> and copy paste in your code so it looks

like this

Are you using a Leonardo? If not, that initial while section can removed.

Something is missing from what is clearly supposed to be your setup() function...

// COMBINED CODE SETS

/-------------------------------------/
/----------- FILE INFO ---------------/
/-------------------------------------/

// File_Name_No_5_Greenhouse_DUAL_TEMP_HUMIDITY_10232017
// Datalogger with the Arduino Ethernet Shield on MEGA Board
// Reads sensors and writes reading to SD card

/-------------------------------------/
/------ LIBRARIES & DEFINITIONS ------/
/-------------------------------------/

// ----- INCLUDED LIBRARIES -----//
// Include libraries
#include <SD.h>
#include <SPI.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <DHT.h>
#include <Adafruit_Sensor.h>

//*********************** FROM CLOCK CODE *************************

//READ REAL TIME CLOCK - RUNS ON UNO AND MEGA BOARD
#include <Wire.h>
#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return( (val/1016) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return( (val/16
10) + (val%16) );
}

//*********************** END FROM CLOCK *********************

//-----DEFINE LOOP INTERVALS -----//
// Systematic Loop Interval - 2 Seconds
const int LOOPINTERVAL = 6000;
// Log Interval - 30 Minutes
// const int LOGINTERVAL = 108000;

// — ONE WIRE SENSORS — //
//Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3
//Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
//Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

//Assign the addresses of your 1-Wire temp sensors.
//See the tutorial on how to obtain these addresses:
//http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
DeviceAddress insideThermometer = {0x10, 0xC8, 0x5E, 0x21, 0x02, 0x08, 0x00, 0x34 };
DeviceAddress outsideThermometer = { 0x10, 0xB7, 0x6A, 0x21, 0x02, 0x08, 0x00, 0x13 };

// — DHT11 SENSORS — //
#define DHTPIN1 6
#define DHTPIN2 7
#define DHTTYPE DHT11
DHT dhtSensor1(DHTPIN1, DHTTYPE);
DHT dhtSensor2(DHTPIN2, DHTTYPE);

// — GlOBAL VARS — //
float tempC_inside;
float tempF_inside;
float tempC_outside;
float tempF_outside;
float fHumidity1;
float fHumidity2;

/------- from SD Test Code ---------/
const int chipSelect = 4;
File dataFile;
/------- from SD Test Code ---------/

/-----------------------------------/
/--------------SETUP----------------/
/-----------------------------------/

void setup(void)

//*********************** FROM CLOCK CODE *************************

{
Wire.begin();
Serial.begin(9600);
}

void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
// request seven bytes of data from DS3231 starting from register 00h
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());

}
void displayTime()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// retrieve data from DS3231
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
&year);
Serial.println();
// send it to the serial monitor
Serial.print(hour, DEC);
// convert the byte variable to a decimal number when displayed
Serial.print(":");
if (minute<10)
{
Serial.print(“0”);
}
Serial.print(minute, DEC);
Serial.print(":");
if (second<10)
{
Serial.print(“0”);
}
Serial.print(second, DEC);
Serial.print(" “);
//Serial.print(dayOfMonth, DEC);
Serial.print(month, DEC);
Serial.print(”/");
//Serial.print(month, DEC);
Serial.print(dayOfMonth, DEC);
Serial.print("/");
Serial.print(year, DEC);
Serial.print(" Day of week: ");
switch(dayOfWeek){
case 1:
Serial.println(“Sunday”);
break;
case 2:
Serial.println(“Monday”);
break;
case 3:
Serial.println(“Tuesday”);
break;
case 4:
Serial.println(“Wednesday”);
break;
case 5:
Serial.println(“Thursday”);
break;
case 6:
Serial.println(“Friday”);
break;
case 7:
Serial.println(“Saturday”);
break;
}
}

//*********************** END FROM CLOCK *********************

{
Serial.begin(9600);
delay(250);
Serial.println(“Greenhouse V5”);

// Initialize DHT sensor
dhtSensor1.begin();
dhtSensor2.begin();

/------- from SD Test Code ---------/
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only

}

Serial.print(“Initializing SD card…”);
// make sure that the default chip select pin is set to
// output, even if you don’t use it:
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);

// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println(“Card failed, or not present”);
// don’t do anything more:
while (1) ;
}
Serial.println(“card initialized.”);

// Open up the file we’re going to log to!
dataFile = SD.open(“datalog.txt”, FILE_WRITE);
if (! dataFile) {
Serial.println(“error opening datalog.txt”);
// Wait forever since we cant write data
while (1) ;
}

}
/------- from SD Test Code ---------/

// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(insideThermometer, 10);
sensors.setResolution(outsideThermometer, 10);

Serial.println(“Setup has Finished”);
}

/-----------------------------------/
/---------------LOOP----------------/
/-----------------------------------/
void loop(void)
{
delay(LOOPINTERVAL);

sensors.requestTemperatures();

// OneWire Sensor - Inside Greenhouse
tempC_inside = sensors.getTempC(insideThermometer);
tempF_inside = DallasTemperature::toFahrenheit(tempC_inside);
if (tempC_inside == -127.00)
{
Serial.print(“Error getting temperature: Inside OneWire”);
}
else
{
Serial.print("Inside Greenhouse temperature is: ");
//Serial.print("C: “);
// Serial.print(tempC_inside);
Serial.print(tempF_inside);
Serial.println(” F ");
}

// OneWire Sensor - Outside Greenhouse
tempC_outside = sensors.getTempC(outsideThermometer);
tempF_outside = DallasTemperature::toFahrenheit(tempC_outside);
if (tempC_outside == -127.00)
{
Serial.print(“Error getting temperature: Outside OneWire”);
}
else
{
Serial.print("Outside Greenhouse temperature is: ");
//Serial.print(“C: “);
//Serial.print(tempC_outside);
Serial.print(tempF_outside);
Serial.println(” F”);
}

// GET DHT SENSOR HUMIDITY READINGS
fHumidity1 = dhtSensor1.readHumidity();
fHumidity2 = dhtSensor2.readHumidity();

Serial.print(“Inside Greehouse Humidity is: “);
Serial.print(fHumidity1);
Serial.print(”%”);
Serial.println();
Serial.print(“Outside Greenhoue Humidity is: “);
Serial.print(fHumidity2);
Serial.print(”%”);
Serial.println();
Serial.println();

/* Write readings to file /
dataFile.print(tempF_inside);
dataFile.print(",");
dataFile.print(tempF_outside);
dataFile.print(",");
dataFile.print(fHumidity1);
dataFile.print(",");
dataFile.println(fHumidity2);
dataFile.flush();
delay(1000);
//
****************************** FROM CLOCK CODE ***********************
{
displayTime(); // display the real-time clock data on the Serial Monitor,
delay(1000); // every second
}
//******************************* END FROM CLOCK CODE *******************

}

Why make it such a pain to help you? Please post your code in code tags like requested in reply #1. Please post the entire error message. That is made easier by the button on the top right of the console labeled "copy error message" Then paste the error between code tags. The error message has clues where to look for the error(s). Without the whole error message we have to search through the code in hopes of spotting it. Or, if we have all of the libraries (which I don't), we can compile the code to find the error.

Looking at the code, it seems that you stuck a couple of function definitions in the middle of setup(). You do close setup() and then define readDS3231time and displayTime then there is more stuff that should be in setup() that is not in any function.

I apologize for the problems in my attempt to post the code and error. This is the first time I have attempted to post on the forum so this all new to me. Thanks to everyone responding to my post.

The code is posted with tags as requested. The complete error message is listed in the next posted message. I have placed a comment in the code just above the line that was flagged as an error when I attempted to compile the code.

Dan

//GREENHOUSE DATA LOGGER

/*-------------------------------------*/
/*----------- FILE INFO ---------------*/
/*-------------------------------------*/

// File_Name_No_5_Greenhouse_DUAL_TEMP_HUMIDITY_10232017
// Datalogger with the Arduino Ethernet Shield on MEGA Board
// Reads sensors and writes reading to SD card


/*-------------------------------------*/
/*------ LIBRARIES & DEFINITIONS ------*/
/*-------------------------------------*/

// -----  INCLUDED LIBRARIES  -----//
// Include libraries
#include <SD.h>
#include <SPI.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <DHT.h>
#include <Adafruit_Sensor.h>

//*********************** FROM CLOCK CODE *************************

//READ REAL TIME CLOCK - RUNS ON UNO AND MEGA BOARD
#include <Wire.h>
#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}


//*********************** END FROM CLOCK *********************

//-----DEFINE LOOP INTERVALS  -----//
// Systematic Loop Interval - 2 Seconds
  const int LOOPINTERVAL = 6000;
// Log Interval - 30 Minutes
//  const int LOGINTERVAL = 108000; 
  
    
// --- ONE WIRE SENSORS --- //
  //Data wire is plugged into pin 3 on the Arduino
  #define ONE_WIRE_BUS 3
  //Setup a oneWire instance to communicate with any OneWire devices
  OneWire oneWire(ONE_WIRE_BUS);
  //Pass our oneWire reference to Dallas Temperature.
  DallasTemperature sensors(&oneWire);

  //Assign the addresses of your 1-Wire temp sensors.
  //See the tutorial on how to obtain these addresses:
  //http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
  DeviceAddress insideThermometer = {0x10, 0xC8, 0x5E, 0x21, 0x02, 0x08, 0x00, 0x34  };
  DeviceAddress outsideThermometer = { 0x10, 0xB7, 0x6A, 0x21, 0x02, 0x08, 0x00, 0x13 };
  
  
// --- DHT11 SENSORS --- //
  #define DHTPIN1 6
  #define DHTPIN2 7
  #define DHTTYPE DHT11
  DHT dhtSensor1(DHTPIN1, DHTTYPE);
  DHT dhtSensor2(DHTPIN2, DHTTYPE);
  
  
  
// --- GlOBAL VARS --- //
  float tempC_inside;
  float tempF_inside;
  float tempC_outside;
  float tempF_outside;
  float fHumidity1;
  float fHumidity2;
  
/*------- from SD Test Code ---------*/  
  const int chipSelect = 4;
  File dataFile;
/*------- from SD Test Code ---------*/  
 
 
/*-----------------------------------*/
/*--------------SETUP----------------*/
/*-----------------------------------*/

void setup(void)

//*********************** FROM CLOCK CODE *************************

{
  Wire.begin();
  Serial.begin(9600);
}

void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
  

}
void displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  Serial.println();
  // send it to the serial monitor
  Serial.print(hour, DEC);
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
  if (minute<10)
  {
    Serial.print("0");
  }
  Serial.print(minute, DEC);
  Serial.print(":");
  if (second<10)
  {
    Serial.print("0");
  }
  Serial.print(second, DEC);
  Serial.print(" ");
  //Serial.print(dayOfMonth, DEC);
  Serial.print(month, DEC);
  Serial.print("/");
  //Serial.print(month, DEC);
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(year, DEC);
  Serial.print(" Day of week: ");
  switch(dayOfWeek){
  case 1:
    Serial.println("Sunday");
    break;
  case 2:
    Serial.println("Monday");
    break;
  case 3:
    Serial.println("Tuesday");
    break;
  case 4:
    Serial.println("Wednesday");
    break;
  case 5:
    Serial.println("Thursday");
    break;
  case 6:
    Serial.println("Friday");
    break;
  case 7:
    Serial.println("Saturday");
    break;
  }
}



//*********************** END FROM CLOCK *********************
//----------  THE NEXT LINE IS THE LINE FLAGGED AS THE  ERROR ----------

  {
  Serial.begin(9600);
  delay(250);
  Serial.println("Greenhouse V5");
  
   
  // Initialize DHT sensor
  dhtSensor1.begin();
  dhtSensor2.begin();

  /*------- from SD Test Code ---------*/  
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
    
  }


  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1) ;
  }
  Serial.println("card initialized.");
  
  // Open up the file we're going to log to!
  dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (! dataFile) {
    Serial.println("error opening datalog.txt");
    // Wait forever since we cant write data
    while (1) ;
  }

    } 
  /*------- from SD Test Code ---------*/  

  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(insideThermometer, 10);
  sensors.setResolution(outsideThermometer, 10);
  
  Serial.println("Setup has Finished");
}


/*-----------------------------------*/
/*---------------LOOP----------------*/
/*-----------------------------------*/
void loop(void)
{
  delay(LOOPINTERVAL);
  
  sensors.requestTemperatures();
  
  // OneWire Sensor - Inside Greenhouse
  tempC_inside = sensors.getTempC(insideThermometer);
  tempF_inside = DallasTemperature::toFahrenheit(tempC_inside);
  if (tempC_inside == -127.00) 
  {
    Serial.print("Error getting temperature: Inside OneWire");
  } 
  else
  {
    Serial.print("Inside Greenhouse temperature is: ");
    //Serial.print("C: ");
   // Serial.print(tempC_inside);
    Serial.print(tempF_inside);
    Serial.println(" F ");
  }
  
  
  // OneWire Sensor - Outside Greenhouse
  tempC_outside = sensors.getTempC(outsideThermometer);
  tempF_outside = DallasTemperature::toFahrenheit(tempC_outside);
  if (tempC_outside == -127.00) 
  {
    Serial.print("Error getting temperature: Outside OneWire");
  } 
  else
  {
    Serial.print("Outside Greenhouse temperature is: ");
    //Serial.print("C: ");
    //Serial.print(tempC_outside);   
    Serial.print(tempF_outside);
    Serial.println(" F");
  }

  // GET DHT SENSOR HUMIDITY READINGS
  fHumidity1 = dhtSensor1.readHumidity();
  fHumidity2 = dhtSensor2.readHumidity();

  Serial.print("Inside Greehouse Humidity is: ");
  Serial.print(fHumidity1);
  Serial.print("%");
  Serial.println();
  Serial.print("Outside Greenhoue Humidity is: ");
  Serial.print(fHumidity2);
  Serial.print("%");
  Serial.println();
  Serial.println();
 
  /* Write readings to file */
    dataFile.print(tempF_inside);
    dataFile.print(",");
    dataFile.print(tempF_outside);
    dataFile.print(",");
    dataFile.print(fHumidity1);
    dataFile.print(",");
    dataFile.println(fHumidity2);
    dataFile.flush();
    delay(1000);
//******************************* FROM CLOCK CODE ***********************
    {
  displayTime(); // display the real-time clock data on the Serial Monitor,
  delay(1000); // every second
    }
//******************************* END FROM CLOCK CODE *******************

}

Complete error message is listed below.

C:\Users\rdbro\OneDrive\Documents\Arduino\libraries\Adafruit_Sensor-master/Adafruit_Sensor.h:146:37: warning: unused parameter 'enabled' [-Wunused-parameter]

virtual void enableAutoRange(bool enabled) {};

^

No_5_Greenhouse_DUAL_TEMP_HUMIDITY_10232017-V5:189: error: expected unqualified-id before '{' token

{

^

Multiple libraries were found for "SD.h"
Used: C:\Program Files (x86)\Arduino\libraries\SD
Not used: C:\Users\rdbro\OneDrive\Documents\Arduino\libraries\SD-master
Using library Adafruit_Sensor-master at version 1.0.2 in folder: C:\Users\rdbro\OneDrive\Documents\Arduino\libraries\Adafruit_Sensor-master
Using library SD at version 1.1.1 in folder: C:\Program Files (x86)\Arduino\libraries\SD
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI
Using library Arduino-Temperature-Control-Library-master at version 3.7.7 in folder: C:\Users\rdbro\OneDrive\Documents\Arduino\libraries\Arduino-Temperature-Control-Library-master
Using library OneWire-master at version 2.3.3 in folder: C:\Users\rdbro\OneDrive\Documents\Arduino\libraries\OneWire-master
Using library DHT-sensor-library-master at version 1.3.0 in folder: C:\Users\rdbro\OneDrive\Documents\Arduino\libraries\DHT-sensor-library-master
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire
exit status 1
expected unqualified-id before '{' token

You will need to fix the problem that I pointed out in reply#5 before there is a chance of the code to compile. Move the short bit of setup() that is before those function definitions to where you noted the error and fix the braces.

Why Serial.begin() 3 times?

Thanks for the help.

Dan