ERROR MESSAGE

I got this message when I upload my source code to Mega.

Error; a function-definition is not allowed here before '{' token

You can find the problem with bold letter near void loop

/*
PUMP CONTROL SYSTEM

*/

#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>

int led2 = 24;
int led3 = 26;
int led4 = 28;
int led5 = 30;
int led6 = 32;
int led7 = 34;
int led8 = 36;
int led9 = 38;
OneWire ds(2);

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 0, 66 }; // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;

void setup() {

// 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.println("Dallas Temperature IC Control Library Demo");
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
pinMode(led9, OUTPUT);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}

void loop(void)
{
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;

if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(250);
return;
}

Serial.print("ROM =");
for( i = 0; i < 8; i++) {
Serial.write(' ');
Serial.print(addr*, HEX);*

  • }*
  • if (OneWire::crc8(addr, 7) != addr[7]) {*
  • Serial.println("CRC is not valid!");*
  • return;*
  • }*
  • Serial.println();*
  • // the first ROM byte indicates which chip*
  • switch (addr[0]) {*
  • case 0x10:*
  • Serial.println(" Chip = DS18S20"); // or old DS1820*
  • type_s = 1;*
  • break;*
  • case 0x28:*
  • Serial.println(" Chip = DS18B20");*
  • type_s = 0;*
  • break;*
  • case 0x22:*
  • Serial.println(" Chip = DS1822");*
  • type_s = 0;*
  • break;*
  • default:*
  • Serial.println("Device is not a DS18x20 family device.");*
  • return;*
  • }*
  • ds.reset();*
  • ds.select(addr);*
  • ds.write(0x44); // start conversion, use ds.write(0x44,1) with parasite power on at the end*
  • delay(1000); // maybe 750ms is enough, maybe not*
  • // we might do a ds.depower() here, but the reset will take care of it.*
  • present = ds.reset();*
  • ds.select(addr); *
  • ds.write(0xBE); // Read Scratchpad*
  • Serial.print(" Data = ");*
  • Serial.print(present, HEX);*
  • Serial.print(" ");*
  • for ( i = 0; i < 9; i++) { // we need 9 bytes*
    _ data = ds.read();_
    _ Serial.print(data*, HEX);
    Serial.print(" ");
    }
    Serial.print(" CRC=");
    Serial.print(OneWire::crc8(data, 8), HEX);
    Serial.println();
    // Convert the data to actual temperature*
    * // because the result is a 16 bit signed integer, it should*
    * // be stored to an "int16_t" type, which is always 16 bits*
    * // even when compiled on a 32 bit processor._
    int16_t raw = (data[1] << 8) | data[0];
    if (type_s) {
    _ raw = raw << 3; // 9 bit resolution default*
    * if (data[7] == 0x10) {
    // "count remain" gives full 12 bit resolution*
    * raw = (raw & 0xFFF0) + 12 - data[6];
    }
    } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them*
    * if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms*
    * else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms*
    * else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms*
    * //// default is 12 bit resolution, 750 ms conversion time*
    * }
    celsius = (float)raw / 16.0;
    fahrenheit = celsius * 1.8 + 32.0;
    Serial.print(" Temperature = ");
    Serial.print(celsius);
    Serial.print(" Celsius, ");
    Serial.print(fahrenheit);
    Serial.println(" Fahrenheit");
    // Create a client connection*
    * EthernetClient client = server.available();
    if (client) {
    while (client.connected()) {
    if (client.available()) {
    char c = client.read();*_

* //read char by char HTTP request*
* if (readString.length() < 100) {*
* //store characters to string*
* readString += c;*
* //Serial.print(c);*
* }*
* //if HTTP request has ended*
* if (c == '\n') { *
* Serial.println(readString); //print to serial monitor for debuging*

* client.println("HTTP/1.1 200 OK"); //send new page*
* client.println("Content-Type: text/html");*
* client.println(); *
* client.println("Refresh: 5");*
* client.println("");*
* client.println("");*
* client.println("");*
* client.println("");*
* client.println("");*
* client.println("PUMP CONTROL SYSTEM");*
* client.println("");*
* client.println("");*
* client.println("

PUMP CONTROL SYSTEM

");*
* client.println("
");*

* client.println("*
*"); *
* client.println("

169-1

");*

* client.println("*
*"); *
* client.println("<a href="/?button1off"">Turn OFF PUMP1");*
* client.println("<a href="/?button1on"">Turn ON PUMP1*
*"); *
* client.println("*
*"); *
* client.println("*
");
* client.println("<a href="/?button2off"">Turn OFF PUMP2");*
* client.println("<a href="/?button2on"">Turn ON PUMP2*
");
* client.println("*
*"); *
* client.println("*
");
* client.println("<a href="/?button3off"">Turn OFF PUMP3");*
* client.println("<a href="/?button3on"">Turn ON PUMP3*
");
* client.println("*
*"); *
* client.println("*
");
* client.println("<a href="/?button4off"">Turn OFF PUMP4");*
* client.println("<a href="/?button4on"">Turn ON PUMP4*
");
* client.println("*
*"); *
* client.println("*
");
* client.println("<a href="/?button5off"">Turn OFF PUMP5");*
* client.println("<a href="/?button5on"">Turn ON PUMP5*
");
* client.println("*
*"); *
* client.println("*
");
* client.println("<a href="/?button6off"">Turn OFF PUMP6");*
* client.println("<a href="/?button6on"">Turn ON PUMP6*
");
* client.println("*
*"); *
* client.println("*
");
* client.println("<a href="/?button7off"">Turn OFF PUMP7");*
* client.println("<a href="/?button7on"">Turn ON PUMP7*
");
* client.println("*
*"); *
* client.println("*
");
* client.println("<a href="/?button8off"">Turn OFF PUMP8");*
* client.println("<a href="/?button8on"">Turn ON PUMP8*
*"); *
* client.println("*
*"); *
* client.println("*
");

* client.println("");*
* client.println("

");*
* client.print("FARM_1");
_ client.println("

");
client.println("

");
client.print("Temperature and Humidity");
client.println("

");
client.println("

");
client.print("tempC : ");
client.print(celsius);
client.print("0");
client.print("C");
client.println("
");
client.print("Humidity : ");
client.print(celsius);
client.print("%");
---------------------------------------------------
}
}
}
}
}
}*_

Where does your setup function end?

Hopefully you can now see why we ask you to use code tags when you post code.

 ---------------------------------------------------
        }

I bet the compiler isn't too keen on that either.

You're not uploading your code, because your code does not compile.

first, spend a little time and read the instructions "how to post...." in main "Programming Question" page. Most significant is the way to post your code so to be easily readable (code tags, button "</>" on top of posting page).

then, use the "tools/autoformat" so your code gets a meaningfull appearance

after that that, im sure you will see by yourself that there are stray or missing { or } or;

I think the problem is here:

 while (!Serial) {
  ; // wait for serial port to connect. Needed for Leonardo only

Just add closing curly brackets after the second line.

GRuser:
first, spend a little time and read the instructions "how to post...." in main "Programming Question" page. Most significant is the way to post your code so to be easily readable (code tags, button "</>" on top of posting page).

then, use the "tools/autoformat" so your code gets a meaningfull appearance

after that that, im sure you will see by yourself that there are stray or missing { or } or;

I was unable to post full code with that feature as it exceed 9k character which is maximum of the post.

What shoul I do?

You should read the replies already given

You should balance the opening and closing curly ({}) braces of your sketch in the following style; where, the opening brace({) is aligned with the closing brace (}).

void setup() 
{
   // 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.println("Dallas Temperature IC Control Library Demo");
   pinMode(led2, OUTPUT);
   pinMode(led3, OUTPUT);
   pinMode(led4, OUTPUT);
   pinMode(led5, OUTPUT);
   pinMode(led6, OUTPUT);
   pinMode(led7, OUTPUT);
   pinMode(led8, OUTPUT);
   pinMode(led9, OUTPUT);
   // start the Ethernet connection and the server:
   Ethernet.begin(mac, ip, gateway, subnet);
   server.begin();
   Serial.print("server is at ");
   Serial.println(Ethernet.localIP());
}

In the above codes, there are two opening braces and only one closing brace. There is an imbalance which should be corrected by placing the missing one at the appropriate place. It has been brought to your attention in Post#3.