(Last Updated: September 28, 2020)

upnp event proxy



  • I've made some mods to Futzle's upnp event proxy and placed it in the AltApp store (with her permission). ie it's here in GitHub.

    Now it seems some people say it works with openLuup already. However the version released by Futzle required two things in order to function:

    1. the file L_UPnPProxy1.lua was expected to be compressed, as it would be on a Vera eg: L_UPnPProxy1.lua.lzo

    2. the hardware needs to be running OpenWrt; ie as per Vera does.

    I modified the code to fix point 1) (see the script below) but I would like to see point 2) resolved, so a RasPi can be used. That is modify the script to allow a deamon to be run on a RasPi without fiddling around with say "/etc/rc.local".

    So has any one got the proxy going on any hardware that is NOT using OpenWrt ? I'm unsure how to do it.

    Basically this script and/or the script it includes needs to be modified or even merged to suit. You'll note that after the shebang, it requires the file "etc/rc.common" (reproduced further below). The latter appears to be some sort of template file that is overriden as required by the first script. It cites "$IPKG_INSTROOT", whatever that is. However it may be possible to make use of it somehow on a RasPi?

    #!/bin/sh /etc/rc.common
    
    # Copyright (C) 2007 OpenWrt.org
    START=80
    PID_FILE=/var/run/upnp-event-proxy.pid
    PROXY_DAEMON=/tmp/upnp-event-proxy.lua
    
    start() {
    	if [ -f "$PID_FILE" ]; then
    		# May already be running.
    		PID=$(cat "$PID_FILE")
    		if [ -d "/proc/$PID" ]; then
    			COMMAND=$(readlink "/proc/$PID/exe")
    			if [ "$COMMAND" = "/usr/bin/lua" ]; then
    				echo "Daemon is already running"
    				return 1
    			fi
    		fi
    	fi
    
        # openLuup: Look for the uncompressed proxy daemon Lua source.
        if [ -f /etc/cmh-ludl/L_UPnPProxyDaemon.lua ]; then
            PROXY_DAEMON_UC=/etc/cmh-ludl/L_UPnPProxyDaemon.lua
        elif [ -f /etc/cmh-ludl/files/L_UPnPProxyDaemon.lua ]; then
            PROXY_DAEMON_UC=/etc/cmh-ludl/files/L_UPnPProxyDaemon.lua
    
        # Vera 3: Else look for the compressed proxy daemon Lua source.
        elif [ -f /etc/cmh-ludl/L_UPnPProxyDaemon.lua.lzo ]; then
            PROXY_DAEMON_LZO=/etc/cmh-ludl/L_UPnPProxyDaemon.lua.lzo
        elif [ -f /etc/cmh-lu/L_UPnPProxyDaemon.lua.lzo ]; then
            PROXY_DAEMON_LZO=/etc/cmh-lu/L_UPnPProxyDaemon.lua.lzo
        fi
    
    
        if [ -n "$PROXY_DAEMON_UC" ]; then
            cp "$PROXY_DAEMON_UC" "$PROXY_DAEMON"
        elif [ -n "$PROXY_DAEMON_LZO" ]; then
            /usr/bin/pluto-lzo d "$PROXY_DAEMON_LZO" "$PROXY_DAEMON"
        fi
    
    
    	# Close file descriptors.
    	for fd in /proc/self/fd/*; do
    		fd=${fd##*/}
    		case $fd in
    			0|1|2) ;;
    			*) eval "exec $fd<&-"
    		esac
    	done
    
    	# Run daemon.
    	/usr/bin/lua "$PROXY_DAEMON" </dev/null >/dev/null 2>&1 &
    	echo "$!" > "$PID_FILE"
    }
    stop() {
    	if [ -f "$PID_FILE" ]; then
    		PID=$(cat "$PID_FILE")
    		if [ -d "/proc/$PID" ]; then
    			COMMAND=$(readlink "/proc/$PID/exe")
    			if [ "$COMMAND" = "/usr/bin/lua" ]; then
    				/bin/kill -KILL "$PID" && /bin/rm "$PID_FILE"
    				return 0
    			fi
    		fi
    	fi
    
    	echo "Daemon is not running"
    	return 1
    }
    
    

    And here is "etc/rc.common" as found in OpenWrt initscripts. Note the command actions it implements - in particular disable & enable, which set up Sxxy (start) & Kxxy (stop) files in the directory "etc/rc.d", which is not found in the RasPi directory structure:

    #!/bin/sh
    # Copyright (C) 2006-2009 OpenWrt.org
    
    . $IPKG_INSTROOT/etc/functions.sh
    
    initscript=$1
    action=${2:-help}
    shift 2
    
    start() {
    	return 0
    }
    
    stop() {
    	return 0
    }
    
    reload() {
    	return 1
    }
    
    restart() {
    	trap '' TERM
    	stop "$@"
    	start "$@"
    }
    
    boot() {
    	start "$@"
    }
    
    shutdown() {
    	stop
    }
    
    disable() {
    	name="$(basename "${initscript}")"
    	rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name
    	rm -f "$IPKG_INSTROOT"/etc/rc.d/K??$name
    }
    
    enable() {
    	name="$(basename "${initscript}")"
    	disable
    	[ "$START" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
    	[ "$STOP"  ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}"
    }
    
    enabled() {
    	name="$(basename "${initscript}")"
    	[ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
    }
    
    depends() {
    	return 0
    }
    
    help() {
    	cat <<EOF
    Syntax: $initscript [command]
    
    Available commands:
    	start	Start the service
    	stop	Stop the service
    	restart	Restart the service
    	reload	Reload configuration files (or restart if that fails)
    	enable	Enable service autostart
    	disable	Disable service autostart
    $EXTRA_HELP
    EOF
    }
    
    . "$initscript"
    
    ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
    list_contains ALL_COMMANDS "$action" || action=help
    [ "$action" = "reload" ] && action='eval reload "$@" || restart "$@" && :'
    $action "$@"
    
    


  • Can’t you just install ubuntu (it’s easy with windows subsystem for Linux , if you’re a windows user) and try it?

    I will just remove this part completely and give instructions to manually install the daemon. People using openluup are usually able to do it and I’ll prefer this any day over a script messing with my config files.



  • For this sort of thing (also like mounting file systems) I do this in Lua Startup. Should be easy enough to check whether it’s already running (eg. Is the socket in use.)



  • @therealdb said in upnp event proxy:

    prefer this any day over a script messing with my config files

    Totally in agreement as per:

    ..run on a RasPi without fiddling around with say "/etc/rc.local"

    This makes some sense also:

    ... I do this in Lua Startup

    Well it would obviously require a major rework of some of the code but some users do find installing stuff manually not so easy - including me at times! Something to perhaps think about.I really want my Sonos stuff running under openLuup.



  • You don’t need the proxy in order to run the Sonos plugin...?



  • No you don't need it but it helps makes the Sonos plugin more responsive. Speaking of which, it would be good to see the Sonos plugin in GitHub and in the AltApp store.



  • Isn't rigpapa new version already on Github?



  • Yep - you're right - it's in GitHub. My memory is playing tricks on me again. I read that rigpapa had it available in the AltApp store but I can't see it there - that's the bit that's missing.



  • Ping him, it's been very critical about Ezlo lately, so maybe it's willing to fix it, if necessary.



  • @a-lurker said in upnp event proxy:

    Well it would obviously require a major rework of some of the code but some users do find installing stuff manually not so easy - including me at times!

    Speaking of this, you can just detect openluup and stop doing the magical thing. Remember openluup can run on windows and Macos too and I'm not sure daemon could be so generalized.


Log in to reply