esp8266 + irserver + ledPin не получается скомпилировать.
- Войдите на сайт для отправки комментариев
Пт, 03/08/2018 - 20:01
Добрый день всем
Стоит следующая задача: Поднять вебсервер на esp8266, подключить ик передатчик и в добавок прикрутить возможность вкл\выкл светодиод, нашел скетч IRremoteESP8266 и все вроде бы работает но когда попытался добавить в код возможность управлять светодиодом перестало компилится и пошли ошибки.
Сам скетч
* IRremoteESP8266: IRServer - demonstrates sending IR codes controlled from a webserver
* Version 0.2 June, 2017
#ifndef UNIT_TEST
#include <Arduino.h>
#endif
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <WiFiClient.h>
const char* ssid = "TP-LINK_BCBBEC";
const char* password = "12345678";
MDNSResponder mdns;
ESP8266WebServer server(80);
#define IR_LED 4 // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRsend irsend(IR_LED); // Set the GPIO to be used to sending the message.
int ledPin = 16;
bool ledState = LOW;
pinMode(ledPin, OUTPUT);
server.on("/on", turnOn); //Associate the handler function to the path
server.on("/off", turnOff); //Associate the handler function to the path
server.on("/toggle", toggle); //Associate the handler function to the path
void handleRoot() {
server.send(200, "text/html",
"<html>" \
"<head><title>Smart Home control panel ESP8266</title></head>" \
"<body>" \
"<h1>Smart Home control panel</h1>" \
"<p><a href=\"ir?code=50153655\">on tv</a></p>" \
"<p><a href=\"ir?code=50157735\">vol+</a></p>" \
"<p><a href=\"ir?code=50165895\">vol-</a></p>" \
"<p><a href=\"ir?code=50137335\">voloff</a></p>" \
"<p><a href=\"ir?code=16711935\">vkl_kolonki</a></p>" \
"<p><a href=\"ir?code=16771222\">Send 0xFFE896</a></p>" \
"<p><a href=\"ir?code=16771222\">Send 0xFFE896</a></p>" \
"<p><a href=\"ir?code=16771222\">Send 0xFFE896</a></p>" \
"</body>" \
"</html>");
}
void handleIr() {
for (uint8_t i = 0; i < server.args(); i++) {
if (server.argName(i) == "code") {
uint32_t code = strtoul(server.arg(i).c_str(), NULL, 10);
#if SEND_NEC
irsend.sendNEC(code, 32);
#endif // SEND_NEC
}
}
handleRoot();
}
void handleNotFound() {
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i = 0; i < server.args(); i++)
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
server.send(404, "text/plain", message);
}
void setup(void) {
irsend.begin();
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP().toString());
if (mdns.begin("esp8266", WiFi.localIP())) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/ir", handleIr);
server.on("/on", turnOn); //Associate the handler function to the path
server.on("/off", turnOff); //Associate the handler function to the path
server.on("/toggle", toggle); //Associate the handler function to the path
server.on("/inline", [](){
server.send(200, "text/plain", "this works as well");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop(void) {
server.handleClient();
}И вот логи:
Arduino: 1.8.5 (Windows 10), Плата:"NodeMCU 1.0 (ESP-12E Module), 80 MHz, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"
ww:53: error: expected unqualified-id before '{' token
{
^
ww:58: error: 'server' does not name a type
server.on("/on", turnOn); //Associate the handler function to the path
^
ww:59: error: 'server' does not name a type
server.on("/off", turnOff); //Associate the handler function to the path
^
ww:60: error: 'server' does not name a type
server.on("/toggle", toggle); //Associate the handler function to the path
^
C:\Users\fanfcsd\Documents\Arduino\ww\ww.ino: In function 'void setup()':
ww:138: error: 'turnOn' was not declared in this scope
server.on("/on", turnOn); //Associate the handler function to the path
^
ww:139: error: 'turnOff' was not declared in this scope
server.on("/off", turnOff); //Associate the handler function to the path
^
ww:140: error: 'toggle' was not declared in this scope
server.on("/toggle", toggle); //Associate the handler function to the path
^
exit status 1
expected unqualified-id before '{' token
Мне видется проблема здесь:
ww:53: error: expected unqualified-id before'{'tokenСкобку не закрыли Вы сударь...
Я не могу понять в каком месте я её не закрыл
Закрыть скобку можно в любом месте после того, где она открыта.
Но, вероятнее всего, поведение программы в каждом случае будет различным. Которое из них - желаемое, - известно только Вам.
Поэтому и "в каком месте закрывать скобку" - может быть известно только Вам.
Но, на самом деле, Вы ее не забыли закрыть, а забыли открыть.
Да и впечатление такое, что поместили на форум Вы один скетч, а диагностика - от совершенно другого.
Но, на самом деле, Вы ее не забыли закрыть, а забыли открыть.
Да и впечатление такое, что поместили на форум Вы один скетч, а диагностика - от совершенно другого.
А я то чувствую запашок... Спасибо!