added administrable interval to query for changes. now wifi_schedule daemon uses tmpfs as temporary storage for wifi_schedule config
added administrable interval to query for changes. now wifi_schedule daemon uses tmpfs as temporary storage for wifi_schedule config

--- a/wifischedule-luci/Makefile
+++ b/wifischedule-luci/Makefile
@@ -9,7 +9,7 @@
 
 PKG_NAME:=luci-app-wifischedule
 PKG_VERSION:=0.1
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 include $(INCLUDE_DIR)/package.mk
 

--- a/wifischedule-luci/files/usr/lib/lua/luci/model/cbi/wifi_schedule/schedule.lua
+++ b/wifischedule-luci/files/usr/lib/lua/luci/model/cbi/wifi_schedule/schedule.lua
@@ -2,11 +2,11 @@
 require("luci.tools.webadmin")
 
 m = Map("wifi_schedule", translate("Wifi Schedule"),
-	translate(""))
+	translate("Wifi Schedule is a very useful app which will allow you to manage and schedule when your device Wi-Fi will turn on and off."))
 
-s = m:section(TypedSection, "wifischedule", "")
+s = m:section(TypedSection, "days", "Days of the week")
 s.addremove = false
-s.anonymous = false
+s.anonymous = true
 
 s:tab("wd1", translate("Monday"))
 s:tab("wd2", translate("Tuesday"))
@@ -26,5 +26,14 @@
 	end
 end
 
+s = m:section(TypedSection, "options", "Options")
+s.addremove = false
+s.anonymous = true
+
+o = s:option(Value, "interval", translate("Interval to query for changes"), translate("In seconds"))
+o.optional = true
+o.datatype = "and(uinteger,min(30))"
+o.default = 30
+
 return m
 

--- a/wifischedule/Makefile
+++ b/wifischedule/Makefile
@@ -9,7 +9,7 @@
 
 PKG_NAME:=wifischedule
 PKG_VERSION:=0.1
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 include $(INCLUDE_DIR)/package.mk
 

--- a/wifischedule/files/etc/config/wifi_schedule
+++ b/wifischedule/files/etc/config/wifi_schedule
@@ -1,3 +1,7 @@
 
-config wifischedule 'Days'
+config days
 
+config options
+	option interval '60'
+
+

--- a/wifischedule/files/usr/sbin/wifi_schedule
+++ b/wifischedule/files/usr/sbin/wifi_schedule
@@ -2,25 +2,33 @@
 
 echo "$$" > /var/run/wifi_schedule.pid
 
+logger "wifi_schedule is starting"
+mkdir -p /var/wifi_schedule
+cp /etc/config/wifi_schedule /var/wifi_schedule
+
 while [ 1 ] ; do
 	day_hour=$(date +"%u_%k" | tr -d ' ')
-	enabledoncurrenthour="x$(uci -q get wifi_schedule.Days.`echo $day_hour`)"
+	enabledoncurrenthour="x$(uci get -q -c /var/wifi_schedule wifi_schedule.@days[0].`echo $day_hour`)"
 
 	if [ $enabledoncurrenthour == "x1" ]
 	then
 		if [ "x$(uci -q -P /var/state/ get wireless.@wifi-iface[0].up)" != "x1" ]
 		then
-        	        logger "wifi is enabled $day_hour and wifi is off, turn on"
-                	wifi up
+			logger "wifi_schedule: wifi is enabled $day_hour and wifi is off, turn on"
+			wifi up
 		fi
 	else
 		if [ "x$(uci -q -P /var/state/ get wireless.@wifi-iface[0].up)" == "x1" ]
-	        then
-        	        logger "wifi is disabled $day_hour and wifi is on, turn off"
-	                wifi down
-        	fi
+		then
+			logger "wifi_schedule: wifi is disabled $day_hour and wifi is on, turn off"
+			wifi down
+		fi
 	fi
 
-	sleep 30
+	timetosleep=$(uci -q -c /var/wifi_schedule get wifi_schedule.@options[0].interval)
+	if [ $timetosleep -lt 30 ] || [ $timetosleep == "" ]
+	then
+		timetosleep=30
+	fi
+	sleep $timetosleep
 done
-

comments