Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

How to use lwip_setsockopt with ESP8266?? Error: undefined reference to `lwip_setsockopt'

I am including this file:

#include "lwip/sockets.h"

Defining those on mos.yml:

cdefs:
  LWIP_SOCKET: 1
  LWIP_COMPAT_SOCKETS: 1
  MG_LWIP: 1

I can see the LIBs are under the folder below:
...projectpath/deps/modules/mongoose-os/fw/tools/docker/esp8266/cs_lwip/src/include/lwip/

I always get the error above:

make: Entering directory '/app'
  LD    /Users/gustavomorais/Documents/Dev/mongoose/skyProxy/build/objs/skyProxy.elf
/Users/gustavomorais/Documents/Dev/mongoose/skyProxy/build/objs/main.c.o:(.text.mgos_app_init+0x40): undefined reference to `lwip_setsockopt'
/Users/gustavomorais/Documents/Dev/mongoose/skyProxy/build/objs/main.c.o: In function `mgos_app_init':
/Users/gustavomorais/Documents/Dev/mongoose/skyProxy/src/main.c:249: undefined reference to `lwip_setsockopt'
collect2: error: ld returned 1 exit status
make: *** [/Users/gustavomorais/Documents/Dev/mongoose/skyProxy/build/objs/skyProxy.elf] Error 1
/mongoose-os/fw/platforms/esp8266/Makefile.build:399: recipe for target '/Users/gustavomorais/Documents/Dev/mongoose/skyProxy/build/objs/skyProxy.elf' failed

Comments

  • rojerrojer Dublin, Ireland

    socket support won't work on esp8266, you'll need to use mongoose api for networking. which options are you looking to set, specifically?

  • edited October 8

    Hi rojer!
    Thanks for your reply.

    Basically, I need to find DLNA enabled devices in my local network (SmartTV, DLNA server etc) using ESP8266 (nodemcu board).
    For this, I need to use SSDP (UDP publish/listen and join a group).

    The function "lwip_setsockopt" would be use to join a group in multicast UDP and listen to SSDP responses...
    If you have an alternative for that, you will save my life!!

    As reference, this is a Android/Java implementation of the same thing:

    //####################
    //QUERY DEVICES
    //####################
    
    private java.net.MulticastSocket skt;
    public static void sendSearchMessage(InetAddress src) throws IOException {
        //The default SSDP multicast address and port
        InetSocketAddress adr = new InetSocketAddress(InetAddress.getByName("239.255.255.250"), 1900);
    
        java.net.MulticastSocket skt = new java.net.MulticastSocket(null);
        skt.bind(new InetSocketAddress(src, 1901));
        skt.setTimeToLive(4);
        StringBuffer packet = new StringBuffer();
    
        //Ask all devices on the network to respond if they’re UPNP media renderers
        packet.append("M-SEARCH * HTTP/1.1\r\n");
        packet.append("HOST: 239.255.255.250:1900\r\n");
        packet.append("MAN: \"ssdp:discover\"\r\n");
        packet.append("MX: 3\r\n");
        packet.append("ST: urn:schemas-upnp-org:device:MediaRenderer:1\r\n\r\n");
    
        String toSend = packet.toString();
        byte[] pk = toSend.getBytes();
        //Send the packet on its way
        skt.send(new DatagramPacket(pk, pk.length, adr));
        skt.disconnect();
        skt.close();
    }
    
    
    //####################
    //LISTEN FOR DEVICES
    //####################
    
    private final Object REGISTRATION_PROCESS = new Object();
    private java.net.MulticastSocket skt;
    private DatagramPacket input;
    private DirectvDiscoveryResultsHandler handler;
    
    private void startMultiCastSocket() throws IOException {
        int bindPort = 1901;
    
        skt = new java.net.MulticastSocket(null);
        skt.bind(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), bindPort));
        skt.setTimeToLive(4);
        skt.setSoTimeout(3000);
        //SSDP uses 239.255.255.250 as its multicast address
       skt.joinGroup(InetAddress.getByName("239.255.255.250"));
        byte[] buf = new byte[2048];
        input = new DatagramPacket(buf, buf.length);
    }
    

    Thanks

Sign In or Register to comment.