1

I'm currently facing a problem with setting a hostname for the ESP8266. My STM32 is connected to the ESP over Uart and the connection is working. So I'm able so set up a Acccess Point or connect to a Wifi by using AT-commands. Problem is that i always need to figure out my IP and put the IP in the browser which is uncomftable.

I spent the last days to solve this issue and looked in some Arduino/ESP librarys without any success.

In the code there are some lines commented out whith some AT-commands I tried to use. But those weren't working or had issues. The reply of the ESP I put behind the command

...some other code

    Uart_sendstring("AT+RST\r\n", wifi_uart);
    for (int i=0; i<5; i++)
    {
        HAL_Delay(1000);
    }

    /********* AT **********/
    Uart_flush(wifi_uart);
    Uart_sendstring("AT\r\nAT\r\n", wifi_uart);
    while(!(Wait_for("OK\r\n", wifi_uart)));

    Uart_flush(wifi_uart);
    if (AP == CONNECT_AP)
    {

        //test
        Uart_flush(wifi_uart);
        //Uart_sendstring("AT+MDNS=1, my_test, iot, 80\r\n", wifi_uart); ->reply: get hostname fail when mdns
        //Uart_sendstring("AT+CWHOSTNAME=my_test\r\n", wifi_uart); -> reply: ERROR
        //Uart_sendstring("AT+CWHOSTNAME?\r\n", wifi_uart); -> reply: ERROR
        while (!(Wait_for("OK\r\n", wifi_uart)));
        //test end


        /********* AT+CWMODE=1 **********/
        Uart_flush(wifi_uart);
        Uart_sendstring("AT+CWMODE=1\r\n", wifi_uart); // connect to AP
        while (!(Wait_for("OK\r\n", wifi_uart)));

        /********* AT+CWJAP="SSID","PASSWD" **********/
        Uart_flush(wifi_uart);
        sprintf (data, "AT+CWJAP=\"%s\",\"%s\"\r\n", SSID, PASSWD);
        Uart_sendstring(data, wifi_uart);
        while (!(Wait_for("OK\r\n", wifi_uart)));

        /********* AT+CIFSR **********/
        // Zum Anzeigen von IP und Mac-Adresse
        Uart_flush(wifi_uart);
        Uart_sendstring("AT+CIFSR\r\n", wifi_uart);
        while (!(Wait_for("CIFSR:STAIP,\"", wifi_uart)));
        while (!(Copy_upto("\"",My_IP, wifi_uart)));
        while (!(Wait_for("OK\r\n", wifi_uart)));
    }
    else if (AP == OPEN_AP)
    {

        //test
        Uart_flush(wifi_uart);
        //Uart_sendstring("AT+MDNS=1, my_test, iot, 80\r\n", wifi_uart);
        //Uart_sendstring("AT+CWHOSTNAME=my_test\r\n", wifi_uart);
        //Uart_sendstring("AT+CWHOSTNAME?\r\n", wifi_uart);
        while (!(Wait_for("OK\r\n", wifi_uart)));
        //end test

        /********* AT+CWMODE=2 **********/
        Uart_flush(wifi_uart);
        Uart_sendstring("AT+CWMODE=2\r\n", wifi_uart); // open AP
        while (!(Wait_for("OK\r\n", wifi_uart)));

        /********* AT+CWJAP="SSID","PASSWD" **********/
        Uart_flush(wifi_uart);
        sprintf (data, "AT+CWSAP=\"%s\",\"%s\",%d,%d\r\n", SSID, PASSWD, 11, 3);
        Uart_sendstring(data, wifi_uart);
        while (!(Wait_for("OK\r\n", wifi_uart)));
    }
        
    /********* AT+CIPMUX **********/
    Uart_flush(wifi_uart);
    Uart_sendstring("AT+CIPMUX=1\r\n", wifi_uart);
    while (!(Wait_for("OK\r\n", wifi_uart)));

    /********* AT+CIPSERVER **********/
    Uart_flush(wifi_uart);
    Uart_sendstring("AT+CIPSERVER=1,80\r\n", wifi_uart);
    while (!(Wait_for("OK\r\n", wifi_uart)));

I would be very thankful if someone could help me solving this problem.

I'm not very deep in the mdns topic and setting up a Access Point. I'm just trying to open a Website to connect.

Best regards Max

Max
  • 11
  • 3
  • so do you want to name your host "espressif" or "my_test"? AT+HOSTNAME sets the name sent to the DHCP server. the AT+MDNS advertises a service for devices which look up such advertisement. – Juraj Mar 19 '23 at 16:03
  • Thanks for the question. I edited the code to make it equal. my_test would be good. So is one of this calls correct and if so - why it won't work? Is it the wrong sequence I'm calling those commands? – Max Mar 19 '23 at 16:18
  • does the mdns tool on your computer show the service advertised by the esp8266? – Juraj Mar 19 '23 at 16:20
  • Not sure if I understood you correct but if I'm connecting to a WIFI it shows up like: esp-231f3f.fritz.box with the ip 192.168.178.137 When I'm setting up an own AP its called Router and ip 192.168.5.1 When I'm sending one of the commands which are commented out I can't connect to the WIFI or can't set up the AP. – Max Mar 19 '23 at 16:38
  • did you already read this? https://en.wikipedia.org/wiki/Multicast_DNS – Juraj Mar 19 '23 at 17:18
  • yes I have read, but I can not really figure it out. Do I have to send a UDP multicast package to port 5353? – Max Mar 19 '23 at 23:18
  • Instead of using "AT+MDNS=1, my_test, iot, 80\r\n", did you try "AT+MDNS=1, \"my_test\", \"iot\", 80\r\n"? – hcheung Mar 20 '23 at 05:58
  • "AT+MDNS=1, \"my_test\", \"http\", 80\r\n" is working now if I'm connecting to a WIFI. When I'm setting up a Wifi with Access-Point this function call isn't working :/ Any idea why? – Max Mar 20 '23 at 20:13

0 Answers0