2

In an attempt to reduce risk to an IOT device I'd like it to enable wifi on a schedule, say only between 00:00 and 00:03 every day. Only just enough to upload a log file to my server, and then disable the networking again for 24 hours.

Is there a simple config or tool to help me set that up? Or is it easily scripted in python or such if I set it on a CRON job?

Matt Welander
  • 133
  • 1
  • 6

1 Answers1

1

One way (not necessarily the best way) to disable wlan0 on your RPi is with rfkill. Before going further, I should state the obvious for clarity: Once you've disabled wlan0, it cannot be used to communicate with the device. So - if wlan0 is your only interface, you will need to do some planing; i.e. how to connect to your RPi in the absence of wlan0.

That said, here's a cron job that should do what you want:

Since rfkill typically requires root privileges, we'll use root's crontab for this:

$ sudo crontab -e

root crontab opens in your chosen default editor...

The following crontab entries should toggle wlan0 ON at midnight (local time), and OFF again 3 minutes later:

0 0 * * * /usr/sbin/rfkill unblock wlan0 
3 0 * * * /usr/sbin/rfkill block wlan0 

Save your crontab & exit the editor. That should meet your minimum requirement; I'll leave it to you to embellish the crontab entries for output redirection - or development of a script to perform any related tasks.

You may also wish to consider how to handle things following a reboot. Let us know if you have further questions.

Seamus
  • 23,558
  • 5
  • 42
  • 83