luci icon indicating copy to clipboard operation
luci copied to clipboard

Feature request: Tilt/Pan for Dlink camera DCS-5030L

Open aguaviva opened this issue 8 months ago • 5 comments

What would you like to see in luci?

I successfully got pan&tilt working using this micropython script:

import os  # Import os to run shell commands

# coil sequence to move stepper motors
vertical = [14, 15, 16, 17]
horizontal = [18, 19, 20, 21]


def move(iterations, vel, commands):
    p = 0
    for i in range(iterations):
        str1 = "gpioset -c 0 -t0 %i=0" % commands[ p % len(commands)]
        str2 = "gpioset -c 0 --hold-period 2ms -t0 %i=1" % commands[ (p+vel) % len(commands)]
        os.system(str1+";"+str2)
        p+=vel

    str1 = "gpioset -c 0 -t0 %i=0" % commands[ p % len(commands)] #deenergize stepper coil
    os.system(str1)

def test():
    move(300, -1, horizontal)
    move(100, 1, vertical)
    move(300, 1, horizontal)
    move(100, -1, vertical)

if __name__ == "__main__":
    test()

However I failed miserably writing a lucy module (too complex), any help on how to create a lua module that show 4 buttons or how to add them to mjpg-streamer is very welcome.

aguaviva avatar Apr 22 '25 23:04 aguaviva

I recommend writing the above in ucode, which runs on the router, and calls the named commands. Check through the repo for .uc files. Then the JS front end can call the ucode script.

For guidance, some good examples to check are luci-app-ddns, and luci-proto-wireguard.

systemcrash avatar Apr 23 '25 13:04 systemcrash

What is the JS frontend? I'd appreaciate a lot having some clear documentation and a simple sample. The samples you mentions seem to have a lot of stuff that is not clear whether all that is really needed. I'd love to contribute to this fantastic project to be honest.

aguaviva avatar Apr 23 '25 18:04 aguaviva

I admit they're not trivial, so I generally don't undertake them for rare cases like this, but if you make a PR I can give some corrections. Clone this repo and check the luci-app-example (it's quite simple).

systemcrash avatar Apr 23 '25 20:04 systemcrash

Before that I want to name the GPIO pins that driver the stepper motors, I was able to do it with the LEDs (and also exposed the SD card and buttons of my device, PR sent!). I tried assigning names to the GPIOs that drive the stepper motors but it didn't work very well, anyway I am not sure if this is the right approach.

Is this something you can offer guidance with?

aguaviva avatar Apr 26 '25 19:04 aguaviva

You probably have an error when the vel is -1. Please check. The Python is too big for routers, the ucode (JS flavor) is installed in the OpenWrt but here just the plain shell script to do same:

#!/bin/sh
# coil sequence to move stepper motors
vertical="14 15 16 17"
horizontal="18 19 20 21"

move() {
  iterations="$1"
  vel="$2"
  commands="$3"
  p=0
  for i in $(seq 0 "$iterations"); do
    cmd_num_1=$((i % 4 + 1)) # number of command, starting from 1
    cmd1=$(echo "$commands" | cut -d ' ' -f $cmd_num_1) # get N-th command from $commands
    next_p=$((p + vel))
    cmd_num_2=$((next_p % 4 + 1)) # number of command, starting from 1
    cmd2=$(echo "$commands" | cut -d ' ' -f $cmd_num_2) # get N-th command from $commands

# uncomment for debug:
#    echo "i=$i cmd_num_1=$cmd_num_1 cmd1=$cmd1"
#    echo "i=$i cmd_num_2=$cmd_num_2 cmd2=$cmd2 next_p=$next_p"
    gpioset -c 0 -t0 "$cmd1"=0
    gpioset -c 0 --hold-period 2ms -t0 "$cmd2"=1
    p="$next_p"
  done
  cmd_num_3=$((p % 4 + 1)) # number of command, starting from 1
  cmd3=$(echo "$commands" | cut -d ' ' -f $cmd_num_3)  # get N-th command from $commands
  gpioset -c 0 -t0 "$cmd3"=0
}

move 300 -1 "$horizontal"
move 100 1 "$vertical"
move 300 1 "$horizontal"
move 100 -1 "$vertical"

You can put the script into a router and call it from JS with fs.exec(). Here is a sample

https://github.com/openwrt/luci/blob/master/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_keys.js#L148

Additionally you can turn your script into rpcd service and call it from UBUS. See https://openwrt.org/docs/techref/ubus and those two apps luci-app-ddns and luci-proto-wireguard that systemcrash suggested. But that would be overcomplication as for me.

If you wish to learn how to develop apps start from the https://github.com/openwrt/luci/tree/master/applications/luci-app-example and check wiki https://github.com/openwrt/luci/wiki

yurtpage avatar May 24 '25 18:05 yurtpage