This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3220S-LAUNCHXL: Register http MDNS service for AP Mode

Part Number: CC3220S-LAUNCHXL

This is a repost since no one every got back to me on why registering an MDNS http service does not work in AP mode.

I'm trying to register an http mdns service so that when I type in a we browser "http://test.local" in goes to the web page on the device.  The sl_NetAppMDNSRegisterService function returns 0, but I am unable to get to the webpage using http://test.local".  The IP address and mysimplelink.net work just fine.  This is my code I've managed to piece together from various documentation sources...

#define SERVICE_NAME "test._http._tcp.local" 
#define SERVICE_TEXT "p_http"   // I'm not sure what this is supposed to be???

retVal = sl_NetAppStart(SL_NETAPP_MDNS_ID);
// Unregister first, then register to clean up previous registration
// with the same service name.
sl_NetAppMDNSUnRegisterService(0, 0, 0);
retVal = sl_NetAppMDNSRegisterService((_i8 *)SERVICE_NAME, (unsigned char)strlen(SERVICE_NAME), (_i8 *)SERVICE_TEXT, (unsigned char)strlen(SERVICE_TEXT), 200, 2000, 0x00000001);

UART_PRINT("MDNS 1 Registered with NAME: %s & ERROR code: %d\n\r", SERVICE_NAME, retVal);

  • Hi,

    This will only work if your browser supports local service discovery. You usually discover local service through bonjour or similar applications

    Regards,
    Charles O
  • Yes, I understand.  I'm using iOS and have mdns responder installed on windows.  Still doesn't work.

  • Anyone at Texas Instruments?
  • Hi Andrew,

    I added your code into the end of the "wlan_ap_start" command as follows :-

    // wlan_cmd.c
    
    int32_t cmdWlanStartApCallback(void *arg)
    {
        ...
    
        mode = sl_Start(0, 0, 0);
        ASSERT_AND_CLEAN_STARTAP(ret, DEVICE_ERROR, &StartApParams);
    
        if(mode != ROLE_AP)
        {
            UART_PRINT("\n\r[wlan ap start] : Unable to configure AP role.\n\r");
            FreeStartApCmd(&StartApParams);
            return -1;
        }
        else
        {
            app_CB.Role = ROLE_AP;
        }
    
    // Start MDNS
    
    #define SERVICE_NAME "test._http._tcp.local"
    #define SERVICE_TEXT "p_http"
    
        ret = sl_NetAppStart(SL_NETAPP_MDNS_ID);
        UART_PRINT("\n\r[wlan ap start] : sl_NetAppStart ret = %d\n\r", ret);
    
        ret = sl_NetAppMDNSUnRegisterService(0, 0, 0);
        UART_PRINT("\n\r[wlan ap start] : sl_NetAppMDNSUnRegisterService ret = %d\n\r", ret);
    
        ret = sl_NetAppMDNSRegisterService((_i8 *)SERVICE_NAME, (unsigned char)strlen(SERVICE_NAME), (_i8 *)SERVICE_TEXT, (unsigned char)strlen(SERVICE_TEXT), 200, 2000, 0x00000001);
        UART_PRINT("\n\r[wlan ap start] : sl_NetAppMDNSRegisterService MDNS 1 Registered with NAME: %s & ERROR code: %d\n\r", SERVICE_NAME, ret);
    
        FreeStartApCmd(&StartApParams);
        return ret;
    }

    I started the ap in the network_terminal console the received the following output (which includes the console print from my linux machine connecting to the AP) :-

    user:wlan_ap_start -s "my_test_ap"
    
    [NETAPP EVENT] IP set to: IPv4=10.123.45.1 , Gateway=10.123.45.1
    
    [wlan ap start] : sl_NetAppStart ret = -6213 (--> SL_ERROR_NET_APP_MDNS_ALREADY_STARTED)
    [wlan ap start] : sl_NetAppMDNSUnRegisterService ret = 0
    [wlan ap start] : sl_NetAppMDNSRegisterService MDNS 1 Registered with NAME: test._http._tcp.local & ERROR code: 0
    
    [WLAN EVENT] STA was added to AP: BSSID: yy:yy:yy:yy:yy:yy
    [NETAPP EVENT] IP Leased to Client: IP=10.123.45.2
    [WLAN EVENT] STA was removed from AP: BSSID: yy:yy:yy:yy:yy:yy
    

    Then running avahi on the linux machine allows me to see the service advertised on port 200, as a website (_http._tcp) and with the configured txt entry :-

    $ avahi-browse -avr
    
    ...
    
    =  wlan0 IPv4 test                                  Web Site    local
       hostname = [xxxxxxxxxxxx-mysimplelink.local]
       address = [10.123.45.1]
       port = [200]
       txt = ["p_http"]

    Which shows the service advertisement coming through, and that a dns-sd browser should be able to scan for this well-defined web-service and launch a browser on the hostname/port accordingly. Safari on MAC/Windows has a built-in Bonjour discovery tool, which should be able to find this service and launch.  There are a number of iOS apps that can browse for these services, but I'm not aware of support inside the iOS Safari browser.

    If you want to browse directly from the URL bar, you'll need to change the device name as well. I made the following modifications, changing the port (for easier testing), and a more common txt record (not required, but for info).

        // Start MDNS
    #define SERVICE_NAME "test._http._tcp.local"
    #define SERVICE_TEXT "path=/;srcvers=1;productinfo=SimpleLinkWiFi"
    
        ret = sl_NetAppStart(SL_NETAPP_MDNS_ID);
        UART_PRINT("\n\r[wlan ap start] : sl_NetAppStart ret = %d\n\r", ret);
    
        // Unregister first, then register to clean up previous registration
        // with the same service name.
        ret = sl_NetAppMDNSUnRegisterService(0, 0, 0);
        UART_PRINT("\n\r[wlan ap start] : sl_NetAppMDNSUnRegisterService ret = %d\n\r", ret);
    
        ret = sl_NetAppMDNSRegisterService((_i8 *)SERVICE_NAME, (unsigned char)strlen(SERVICE_NAME), (_i8 *)SERVICE_TEXT, (unsigned char)strlen(SERVICE_TEXT), 80, 2000, 0x00000001);
        UART_PRINT("\n\r[wlan ap start] : sl_NetAppMDNSRegisterService MDNS 1 Registered with NAME: %s & ERROR code: %d\n\r", SERVICE_NAME, ret);
    
        ret = sl_NetAppSet(SL_NETAPP_DEVICE_ID, SL_NETAPP_DEVICE_URN, strlen("test"), "test");
        UART_PRINT("\n\r[wlan ap start] : sl_NetAppSet Setting Device Name return : %s : %d\n\r", "test", ret);
    
        FreeStartApCmd(&StartApParams);
        return ret;
    }

    The avavi-record now reports :-

    $ avahi-browse -avr
    
    ...
    =  wlan0 IPv4 test                                  Web Site    local
       hostname = [test.local]
       address = [10.123.45.1]
       port = [80]
       txt = ["path=/;srcvers=1;productinfo=SimpleLinkWiFi"]

    A service discovery application could still scan for services with your particular descriptor, but you'll also be able to browse directly to the advertised "test.local" hostname.  

    Can you give this a try?

    Hope that helps,

    ~roger

  • Hi Roger,

    I'm not sure why I'm getting that error code of 6185 which is duplicate service error code.  I did the unregister right before the register just like you did.

    My iphone will find the webpage via test.local.  However both windows laptop with MDNSresponder installed will not for some reason.  I can't even ping the device using the .local name.  Bonjour browser shows a service for 10.123.45.1:80 _http._tcp. with a path of /

    [wlan ap start] : sl_NetAppSet Setting Device Name return : test : 0
    [NETAPP EVENT] IP Acquired: IP=10.123.45.1 , Gateway=10.123.45.1
    [wlan ap start] : sl_NetAppStart ret = -6213
    [wlan ap start] : sl_NetAppMDNSUnRegisterService ret = 0
    [wlan ap start] : sl_NetAppMDNSRegisterService MDNS 1 Registered with NAME: test._http._tcp.local & ERROR code: 6185
    
    

  • I will also add that a linux machine running avahi and advertising mdns services connect to a windows laptop responds to "ping device.local" just fine. However with the same laptop connected to the simplelink "ping test.local" does not respond. Something seems to be wrong with the mDNS on the simplelink.
  • Hi,

    From errors.h:
    #define SL_ERROR_NET_APP_MDNS_ALREADY_STARTED (-6213L) /* mdns application already started */
    #define SL_ERROR_NET_APP_MDNS_DUPLICATE_SERVICE (-6185L) /* Duplicate service. */

    Jan