programmer131 / esp8266-waterLevel

water level control system using ESP8266 and HC-SR04
16 stars 11 forks source link

Error on Compiling #1

Closed thomasjoseph4321 closed 6 years ago

thomasjoseph4321 commented 6 years ago

Sir Thank you for this project Could assist me to resolve this error message I was received on sketch compiling time .i was following exact process you mentioned in README.MD file and also I am following your YouTube video.

ERROR MESSAGE

Arduino: 1.8.5 (Windows 7), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

waterLevel:182: error: expected constructor, destructor, or type conversion before 'distanceSensor'

UltraSonicDistanceSensor distanceSensor(D1,D2); //D1 trig, D2=echo

                      ^

C:\Users\Thomas\AppData\Local\Temp\Rar$DIa12152.4961\waterLevel\waterLevel.ino: In function 'void measure_Volume()':

waterLevel:243: error: 'distanceSensor' was not declared in this scope

 float heightInch=0.393701*distanceSensor.measureDistanceCm();    

                           ^

exit status 1 expected constructor, destructor, or type conversion before 'distanceSensor'

This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

Complete Sketch

include

include

include

include "Adafruit_MQTT.h"

include "Adafruit_MQTT_Client.h"

const char index_html[] PROGMEM={"<!DOCTYPE html>\n" "\n" "\n" "My first chart using FusionCharts Suite XT\n" "<script type=\"text/javascript\" src=\"http://static.fusioncharts.com/code/latest/fusioncharts.js\">\n" "<script type=\"text/javascript\" src=\"http://static.fusioncharts.com/code/latest/themes/fusioncharts.theme.fint.js?cacheBust=56\">\n" "<script src=\"https://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js\">\n" "<script src=\"https://simeydotme.github.io/jQuery-ui-Slider-Pips/dist/js/jquery-plus-ui.min.js\">\n" "<script src=\"https://simeydotme.github.io/jQuery-ui-Slider-Pips/dist/js/jquery-ui-slider-pips.js\">\n" "<link rel=\"stylesheet\" href=\"https://simeydotme.github.io/jQuery-ui-Slider-Pips/dist/css/jqueryui.min.css\">\n" "<link rel=\"stylesheet\" href=\"https://simeydotme.github.io/jQuery-ui-Slider-Pips/dist/css/jquery-ui-slider-pips.min.css\">\n" "<link rel=\"stylesheet\" href=\"https://simeydotme.github.io/jQuery-ui-Slider-Pips/dist/css/app.min.css\">\n" "\n" "\n" "\t\n" "<script type=\"text/javascript\">\n" " FusionCharts.ready(function(){\n" " var fusioncharts = new FusionCharts({\n" " \"type\": \"cylinder\",\n" " \"dataFormat\": \"json\",\n" " \"id\": \"fuelMeter\",\n" " \"renderAt\": \"chart-container\",\n" " \"width\": \"200\",\n" " \"height\": \"350\",\n" " \"dataSource\": {\n" " \"chart\": {\n" " \"theme\": \"fint\",\n" " \"caption\": \"Water Level in Bucket\",\n" " \"subcaption\": \"at my Home\",\n" " \"lowerLimit\": \"0\",\n" " \"upperLimit\": \"15\",\n" " \"lowerLimitDisplay\": \"Empty\",\n" " \"upperLimitDisplay\": \"Full\",\n" " \"numberSuffix\": \" ltrs\",\n" " \"showValue\": \"1\",\n" " \"chartBottomMargin\": \"25\"\n" " },\n" " \"value\": \"10\"\n" " },\n" " \"events\": {\n" " \"rendered\": function(evtObj, argObj) {\n" "\tsetInterval(function() {\n" "\tvar someUrl = \"/level\";\n" "\t\t\t\t\t$.ajax({\n" "\t\t\t\t\t\turl: someUrl,\n" "\t\t\t\t\t\tdataType: \"text\",\n" "\t\t\t\t\t\tsuccess: function(response) {\n" "\t\t\t\t\t\t\t evtObj.sender.feedData(\"&value=\" + response);\n" "\t\t\t\t\t\t},\n" "\t\t\t\t\t\ttimeout: 2000\n" "\t\t\t\t\t})\t\n" "\t\t\n" " }, 1000); \n" " }\n" "}\n" "});\n" " fusioncharts.render();\n" " });\n" "\n" "\n" "\n" "<div style=\"width:600px;margin:auto;\">\n" "\n" "<div class=\"stuff\">\n" " \n" "

\n" " <div class=\"inline\" id=\"flat-slider-vertical-1\">
\n" " \n" " \n" "
\n" " <div style=\"margin-left: 10px;\" class=\"inline\" id=\"chart-container\">FusionCharts XT will load here!\n" "\t<div class=\"inline\" id=\"status\" style=\"background-color: lightgrey;\n" " width: 100px;\n" " border: 10px solid;\n" "\tborder-color: coral;\n" " padding: 2px;\n" " margin: 1px;\">Motor OFF\n" " \n" "\n" "\n" "\n" "\t\n" "" }; //create new adafruit IO feed and name it as 'waterLevel' //uncomment these two lines and write your wifi ssid/password const char ssid = "ssd"; const char password = "password"; //also uncomment and write here your own adafruit IO username and key.

define AIO_USERNAME "programmer5"//replace it with your username

define AIO_KEY "6e5fd35c936743808ceae4e101f6cbd5"//replace it with your key

//uncomment these lines as well, write radius of tank and total height in units of inches,

define RADIUS 5.5

define MAX_HEIGHT 10

//modify this line if you have to connect relay to some pin other than D4

define MOTOR_CONTROL_PIN D4

//Connect trig of ultrasonic sensor at D1 and echo at D2, modify this line otherwise UltraSonicDistanceSensor distanceSensor(D1,D2); //D1 trig, D2=echo //these are default water level limits, these values will be applied until on reset until user sends new limits from webpage. int waterLevelLowerThreshold=3; int waterLevelUpperThreshold=12;

define AIO_SERVER "io.adafruit.com"

define AIO_SERVERPORT 1883 // use 8883 for SSL

float volume; float liters; // Create an ESP8266 WiFiClient class to connect to the MQTT server. WiFiClient client; // or... use WiFiFlientSecure for SSL //WiFiClientSecure client;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details. Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); Adafruit_MQTT_Publish waterLevel = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/waterLevel");

/*** Sketch Code ****/

// Bug workaround for Arduino 1.6.6, it seems to need a function declaration // for some reason (only affects ESP8266, likely an arduino-builder bug). void MQTT_connect();

String inputString = ""; // a string to hold incoming data String dataToSend=""; int waterLevelDownCount=0,waterLevelUpCount=0;

ESP8266WebServer server(80); void handleRoot() { server.send_P(200, "text/html;charset=UTF-8", index_html); }

void handleLevelRequest(){ server.send(200,"text",String(liters)); }

void handleNotFound(){ String message = "File Not Found\n\n"; server.send(404, "text/plain", message); } void handleStatus() { if(digitalRead(MOTOR_CONTROL_PIN)==0)//MOTOR ON server.send(200, "text/plain","on"); else server.send(200, "text/plain","off"); } void handleRangeSetting(){ waterLevelLowerThreshold=(server.arg(0)).toInt();
waterLevelUpperThreshold=(server.arg(1)).toInt(); Serial.print(waterLevelLowerThreshold); Serial.print(":");
Serial.println(waterLevelUpperThreshold);

server.send(200, "text/plain", ""); }

void measure_Volume() { float heightInch=0.393701distanceSensor.measureDistanceCm();
Serial.println(heightInch); if(heightInch>MAX_HEIGHT) heightInch=MAX_HEIGHT; if(heightInch<0) heightInch=0;
volume=3.14
RADIUSRADIUS(MAX_HEIGHT-heightInch);//MAX_HEIGHT-distance will give actual height, liters=volume*0.0164 ; Serial.println(liters);

if(liters<=waterLevelLowerThreshold)
    waterLevelDownCount++;
  else waterLevelDownCount=0;

  if(liters>=waterLevelUpperThreshold)
    waterLevelUpCount++;
  else waterLevelUpCount=0;

  waterLevel.publish(liters);      

  if(waterLevelDownCount==3)
  {//TURN ON RELAY
    Serial.println("motor turned on");   
    digitalWrite(MOTOR_CONTROL_PIN,LOW);//Relay is active LOW
  }
  if(waterLevelUpCount==3)
  {//TURN OFF RELAY
    Serial.println("motor turned off");   
    digitalWrite(MOTOR_CONTROL_PIN,HIGH);//Relay is active LOW
  }      

} void runPeriodicFunc() { static const unsigned long REFRESH_INTERVAL1 = 2100; // 2.1sec static unsigned long lastRefreshTime1 = 0;

if(millis() - lastRefreshTime1 >= REFRESH_INTERVAL1)
{   
  measure_Volume();
  lastRefreshTime1 = millis();

} }

void MQTT_connect() { int8_t ret;

// Stop if already connected. if (mqtt.connected()) { return; }

Serial.print("Connecting to MQTT... ");

while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
   Serial.println(mqtt.connectErrorString(ret));
   Serial.println("Retrying MQTT connection in 5 seconds...");
   mqtt.disconnect();
   delay(5000);  // wait 5 seconds
   }

Serial.println("MQTT Connected!"); }

void setup(void){ Serial.begin(115200); delay(100); pinMode(MOTOR_CONTROL_PIN, OUTPUT); WiFi.begin(ssid, password); Serial.println("");

while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.print("IP address:");
Serial.println(WiFi.localIP());

server.on("/", handleRoot);
server.on("/level",handleLevelRequest); server.on("/configRange",handleRangeSetting); server.on("/motor_status",handleStatus);

server.onNotFound(handleNotFound);

server.begin(); Serial.println("HTTP server started"); }

void loop(void){ runPeriodicFunc();

MQTT_connect(); server.handleClient(); }

programmer131 commented 6 years ago

please install this library https://github.com/Martinsos/arduino-lib-hc-sr04

programmer131 commented 6 years ago

closing as no further response