Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WebServer.h>
- #include <Ticker.h>
- #define HTTP_WEB_PORT 80
- #define WIFI_RETRY_DELAY 500
- #define MAX_WIFI_INIT_RETRY 50
- const char* wifi_ssid = "SMHWN";
- const char* wifi_passwd = "mNyh7XS2j8Gm3KwnXsdJ79jxq";
- String stato = "FERMA";
- unsigned long attesa = 10000L;
- unsigned long posizione = 0;
- Ticker tapparella_manager;
- IPAddress local_IP(192,168,10,10);
- IPAddress gateway(192,168,10,10);
- IPAddress subnet(255,255,255,0);
- ESP8266WebServer http_server(HTTP_WEB_PORT);
- void setup(void) {
- int retries = 0;
- Serial.begin(115200);
- tapparella_manager.attach(0.5, gestisci_tapparella);
- Serial.println("Configurazione RoboCar WiFi AP..........");
- WiFi.mode(WIFI_STA);
- WiFi.begin(wifi_ssid, wifi_passwd);
- while ((WiFi.status() != WL_CONNECTED) && (retries < MAX_WIFI_INIT_RETRY)) {
- retries++;
- delay(WIFI_RETRY_DELAY);
- Serial.print("#");
- }
- Serial.print("RoboCar WiFi AP IP Address = ");
- Serial.println(WiFi.localIP());
- delay(3000);
- config_server_routing();
- http_server.begin();
- Serial.println("RoboCar HTTP Server Started");
- }
- void config_server_routing() {
- http_server.on("/", HTTP_GET, []() { http_server.send(200, "text/html", "Benvenuto sul ESP8266 RoboCar Web Server"); });
- http_server.on("/tapparella", HTTP_GET, muovi_tapparella);
- }
- void gestisci_tapparella() {
- Serial.println("gestisci tapparella");
- if (stato == "ALZA") {
- posizione += 500;
- Serial.println(posizione);
- }
- else if (stato == "ABBASSA") {
- posizione -= 500;
- Serial.println(posizione);
- }
- else if (stato == "FERMA")
- Serial.println(posizione);
- }
- void muovi_tapparella() {
- String comando = String(http_server.arg(0));
- Serial.print("Ricevuto comando = ");
- Serial.println(comando);
- http_server.send(200, "text/html", "tapparella - comando ricevuto");
- if (comando == "ALZA")
- alza_tapparella();
- else if (comando == "ABBASSA")
- abbassa_tapparella();
- else if (comando == "FERMA")
- ferma_tapparella();
- }
- void alza_tapparella() {
- Serial.println("entro in alza_tapparella");
- stato = "ALZA";
- Serial.println(stato);
- Serial.println("esco da alza_tapparella");
- }
- void abbassa_tapparella() {
- Serial.println("entro in abbassa_tapparella");
- stato = "ABBASSA";
- Serial.println(stato);
- Serial.println("esco da abbassa_tapparella");
- }
- void ferma_tapparella() {
- Serial.println("entro in ferma_tapparella");
- stato = "FERMA";
- Serial.println(stato);
- Serial.println("esco da ferma_tapparella");
- }
- void loop(void) {
- http_server.handleClient();
- delay(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement