Go Down

Topic: error message, weather station (HELP) (Read 120 times) previous topic - next topic

robert0430

I need help with this, i'm trying to make a weather station with Ethernet and the program runs good, temperature humidity, water level but not the windspeed, so i wonder if you could help me.

here is the program

Quote
// Incluimos librerías
#include <math.h>
#include <SPI.h>
#include <Ethernet.h>
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
#define WindSensorPin (3)
DHT dht(DHTPIN, DHTTYPE);

const int read = A0; //Sensor AO pin to Arduino pin A0
int value;          //Variable to store the incomming data

volatile unsigned long Rotations; // cup rotation counter used in interrupt routine
volatile unsigned long ContactBounceTime; // Timer to avoid contact bounce in interrupt routine

float WindSpeed; // speed miles per hour



//Declaración de la direcciones MAC e IP. También del puerto 80
byte mac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED}; //MAC
IPAddress ip(192,168,1,15); //IP
EthernetServer servidor(80);
String readString=String(30);



void setup() {
  Ethernet.begin(mac, ip); //Inicializamos con las direcciones asignadas
  servidor.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  Serial.begin(9600);
  dht.begin();
{
  pinMode(WindSensorPin, INPUT);
  attachInterrupt(digitalPinToInterrupt(WindSensorPin), rotation, FALLING);

  Serial.println("Wind Speed Test");
  Serial.println("Rotations\tMPH");
 
   }
}

void loop() {

EthernetClient cliente= servidor.available();
if(cliente) {
boolean lineaenblanco=true;
while(cliente.connected()) {

 if(cliente.available()) {
char c=cliente.read();
 Serial.write(c);
 if (c == '\n' && lineaenblanco) {
   
 value = analogRead(read); //Read data from analog pin and store it to value variable

 

  cliente.println("HTTP/1.1 200 OK");
  cliente.println("Content-Type: text/html");
  cliente.println("Connection: close");  // the connection will be closed after completion of the response
  cliente.println("Refresh: 5");  // refresh the page automatically every 5 sec
  cliente.println();
  cliente.println("<!DOCTYPE HTML>");
  cliente.println("<html>");
          // output the value of each analog input pin
  cliente.println("<font color=red size=20>");
  cliente.print("Protipo Para Monitoreo De Variables Meteorol&oacute;gicas ");
  cliente.println("<br />");
  cliente.println("<br />");
 

if(readString.length()<30) {
readString.concat(c);
//Cliente conectado
//Leemos petición HTTP caracter a caracter
//Almacenar los caracteres en la variable readString
}
if(c=='\n' && lineaenblanco) //Si la petición HTTP ha finalizado
{

int h = dht.readHumidity();// Lee la humedad
int t= dht.readTemperature();//Lee la temperatura


cliente.println("<font color=black size=13>");
//Humedad
cliente.println("<TABLE BORDER=6 CELLSPACING=5 WIDTH=800>");
cliente.println ("<TR align=center>");
cliente.println("<font color=black size=12>");
cliente.println("<tr>");
cliente.println("<td>");
cliente.print("Humedad Relativa: ");
cliente.println("</td>");
cliente.println("<td>");               
cliente.print(h);//Escribe la humedad
cliente.println(" %");   
cliente.println("</td>");
cliente.println("</tr>");               
delay (500);

//Temperatura       
cliente.println ("<TR align=center>");
cliente.println("<tr>");
cliente.println("<td>");     
cliente.print("Temperatura: ");
cliente.println("</td>");
cliente.println("<td>");                 
cliente.print(t);//Escribe la temperatura
cliente.println(" C'");     
cliente.println("</td>");
cliente.println("</tr>");             
delay (500);

//Pluviometro
if (value<=480){
    cliente.println("<tr>");
    cliente.println("<td>");
    cliente.println("Water level");
    cliente.println("<td>"); 
    cliente.println("Empty!");
    cliente.println("<tr>");
   
  }
  else if (value>480 && value<=530){
    cliente.println("<tr>");
    cliente.println("<td>");
    cliente.println("Water level");
    cliente.println("<td>");
    cliente.println("0mm to 5mm");
    cliente.println("<tr>");
  }
  else if (value>530 && value<=615){
    cliente.println("<tr>");
    cliente.println("<td>");
    cliente.println("Water level");
    cliente.println("<td>");
    cliente.println("5mm to 10mm");
    cliente.println("<tr>");
  }
  else if (value>615 && value<=660){
    cliente.println("<tr>");
    cliente.println("<td>");
    cliente.println("Water level");
    cliente.println("<td>");
    cliente.println("10mm to 15mm");
    cliente.println("<tr>");
  }
  else if (value>660 && value<=680){
    cliente.println("<tr>");
    cliente.println("<td>"); 
    cliente.println("Water level");
    cliente.println("<td>");
    cliente.println("15mm to 20mm");
    cliente.println("<tr>");
  }
  else if (value>680 && value<=690){
    cliente.println("<tr>");
    cliente.println("<td>");
    cliente.println("Water level");
    cliente.println("<td>");
    cliente.println("20mm to 25mm");
    cliente.println("<tr>");
  }
  else if (value>690 && value<=700){
    cliente.println("<tr>");
    cliente.println("<td>");
    cliente.println("Water level");
    cliente.println("<td>");
    cliente.println("25mm to 30mm");
    cliente.println("<tr>");
  }
  else if (value>700 && value<=705){
    cliente.println("<tr>");
    cliente.println("<td>");
    cliente.println("Water level");
    cliente.println("<td>");
    cliente.println("30mm to 35mm");
    cliente.println("<tr>");
  }
  else if (value>705){
    cliente.println("<tr>");
    cliente.println("<td>");
    cliente.println("Water level");
    cliente.println("<td>");
    cliente.println("35mm to 40mm");
    cliente.println("<tr>");
  }
 
    delay(500); // Check for new value every 5 sec
 
//Velocidad del viento MPH

 

Rotations = 0; // Set Rotations count to 0 ready for calculations

sei(); // Enables interrupts
delay (3000); // Wait 3 seconds to average
cli(); // Disable interrupts

// convert to mp/h using the formula V=P(2.25/T)
// V = P(2.25/3) = P * 0.75

WindSpeed = Rotations * 0.75;

cliente.print(Rotations);
cliente.print("\t\t");
cliente.println(WindSpeed);


 
// This is the function that the interrupt calls to increment the rotation count
void rotation () {
{
if ((millis() - ContactBounceTime) > 15 ) { // debounce the switch contact.
Rotations++;
ContactBounceTime = millis();
}

   
}

}

cliente.stop();
//Cierro conexión con el cliente
readString="";
}
}
}
}
the error message is this: In function 'void setup()':

sketch_nov22b:38: error: 'rotation' was not declared in this scope

   attachInterrupt(digitalPinToInterrupt(WindSensorPin), rotation, FALLING);

                                                         ^
and this:

In function 'void loop()':

sketch_nov22b:235: error: expected '}' at end of input

and this:
 
exit status 1
'rotation' was not declared in this scope

GypsumFantastic

#1
Nov 22, 2016, 05:03 pm Last Edit: Nov 22, 2016, 05:10 pm by GypsumFantastic
The variable you defined is called Rotation, not rotation - C++ is case sensitive.

EDIT - ignore that, it's wrong. I didn't spot that your variable is Rotations and your function is rotation()

I think if you get your {} braces sorted, then rotation() will be defined properly and things should work.

Try adding a } after cliente.println(WindSpeed);

robert0430

Now i got this error message:

In function 'void loop()':

sketch_nov22b:217: error: a function-definition is not allowed here before '{' token

 void rotation () {

                  ^

sketch_nov22b:235: error: expected '}' at end of input

 }

 ^

sketch_nov22b:235: error: expected '}' at end of input

sketch_nov22b:235: error: expected '}' at end of input

sketch_nov22b:235: error: expected '}' at end of input

sketch_nov22b:235: error: expected '}' at end of input

sketch_nov22b:235: error: expected '}' at end of input

UKHeliBob

The variable you defined is called Rotation, not rotation - C++ is case sensitive.
That is not the problem
Code: [Select]

    attachInterrupt(digitalPinToInterrupt(WindSensorPin), rotation, FALLING);

attachInterrupt() takes the name of a function, not a variable.

However, there is plenty else wrong with the code.  Once formatted using AutoFormat in the IDE the fact that the loop() function has no closing brace will become obvious.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

CrossRoads

That also looks like the kind of error reported when a function is written inside another function, such as loop:
Code: [Select]

void loop(){
  void rotation() {
  //
  }
}

should be
Code: [Select]

void loop(){
//
}
void rotation() {
//
}
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

robert0430



Thank you so much! it finally works, really thank you so much :D

Go Up