Python Packages - RUT956

Hi,

for some monitoring i want to use a RUT956 as a router to give internet access to the pc used for monitoring my sensors.
To reduce my power consumption and the amount of data i want to use a scheduled meassuring process.
For that i need to Wake on lan the pc.

I’d like to use a python script for that because i imagine it beeing the easierst to implement the schedule that is requiered.

As far as i read the following should be possible with the rut956 and shuld work in my case:

  1. use thumb drive to increase strorage capaccity.
  2. install python package “pip”
  3. install python package “wakeonlan”
  4. write code to shedule won

Am i missing something here?

Thanks in advance

Welcome @felix_re :wave:

I don’t think you need to add the complexity of Python script when this feature is already built in to the RUT device itself.

You can use shell command etherwake (type etherwake -u to see help/options) or also API to configure and execute sending WOL packets:

Example

Add a WoL config for a particular device…

/sbin/api post /wol/config '{"data":{"name":"foo","mac": "aa:bb:cc:dd:ee:ff"}}'

Wake that device…

/sbin/api post /wol/actions/wake_device '{"data":{"name":"foo","mac":"aa:bb:cc:dd:ee:ff"}}'

Wake ALL configured devices…

/sbin/api post /wol/actions/wake_all_devices

You can schedule any of this with cron, by editing /etc/crontabs/root

Hi luckman212,

thanks for the reply.
Are there any downsites of using a python script instead of th eon-board wol functionallity?

I’m more comfortabel with python than with bath and cron so it would be earsier for me.

Also I’d like to use just one script for all my purposes:

  1. WoL
  2. SSH form the router onto a pc
  3. Start a python script on the pc via ssh

Thanks in advance

Well, the main downside is having to install the additional packages on each device, which consumes storage space (and there is not much extra space on these devices to begin with).

If you really want to do this, you can try

opkg -e /etc/opkg/openwrt/distfeeds.conf update &&
opkg -e /etc/opkg/openwrt/distfeeds.conf install python3-pip
pip install wakeonlan

Instead of installing the overhead of installing the pip and wakeonlan packages, you could also just use Python’s subprocess module to invoke the builtin etherwake binary:

import subprocess
rc = subprocess.run([ '/usr/bin/etherwake', '00:11:22:33:44:55' ])
print(rc.returncode)

This topic was automatically closed after 15 days. New replies are no longer allowed.