ESP8266 Webserver Project

Moderator: Sprite_tm

User avatar
By metalphreak
#22423 The hostname redirection doesn't work for me when connecting via the SoftAP, presumably because my devices aren't getting an ip response for the default esp8266.local hostname. Rather than mess around with hostnames, I've written a function to simply redirect to the SoftAP ip address directly.

Function is "cgiRedirectApClientToIP" and goes in httpd.c (and the definition in the httpd.h file).
Does a similar check as the Hostname redirect, except instead of checking if the hostname matches the set hostname, it check if it matches the SoftAP IP address.

Change the first BuiltInURL to {"*", cgiRedirectApClientToIP, NULL}

Code: Select allint ICACHE_FLASH_ATTR cgiRedirectApClientToIP(HttpdConnData *connData) {
   uint32 *remadr;
   struct ip_info apip;
   char buff[1024];
   char ipaddstr[16];
   int x=wifi_get_opmode();
   //Check if we have an softap interface; bail out if not
   if (x!=2 && x!=3) return HTTPD_CGI_NOTFOUND;
   remadr=(uint32 *)connData->conn->proto.tcp->remote_ip;
   wifi_get_ip_info(SOFTAP_IF, &apip);
   if ((*remadr & apip.netmask.addr) == (apip.ip.addr & apip.netmask.addr)) {
      if (connData->conn==NULL) {
         //Connection aborted. Clean up.
         return HTTPD_CGI_DONE;
      }
      os_sprintf(ipaddstr, "%d.%d.%d.%d", IP2STR(&apip.ip));
      //check if hostname is already the http SoftAP IP address
      if (connData->hostName==NULL || os_strcmp(connData->hostName, ipaddstr)==0) return HTTPD_CGI_NOTFOUND;
      //if not, redirect to SoftAP IP address
      os_sprintf(buff, "http://%s/", ipaddstr);
      os_printf("Hostname received is: %s\n", connData->hostName);
      os_printf("Redirecting to hostname url %s\n", buff);
      httpdRedirect(connData, buff);
      return HTTPD_CGI_DONE;
   } else {
      return HTTPD_CGI_NOTFOUND;
   }
}


Not sure if changes can be submitted to your git repo? I'm more of a Github.App user :lol:
User avatar
By Sprite_tm
#24001
metalphreak wrote:The hostname redirection doesn't work for me when connecting via the SoftAP, presumably because my devices aren't getting an ip response for the default esp8266.local hostname.


I think this is because .local is actually a special TLD that is used by mdns; I think that confuses the clients. In my latest commits, I changed the TLD; care to re-try?
User avatar
By kathir
#31203 Sir
GREAT POST I COMPILED AND CREATED libesphttpd success fully in window platform
thanks to the author
BUT WHEN I COMPILE esphttpd up to LD build ok
FW firmware
]usr/bin/env python No such file or directory


ERROR

HOW TO SOLVE

M.Kathiresan
INDIA