Ko'p faylli arduino esp8266 eskiz serverga havola bilan taqsimlanadi

@Gee_Bee: @/maslahatiga ko'ra, birikma oqimiga o'tkazildi

Men Arduino uchun kutubxonani yozish -ni ishga tushirishingiz mumkin.    Sketchni bir nechta faylga aylantirish va Sinf ichidagi sinflar   - Boshlang'ich ro'yxatlari . ESP8266WebServer ning bir misoliga ishlov berish uchun ishlaydigan o'zgaruvchilarga tashqi manbalardan ham foydalanish mumkin.   turli fayllar hali ham tashqarida.

Mening eskizlarim katta bo'lganda, kod bitta fayl ko'rinishida dahshatli ko'rinadi va global o'zgaruvchilar soni juda yuqori.

Mening eskizimning webconfig qismi uchun qurilma onlayn rejimga o'tishga urinadi va agar u muvaffaqiyatsiz bo'lsa, mavjud Wi-Fi tarmoqlarini tekshiradi, Access Point rejimiga kiradi, serverni ishga tushiradi, SSID ro'yxatini yuboradi va SSID/parol jufti. Server faqat konfiguratsiya uchun.

Ideal holda tozalashni istayman main.ino faylga o'xshash

    #include "config.h"
    void setup(){
        Serial.begin(115200);
        Serial.println();
        Serial.println("--------------------------");
      Serial.println("ESP8266 multifile");
      Serial.println("--------------------------");
      getOnline();
    }
    void loop(){
        if(IN_CONFIG_MODE){
           server.handleClient();
        }
    }

config.h bilan o'xshash bir narsa bor.

    #ifndef config_h
    #define config_h
        #include 
        #include 
        ESP8266WebServer server;
        void getOnline();
    #endif

keyin main.ino dastur kodini server misoliga keltiradi, shuning uchun uni tinglash uchun config.cpp asosiy ko'chadan.

#include "config.h"
#include 
#include 
#include 

char *espssid = "espAPsb";
char *ssid = "street_no_vale2";
char *pwd = "jjjjjjjjx";
char ssids[300];

extern server(80);

void handleRoot(){
    server.send(200, "text/html", "

root of espAPsb AP server

");
    //send json of available ssids
}

void scan(){
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);
  int n = WiFi.scanNetworks();
  Serial.println("scan done");  
  if (n == 0)
    Serial.println("no networks found");
  else
  {
    Serial.print(n);
    Serial.println(" networks found");
    for (int i = 0; i < n; ++i)
    {
     //Print SSID and RSSI for each network found
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));
      Serial.print(" (");
      Serial.print(WiFi.RSSI(i));
      Serial.print(")");
      Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
      delay(10);
    }
  }
  Serial.println("");   
}

void setupAP(){
    WiFi.softAP(espssid);
    server.on("/", handleRoot);
    server.begin();
  Serial.println();
  Serial.print("connected as AP ");
  Serial.println(espssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.softAPIP());  
}

void getOnline(){
    WiFi.begin(ssid, pwd);
  int tries =0;
  int success=1;
  while (WiFi.status() != WL_CONNECTED ) {
    delay(500);
    Serial.print(".");
    tries++;
    if (tries==15){
      success=0;
      Serial.println("WiFi not connected");
      scan();
      setupAP();
      break;
    }
  }
  if (success){
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());    
  } 
}
1

Javob yo'q

0