• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

Arduino + ESP8266 + HTML

Object Storage Arubacloud
0 głosów
464 wizyt
pytanie zadane 20 stycznia 2020 w C i C++ przez Bartek_14 Nowicjusz (120 p.)
edycja 20 stycznia 2020 przez Bartek_14

Witam, mam 15 lat i próbuję stworzyć program do WeMos'a d1 r2, który będzie miał za zadanie sterować servomechanizmem. Za wszelką pomoc będę bardzo wdzięczny.

Weryfikuje program, i wyskakuje ten błąd: expected unqualified-id before '=' token

Korzystałem z tego żródła: https://circuits4you.com/2018/02/05/esp8266-arduino-wifi-web-server-led-on-off-control/

PROGRAM wygląda tak:

#include <Servo.h>
Servo = servo;
#include <ESP8266WiFi.h>
#include <WiFiClient.h>

//ESP Web Server Library to host a web page
#include <ESP8266WebServer.h>

//---------------------------------------------------------------
//Our HTML webpage contents in program memory
const char MAIN_page[] PROGMEM = R"=====(
<!DOCTYPE html>
<html>
<body>
<center>
<h1>WiFi LED on off demo: 1</h1><br>
Ciclk to turn <a href="servoON">servoON</a><br>
Ciclk to turn <a href="servoOFF">servoOFF</a><br>
<hr>
</center>
</body>
</html>
)=====";
//---------------------------------------------------------------
#define servo A0  

const char* ssid = "NIEWIADOMO";
const char* password = "213213221";

ESP8266WebServer server(80); //Server on port 80

void handleRoot() {
 Serial.println("You called root page");
 server.send(200, "text/html", MAIN_page); //Send web page
}

void handleservoON() { 
 Serial.println("servo on page");
 servo.write(180);
 server.send(200, "text/html", "servo is ON"); //Send ADC value only to client ajax request
}

void handleservoOFF() { 
 Serial.println("servo off page");
servo.write(0);
 server.send(200, "text/html", "servo is OFF"); //Send ADC value only to client ajax request
}
void setup(void){
  Serial.begin(115200);
  
  WiFi.begin(ssid, password);     //Connect to your WiFi router
  Serial.println("");
f
  servo.write(0);
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  //If connection successful show IP address in serial monitor
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());  //IP address assigned to your ESP
 
  server.on("/", handleRoot);      //Which routine to handle at root location. This is display page
  server.on("/servoON", handleLEDon); //as Per  <a href="ledOn">, Subroutine to be called
  server.on("/servoOFF", handleLEDoff);

  server.begin();                  //Start server
  Serial.println("HTTP server started");
}
void loop(void){
  server.handleClient();          //Handle client requests
}

Zrobiłem parę poprawek i działasmiley

Oto zmieniony program:


#include <Servo.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>

//ESP Web Server Library to host a web page
#include <ESP8266WebServer.h>

Servo Servo1;

//---------------------------------------------------------------
//Our HTML webpage contents in program memory
const char MAIN_page[] PROGMEM = R"=====(
<!DOCTYPE html>
<html>
<body>
<center>
<h1>WiFi LED on off demo: 1</h1><br>
Ciclk to turn <a href="servoON">servoON</a><br>
Ciclk to turn <a href="servoOFF">servoOFF</a><br>
<hr>
</center>
</body>
</html>
)=====";
//---------------------------------------------------------------
//On board LED Connected to GPIO2
//#define servo A0  

const char* ssid = "VR600";
const char* password = "Dzieci_4";

ESP8266WebServer server(80); //Server on port 80

void handleRoot() {
 Serial.println("You called root page");
 server.send(200, "text/html", MAIN_page); //Send web page
}

void handleLEDon() { 
 Serial.println("servo on page");
 Servo1.write(90);
 server.send(200, "text/html", "servo is ON"); //Send ADC value only to client ajax request
}

void handleLEDoff() { 
 Serial.println("servo off page");
Servo1.write(0);
 server.send(200, "text/html", "servo is OFF"); //Send ADC value only to client ajax request
}
//==============================================================
//                  SETUP
//==============================================================
void setup(void){
  Serial.begin(115200);
  
  Servo1.attach(14);
  WiFi.begin(ssid, password);     //Connect to your WiFi router
  Serial.println("");

  Servo1.write(90);
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  //If connection successful show IP address in serial monitor
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());  //IP address assigned to your ESP
 
  server.on("/", handleRoot);      //Which routine to handle at root location. This is display page
  server.on("/servoON", handleLEDon); //as Per  <a href="ledOn">, Subroutine to be called
  server.on("/servoOFF", handleLEDoff);

  server.begin();                  //Start server
  Serial.println("HTTP server started");
}
//==============================================================
//                     LOOP
//==============================================================
void loop(void){
  server.handleClient();          //Handle client requests
}

 

 

1 odpowiedź

0 głosów
odpowiedź 20 stycznia 2020 przez slawek763 Użytkownik (940 p.)
Po co Ci ta 2 linia: "Servo = servo;"? Sprawdź to, tylko nie jestem w 100% pewien bo juz dawno nie pisalem w arduino. Chyba powinno byc po prostu "Servo servo" bez =

Podobne pytania

0 głosów
0 odpowiedzi 1,380 wizyt
0 głosów
2 odpowiedzi 2,148 wizyt

92,615 zapytań

141,465 odpowiedzi

319,781 komentarzy

61,997 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj.

Akademia Sekuraka

Kolejna edycja największej imprezy hakerskiej w Polsce, czyli Mega Sekurak Hacking Party odbędzie się już 20 maja 2024r. Z tej okazji mamy dla Was kod: pasjamshp - jeżeli wpiszecie go w koszyku, to wówczas otrzymacie 40% zniżki na bilet w wersji standard!

Więcej informacji na temat imprezy znajdziecie tutaj. Dziękujemy ekipie Sekuraka za taką fajną zniżkę dla wszystkich Pasjonatów!

Akademia Sekuraka

Niedawno wystartował dodruk tej świetnej, rozchwytywanej książki (około 940 stron). Mamy dla Was kod: pasja (wpiszcie go w koszyku), dzięki któremu otrzymujemy 10% zniżki - dziękujemy zaprzyjaźnionej ekipie Sekuraka za taki bonus dla Pasjonatów! Książka to pierwszy tom z serii o ITsec, który łagodnie wprowadzi w świat bezpieczeństwa IT każdą osobę - warto, polecamy!

...