rezagvn
December 25, 2018, 9:06am
1
i want to control led and servo using web, but it says:
D:\BAHAN PI\inshaallah\inshaallah.ino: In function 'void response()':
inshaallah:68:14: error: 'statusServo' was not declared in this scope
} else if (statusServo == 0) {
^
D:\BAHAN PI\inshaallah\inshaallah.ino: In function 'void setup()':
inshaallah:108:23: error: 'statusServo' was not declared in this scope
digitalWrite(servo, statusServo);
^
exit status 1
'statusServo' was not declared in this scope
can anyone help me?
my code:
#include <TelegramBot.h>
#include <Servo.h>
#include <ESP8266WebServer.h> //memasukan library NodeMCU sebagai web server
#include <ESP8266WiFi.h> //memasukan library NodeMCU
#include <WiFiClient.h> //memasukan library NodeMCU sebagai client
#include <WiFiClientSecure.h>
ESP8266WebServer server(80); //menggunakan port 80
//Masukan nama wifi dan password yang akan dibuat
const char *ssid = "qw";
const char *password = "qwertyuiop";
int statusLED = LOW;
const char BotToken[] = "---------";
WiFiClientSecure net_ssl;
TelegramBot bot (BotToken, net_ssl);
Servo servo;
//membuat fungsi untuk kondisi led built in
void handleLedOn() {
statusLED = LOW;
digitalWrite(LED_BUILTIN, statusLED);
response();
}
void handleLedOff() {
statusLED = HIGH;
digitalWrite(LED_BUILTIN, statusLED);
response();
}
void LockServo() {
servo.write(90);
response();
}
void OpenServo() {
servo.write(0);
response();
}
void handleRoot() {
response();
}
const String HtmlHtml = "<html><head>"
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /></head>";
const String HtmlHtmlClose = "</html>";
const String HtmlTitle = "<h1>Trial kedua kendali LED</h1>
\n";
const String HtmlLedStateLow = "<big>LED is now <b>ON</b></big>
\n";
const String HtmlLedStateHigh = "<big>LED is now <b>OFF</b></big>
\n";
const String HtmlServoStateLow = "<big>The Door is opened <b>0</b></big>
\n";
const String HtmlServoStateHigh = "<big>The Door is locked <b>90</b></big>
\n";
const String HtmlButtons =
"<a href=\"LEDOn\"><button style=\"display: block; width: 100%;\">ON</button></a>
"
"<a href=\"LEDOff\"><button style=\"display: block; width: 100%;\">OFF</button></a>
"
"<a href=\"Open\"><button style=\"display: block; width: 100%;\">Open</button></a>
"
"<a href=\"Lock\"><button style=\"display: block; width: 100%;\">Lock</button></a>
";
void response() {
String htmlRes = HtmlHtml + HtmlTitle;
if (statusLED == LOW) {
htmlRes += HtmlLedStateLow;
} else if (statusLED == HIGH) {
htmlRes += HtmlLedStateHigh;
} else if (statusServo == 0) {
htmlRes += HtmlServoStateLow;
} else {
htmlRes += HtmlServoStateHigh;
}
htmlRes += HtmlButtons;
htmlRes += HtmlHtmlClose;
server.send(200, "text/html", htmlRes);
}
void setup() {
delay(1000); //waktu tunda 1 detik
Serial.begin(115200);
Serial.println();
WiFi.softAP(ssid, password);
//bertindak sebagai access point dengan nama wifi dan pass diatas
IPAddress apip = WiFi.softAPIP(); //alamat IP
Serial.print("visit: \n");
Serial.println(apip); //menuliskan alamat IP yang bisa dikunjungi
server.on("/", handleRoot); //memanggil fungsi handleRoot()
server.on("/LEDOn", handleLedOn);
server.on("/LEDOff", handleLedOff);
server.on("/Open", OpenServo);
server.on("/Close", LockServo);
server.begin(); //proses pemulaian menjadi server
Serial.println("HTTP server beginned");
bot.begin();
message m = bot.getUpdates();
bot.sendMessage(m.chat_id, "The Bot is now Connected");
servo.attach(2); //D4
servo.write(0);
servo.detach();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, statusLED);
digitalWrite(servo, statusServo);
}
void loop() {
server.handleClient();
}
system
December 25, 2018, 9:19am
2
Did you mean "statusLED"?
Or maybe you forgot to declare the variable (it is referenced throughout the sketch)
rezagvn
December 25, 2018, 9:42am
4
I have eliminated the problem for the previous one, but now a new one appears:
D:\BAHAN PI\qw\qw.ino: In function 'void response()':
qw:68:20: error: no match for 'operator==' (operand types are 'Servo' and 'int')
} else if (servo == 0) {
^
exit status 1
no match for 'operator==' (operand types are 'Servo' and 'int')
heres the new code:
#include <TelegramBot.h>
#include <Servo.h>
#include <ESP8266WebServer.h> //memasukan library NodeMCU sebagai web server
#include <ESP8266WiFi.h> //memasukan library NodeMCU
#include <WiFiClient.h> //memasukan library NodeMCU sebagai client
#include <WiFiClientSecure.h>
ESP8266WebServer server(80); //menggunakan port 80
//Masukan nama wifi dan password yang akan dibuat
const char *ssid = "qw";
const char *password = "qwertyuiop";
int statusLED = LOW;
const char BotToken[] = "---------";
WiFiClientSecure net_ssl;
TelegramBot bot (BotToken, net_ssl);
Servo servo;
//membuat fungsi untuk kondisi led built in
void handleLedOn() {
statusLED = LOW;
digitalWrite(LED_BUILTIN, statusLED);
response();
}
void handleLedOff() {
statusLED = HIGH;
digitalWrite(LED_BUILTIN, statusLED);
response();
}
void LockServo() {
servo.write(90);
response();
}
void OpenServo() {
servo.write(0);
response();
}
void handleRoot() {
response();
}
const String HtmlHtml = "<html><head>"
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /></head>";
const String HtmlHtmlClose = "</html>";
const String HtmlTitle = "<h1>Trial kedua kendali LED</h1>
\n";
const String HtmlLedStateLow = "<big>LED is now <b>ON</b></big>
\n";
const String HtmlLedStateHigh = "<big>LED is now <b>OFF</b></big>
\n";
const String HtmlServoStateLow = "<big>The Door is opened <b>0</b></big>
\n";
const String HtmlServoStateHigh = "<big>The Door is locked <b>90</b></big>
\n";
const String HtmlButtons =
"<a href=\"LEDOn\"><button style=\"display: block; width: 100%;\">ON</button></a>
"
"<a href=\"LEDOff\"><button style=\"display: block; width: 100%;\">OFF</button></a>
"
"<a href=\"Open\"><button style=\"display: block; width: 100%;\">Open</button></a>
"
"<a href=\"Lock\"><button style=\"display: block; width: 100%;\">Lock</button></a>
";
void response() {
String htmlRes = HtmlHtml + HtmlTitle;
if (statusLED == LOW) {
htmlRes += HtmlLedStateLow;
} else if (statusLED == HIGH) {
htmlRes += HtmlLedStateHigh;
} else if (servo == 0) {
htmlRes += HtmlServoStateLow;
} else {
htmlRes += HtmlServoStateHigh;
}
htmlRes += HtmlButtons;
htmlRes += HtmlHtmlClose;
server.send(200, "text/html", htmlRes);
}
void setup() {
delay(1000); //waktu tunda 1 detik
Serial.begin(115200);
Serial.println();
WiFi.softAP(ssid, password);
//bertindak sebagai access point dengan nama wifi dan pass diatas
IPAddress apip = WiFi.softAPIP(); //alamat IP
Serial.print("visit: \n");
Serial.println(apip); //menuliskan alamat IP yang bisa dikunjungi
server.on("/", handleRoot); //memanggil fungsi handleRoot()
server.on("/LEDOn", handleLedOn);
server.on("/LEDOff", handleLedOff);
server.on("/Open", OpenServo);
server.on("/Close", LockServo);
server.begin(); //proses pemulaian menjadi server
Serial.println("HTTP server beginned");
bot.begin();
message m = bot.getUpdates();
bot.sendMessage(m.chat_id, "The Bot is now Connected");
servo.attach(2); //D4
servo.write(0);
servo.detach();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, statusLED);
}
void loop() {
server.handleClient();
}
system
December 25, 2018, 9:44am
5
Did you miss a ".read()" out?
rezagvn
December 25, 2018, 10:38am
6
AWOL:
Did you miss a ".read()" out?
thanks for reminding me before, i have used "servo.read" but there is a new problem that appears
Arduino: 1.8.6 Hourly Build 2018/07/11 05:33 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)"
D:\BAHAN PI\qw\qw.ino: In function 'void response()':
qw:68:26: error: no matching function for call to 'Servo::read(int)'
} else if (servo.read(0)) {
^
D:\BAHAN PI\qw\qw.ino:68:26: note: candidate is:
In file included from D:\BAHAN PI\qw\qw.ino:2:0:
C:\Users\Hp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\Servo\src/Servo.h:84:9: note: int Servo::read()
int read(); // returns current pulse width as an angle between 0 and 180 degrees
^
C:\Users\Hp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\Servo\src/Servo.h:84:9: note: candidate expects 0 arguments, 1 provided
exit status 1
no matching function for call to 'Servo::read(int)'
please keep using code tags, } else if (servo.read(0)) {
probably should be } else if (servo.read()==0) {
the read() function doesn't take any arguments and you were comparing with 0 before. Read the error msg thoroughly and see if you can make sense of it. If you can't then posting can help you resolve your issue.
rezagvn
December 25, 2018, 10:51am
8
Deva_Rishi:
please keep using code tags, } else if (servo.read(0)) {
probably should be } else if (servo.read()==0) {
the read() function doesn't take any arguments and you were comparing with 0 before. Read the error msg thoroughly and see if you can make sense of it. If you can't then posting can help you resolve your issue.
Thanks! the problem is solved.