Xcode and eps32 wifi/ble

hello,

I'm pretty new to programming (swift,c++,html, css) I've started working with esp32 to make a home automation project with personal interface.

I'm finding lots of problems to get this going..

at the moment I've tried couple of things:

connect testLed to esp32 to see if code & interface works. first I tried with AsyncWebServer & made a custom webpage with html with the ledbutton. when I push the button the led turns on/off correctly.. Problem: 5-6second delay..

I've tried the same apStyle, remaining the delay...

when I make my custom app with Xcode & make actions to go to the url with paths /on, /off I can control the led with my custom Xcode app.. still remaining a delay of 5-6seconds..

Question: How can I fix everything so it's a max delay of 1second? (I'll post all of my code after this post) or is the problem cause of the contact server & not directly contact esp32?

would ble be better for this project? in my opninion not cause I would like to control everything from anywhere... ble means I need to be at home to maintain connection..

I've been looking up, changing code, & not going anywhere anymore :( tried different GPIO's for led..

coding only for one or 2led's to keep it minimal to optimize, & afterwards expand to the full home with relais en mosfet connections..

working with homekit & homespan is working good, but also delayed 3seconds.. better then what I have but still to slow..

// code for esp32 (spiffs html file is below this code) /*

  • JK electronics

*/

#include "WiFi.h"

#include "ESPAsyncWebServer.h"

#include "SPIFFS.h"

// Replace with your network credentials

const char* ssid = "*****"; //Replace with your own SSID

const char* password = "*****"; //Replace with your own password

const int ledPin = 17;

String ledState;

// Create AsyncWebServer object on port 80

AsyncWebServer server(80);

// Replaces placeholder with LED state value

String processor(const String& var){

Serial.println(var);

if(var == "LED_STATE"){

if(digitalRead(ledPin)){
  ledState = "ON";
}

else{
  ledState = "OFF";
}

Serial.print(ledState);
return ledState;

}

return String(); }

void setup(){

Serial.begin(115200);

pinMode(ledPin, OUTPUT);

// Initialize SPIFFS

if(!SPIFFS.begin(true)){ Serial.println("An Error has occurred while mounting SPIFFS"); return; }

// Connect to Wi-Fi

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi.."); }

// Print ESP32 Local IP Address

Serial.println(WiFi.localIP());

// Route for root / web page

server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send(SPIFFS, "/JKelectronics.html", String(), false, processor); });

// Route for image heading

server.on("/logoJK.jpg", HTTP_GET, [](AsyncWebServerRequest *request){ request->send(SPIFFS, "/logoJK.jpg", "image/jpg"); });

// Route to set GPIO to HIGH

server.on("/led17On", HTTP_GET, [](AsyncWebServerRequest *request){ digitalWrite(ledPin, HIGH);
request->send(SPIFFS, "/JKelectronics.html", String(), false, processor); });

// Route to set GPIO to LOW

server.on("/led17Off", HTTP_GET, [](AsyncWebServerRequest *request){ digitalWrite(ledPin, LOW);
request->send(SPIFFS, "/JKelectronics.html", String(), false, processor); });

// Start server

server.begin(); }

void loop(){

}

// html code for making the webpage

         <style>
          .navigator {
              color: rgb(35, 31, 67); 
              text-decoration:underline;
            }
         </style>
        </h2>
    </nav>
    <br>
    <br>
    <div id="buttons" name="buttons">
        <p>LightState: <strong>%LED_STATE%</strong></p>
        <button><a href="/led17On" class="lights">Light on</a></button>
        <button><a href="/led17Off" class="lights">Light off</a></button>
    <style>
        .lights {
            color:rgb(230, 190, 138)
        }
        button{
            background-color: rgb(35, 31, 67);
            border-width: 100%;
            border-radius: 20px;
            border-style: double;
            padding: 5%;
        }
      </style>
    </div>
</body>

Xcode code: I've used the NSurl method to direct action to browser adres. ex: 192.168.*./led17on. it works but it's also very slow..

Xcode and eps32 wifi/ble
 
 
Q