ESP8266 Library Makes Function Called from External Library Undeclared.

I have been working on some codes for a while. They worked just great. However, I needed an ESP8266 to make my data collection from my sensors easier. Unfortunatelly, as soon as I added the ESP8266 Libraries to my code, the code stops compiling and throws an error message about sim808 being undeclared in the scope. I have read up lots of comments on this forum and others. The nightly builds recommended and arduino-builders recommended are outdated and don't solve the problem again. The latest nightly build 1.8.11 couldn't also compile the sketch. I tried declaring the function in the sketch, I got error messages. I know it's an issue with a function in the ESP8266 Libraries that upsets Arduino Autoprototyping mechanisms. I just recently started coding in C. So, I don't know how to manually prototype when calling a function like this from a library. Please, I need help with resolving this so I can deliver a product fast. I look forward to your responses.

Kindly find the code below.

#include <DFRobot_sim808.h>
#include <sim808.h>
#include <virtuabotixRTC.h> //Library used 
//Wiring CLK -> 6 , DAT -> 7, Reset -> 8
virtuabotixRTC myRTC(6, 7, 8);
//#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

//configuring the Wifi parameters I want to use.
char * ssid_ap = "ESP8266_SSID";
char * password_ap = "haulr.ng";
IPAddress ip(192, 168, 11, 5); //arbitrary IP Address (Doesn't conflict with local network)
IPAddress gateway(192, 168, 11, 4);
IPAddress subnet(255, 255, 255, 0);

#define mydelay 10000
//DFRobot_SIM808 sim808(&Serial);
char http_cmd[182] = "POST /api/tracker/ HTTP/1.1\r\nContent-Type: application/json\r\nContent-Length: 70\r\nHost: haulr.herokuapp.com\r\n\r\n{ \"trackerId\": \"2222\",\"hxeight\": ";
char mybuffer[145];
int count = 142;
long current = 0;
String longitude, latitude, Date, Time;
int digitalStart = 14;

//Set up the server object
ESP8266WebServer server;

float height;

void setup() {
  Serial.begin(9600);
  pinMode(digitalStart, OUTPUT);//switches on the sim808

  //************switches on the sim808************
  digitalWrite(digitalStart, HIGH);
  // put your setup code here, to run once:

  WiFi.mode(WIFI_AP);
  WiFi.softAPConfig(ip, gateway, subnet);
  WiFi.softAP(ssid_ap, password_ap);
  Serial.begin(9600);
  Serial.println();
  Serial.print("IP Address: "); Serial.print(WiFi.localIP());
  //configure the server's route
  server.on("/", handleIndex); //use the top root to report the last sensor value
  server.on("/update", handleUpdate);
  server.begin();

  //******** Initialize sim808 module *************
  while (!sim808.init()) {
    delay(1000);
    Serial.print("Sim808 init error\r\n");
  }
  delay(3000);
  Serial.println(sizeof(http_cmd));

  //*********** Attempt; DHCP *******************
  while (!sim808.join(F("cmnet"))) {
    Serial.println("Sim808 join network error");
    delay(2000);
  }

  //************ Successful DHCP ****************
  Serial.print("IP Address is ");
  Serial.println(sim808.getIPAddress());
  //************* Turn on the GPS power************
  if ( sim808.attachGPS())
    Serial.println("Open the GPS power success");
  else
    Serial.println("Open the GPS power failure");
  current = millis();

  bool mylocation() {
    bool control = LOW;
    long prevfix = millis();
    Serial.println("im here");
    while (millis() - prevfix < 3000) {
      if (sim808.getGPS()) {
        Serial.println("got a fix");
        latitude = String(sim808.GPSdata.lat, 6);
        longitude = String(sim808.GPSdata.lon, 6);
        control = HIGH;
        break;
      }
    }
    if (control) {
      delay(1000);
      sim808.detachGPS();
    }
    return control;
  }
}


void loop() {

  server.handleClient();

  //obtain Date and Time;
  myRTC.updateTime();
  Date = String(myRTC.dayofmonth) + "/" + String(myRTC.month)  + "/" + String(myRTC.year);
  Time = String(myRTC.hours) + ":" + String(myRTC.minutes) ;
  if (millis() - current > mydelay) {
    sim808.attachGPS();
    bool getloc = mylocation();
    if (getloc) {

      if (weight <= 0) weight = weight;
      latitude = (String) height + ",\"location\": \"" + latitude + "," + longitude + ",\"Date\": \"" + Date + ",\"Time\": \"" + Time + "\" }";
      int cnt = count;
      for (int i = 0; i <= latitude.length(); i++) {
        http_cmd[cnt++] = latitude[i];
      }
      postData();
    }
    current = millis();
  }
  delay(100000);
}

void postData() {
  delay(1000);
  if (!sim808.is_connected()) {
label:
    //*********** Establish a TCP connection ************
    if (!sim808.connect(TCP, "haulr.herokuapp.com", 80)) {
      Serial.println("Connect error");
      goto label;
    }
    else {
      Serial.println("Connect haulr.herokuapp.com success");
    }
  }

  //*********** Send a POST request *****************
  Serial.println("waiting to fetch...");
  sim808.send(http_cmd, sizeof(http_cmd) - 1);
  while (true) {
    int ret = sim808.recv(mybuffer, sizeof(mybuffer) - 1);
    if (ret <= 0) {
      Serial.println("fetch over...");
      break;
    }
    mybuffer[ret] = '\0';
    Serial.print("Recv: ");
    Serial.print(ret);
    Serial.print(" bytes: ");
    Serial.println(mybuffer);
    break;
  }

  //************* Close TCP or UDP connections **********
  sim808.close();

  //*** Disconnect wireless connection, Close Moving Scene *******
  sim808.disconnect();
}





void handleIndex() {
  server.send(200, "text/plain", String(height)); // we'll need to refresh the page to get latest value
}

void handleUpdate() {
  //the value will be passed as a url argument
  height = server.arg("value").toFloat();
  Serial.println(a_value);
  server.send(200, "text/plain", "Value has been updated");
}

The error message is shown below.

In file included from C:\Users\hp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\ESP8266WiFi\src/ESP8266WiFi.h:28:0,

                 from C:\Users\hp\Documents\Arduino\sketch_oct08a\sketch_oct08a.ino:10:

C:\Users\hp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\ESP8266WiFi\src/include/wl_definitions.h:73:17: error: redeclaration of 'CLOSED'

   CLOSED      = 0,

                 ^

In file included from C:\Users\hp\Documents\Arduino\sketch_oct08a\sketch_oct08a.ino:2:0:

C:\Users\hp\Documents\Arduino\libraries\DFRobot_SIM808-master/DFRobot_sim808.h:41:5: note: previous declaration 'Protocol CLOSED'

     CLOSED = 0,

     ^

C:\Users\hp\Documents\Arduino\sketch_oct08a\sketch_oct08a.ino: In function 'void setup()':

sketch_oct08a:58: error: 'sim808' was not declared in this scope

   while (!sim808.init()) {

           ^

sketch_oct08a:66: error: 'sim808' was not declared in this scope

   while (!sim808.join(F("cmnet"))) {

           ^

sketch_oct08a:73: error: 'sim808' was not declared in this scope

   Serial.println(sim808.getIPAddress());

                  ^

sketch_oct08a:81: error: a function-definition is not allowed here before '{' token

   bool mylocation() {

                     ^

sketch_oct08a:180: error: expected '}' at end of input

 }

 ^

exit status 1
'sim808' was not declared in this scope

I know it's an issue with a function in the ESP8266 Libraries that upsets Arduino Autoprototyping mechanisms.

No. it isn't. It's much simpler. The ESP8266 core developer and the DFRobot_sim888 developers both defined CLOSED as a C constant without any namespace or other limitation. As "CLOSED" is a rather generic term, the probability of a clash is quite high and you experienced such a clash. I suggest to modify your SIM888 library and change every occurence of CLOSED to SIM888_CLOSED.

Thanks for the response.I have done that and the error on "CLOSE" was fixed.

However, the error message on "Function is Undeclared in Scope" still persists. I can't still get around it yet.

Please, can you direct me on how to solve this?

Anybody else got any helpful information on solving this?

//DFRobot_SIM808 sim808(&Serial);

If you comment out the declaration, this is not a surprise.

current = millis();

  bool mylocation() {

and a '}' in between these lines is missing.

Thanks guys. I acted on your advice and the issue was resolved. The issue was the commented declaration as Pylon said. The closing brace for the boolean function was also an error. Thanks once again.