ayushsharma82 / ESP-DASH

Blazing fast library to create a functional, on-device dashboard for ESP8266 / ESP32 / RP2040
https://espdash.pro
GNU General Public License v3.0
978 stars 200 forks source link

API Access #215

Closed usairforce456 closed 4 months ago

usairforce456 commented 5 months ago

Is there an API available through ESP-dash or an easy way to integrate one? While the dash does a great job for displaying data and controlling relays, i would also like to be able to use an api to make calls to update other devices

I would like a suggestion to integrate either my own api with the included web server or have ESP-Dash provide its own. Willing to pay for pro to get this feature

I already tried running another web server on the esp32 with a easy to use api, but the esp did not like that very well

mathieucarbou commented 5 months ago

I have teh same need in my YaSolR project. You can easily create your own REST API with ESPAsyncWebServer.

Example:

  webServer
    .on("/api/router/relay1", HTTP_POST, [](AsyncWebServerRequest* request) {
      if (relay1.isEnabled() && request->hasParam("state", true)) {
        String state = request->getParam("state", true)->value();
        uint32_t duration = request->hasParam("duration", true) ? request->getParam("duration", true)->value().toInt() : 0;
        if (state == YASOLR_ON)
          Mycila::RelayManager.tryRelayState("relay1", true, duration);
        else if (state == YASOLR_OFF)
          Mycila::RelayManager.tryRelayState("relay1", false, duration);
      }
      request->send(200);
    })
    .setAuthentication(YASOLR_ADMIN_USERNAME, config.get(KEY_ADMIN_PASSWORD));
github-actions[bot] commented 4 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

ayushsharma82 commented 4 months ago

I can only think of the same thing which @mathieucarbou proposed. ESP-DASH is not meant to be your complete backend, therefore there is no standard API, It's only a UI library which holds states.