Go Down

Topic: problem in coding (Read 653 times) previous topic - next topic

Himashree123

hello iwant to send data from two sensors one is lm35 and other heartrate through esp8266 i have a code which is giving error:exit status 1
a function-definition is not allowed here before '{' token
please help
this is my code


#include<SoftwareSerial.h>
SoftwareSerial esp8266(2,3);
#define DEBUG true
 
void setup()
{
  Serial.begin(9600);    ///////For Serial monitor
  esp8266.begin(115200); ///////ESP Baud rate
  //pinMode(11,OUTPUT);    /////used if connecting a LED to pin 11
  //digitalWrite(11,LOW);
 
  sendData("AT+RST\r\n",2000,DEBUG); // reset module
  sendData("AT+CWMODE=2\r\n",1000,DEBUG); // configure as access point
  sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address
  sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
  sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80
}

float sense()
{
  float sensetemp()
  {
      int val = analogRead(A0);
    float mv = ( val/1024.0)*5000;
    float celcius = mv/10;
    return(celcius);
  }
float senserate()
{
oldvalue=newvalue;
newvalue= 0;
for(int i=0; i<64;i++)
{
  newvalue +=analogRead(A0);
}
newvalue=newvalue/64;
if (oldvalue<threshold && newvalue>=threshold){
  oldmillis=newmillis;
  newmillis=millis();
  timings[cnt%16]=(int)(newmillis-oldmillis);
  int totalmillis=0;
  for(int i=0;i<=16;i++){
    totalmillis+= timings;
    }
   int heartrate = {60000/(totalmillis/16)};
   Serial.println(heartrate,DEC);
   cnt++;
}
delay(10);
}
}


int connectionId;
void loop(){
    /////////////////////Recieving from web browser to toggle led
    if(esp8266.find("+IPD,"))
{
  if(esp8266.available())
  {
    {
     delay(300);
     connectionId = esp8266.read()-48;
     if(esp8266.find("pin="))
     {
     Serial.println("recieving data from web browser");
     int pinNumber = (esp8266.read()-48)*10;
     pinNumber += (esp8266.read()-48);
     digitalWrite(pinNumber, !digitalRead(pinNumber));
     }
   
    /////////////////////Sending data to browser
    else
    {
      String webpage = "<h1>Hello World</h1>";
      espsend(webpage);
     }
   
     if(sense()!= 0)
     {
       String add1="<h4>Temperature=</h4>";
      String two =  String(sensetemp(), 3);
      add1+= two;
      add1+="&#x2103";   //////////Hex code for degree celcius
      espsend(add1);
      String add2="<h4>heartrate=</h4>";
      String two =  String(senserate(), 3);
      add2+= two;
      add2+="BPM";   //////////Hex code for degree celcius
      espsend(add2);
     }
   
     else
     {
      String c="sensor is not conneted";
      espsend(c);                                     
     }      closeCommand+=connectionId; // append connection id

     
     String closeCommand = "AT+CIPCLOSE=";  ////////////////close the socket connection////esp command
     closeCommand+="\r\n";
     sendData(closeCommand,3000,DEBUG);
    }
  }
}
}
 
  //////////////////////////////sends data from ESP to webpage///////////////////////////
 
 void espsend(String d)
         {
             String cipSend = " AT+CIPSEND=";
             cipSend += connectionId;
             cipSend += ",";
             cipSend +=d.length();
             cipSend +="\r\n";
             sendData(cipSend,1000,DEBUG);
             sendData(d,1000,DEBUG);
         }

//////////////gets the data from esp and displays in serial monitor///////////////////////         
String sendData(String command, const int timeout, boolean debug)
            {
                String response = "";
                esp8266.print(command);
                long int time = millis();
                while( (time+timeout) > millis())
                {
                   while(esp8266.available())
                      {
                         char c = esp8266.read(); // read the next character.
                         response+=c;
                      } 
                }
               
                if(debug)
                     {
                     Serial.print(response); //displays the esp response messages in arduino Serial monitor
                     }
                return response;
            }

     

CtrlAltElite

Code: [Select]
float sense()
{
  float sensetemp()
  {

Here you are trying to define a function inside another function, but the dialect of C the Arduino uses doesn't allow that.
Has there been an outbreak of the stupid virus, and I didn't get the memo?

Go Up