OpenSprinkler › Forums › Hardware Questions › OpenSprinkler Pi (OSPi) › ospi2.img seems outdated › Reply To: ospi2.img seems outdated
sakos
These are the changes. I also added the clearing of all stations in case of managed shutdown of OSPI. I think it is necessary to prevent unwanted water leak due to a valve left open accidentally. I would like to mention here that RF stations are not closed by forced clearing of stations.
OpenSprinkler.h
@@ -38,6 +38,8 @@
#include <string.h>
#include <unistd.h>
#include "etherport.h"
+ #include "linux/watchdog.h"
+ #include "sys/ioctl.h"
@@ -195,5 +197,6 @@ private:
#endif
#endif // LCD functions
};
+ static int deviceHandle = -1; // Watchdog device handler
defines.h
@@ -378,6 +378,7 @@ typedef enum {
typedef short int16_t;
typedef unsigned short uint16_t;
typedef bool boolean;
+ #define WATCHDOG_TIMEOUT 15
main.cpp
@@ -249,6 +249,17 @@ ISR(WDT_vect)
#else
void do_setup() {
+
+#if defined(OSPI)
+ // Try to inicialize Watchdog device
+ // deviceHandle >=0 indicates success
+ if ((deviceHandle = open("/dev/watchdog", O_WRONLY)) < 0) {
+ DEBUG_PRINTLN("Error: Couldn't open watchdog device!");
+ } else {
+ ioctl(deviceHandle, WDIOC_SETTIMEOUT, WATCHDOG_TIMEOUT);
+ DEBUG_PRINTLN("Watchdog device opened.");
+ }
+#endif
@@ -647,6 +659,11 @@ void do_loop()
// check weather
check_weather();
+ // kick Watchdog
+ // deviceHandle can have valid value only in case of OSPI
+ if (deviceHandle >= 0) {
+ ioctl(deviceHandle, WDIOC_KEEPALIVE, 0);
+ }
}
OpenSprinkler.cpp
@@ -419,13 +419,31 @@ void OpenSprinkler::reboot_dev() {
#if defined(DEMO)
// do nothing
#else
+ // Reset all stations before quit
+ clear_all_station_bits();
+ apply_all_station_bits();
+
sync(); // add sync to prevent file corruption
- reboot(RB_AUTOBOOT);
+ // Stop Watchdog by sending magic character
+ // deviceHandle can have valid value only in case of OSPI
+ if (deviceHandle >= 0) {
+ write(deviceHandle, "V", 1);
+ };
+ reboot(RB_AUTOBOOT);
#endif
}
/** Launch update script */
void OpenSprinkler::update_dev() {
+ // Reset all stations before quit
+ clear_all_station_bits();
+ apply_all_station_bits();
+
+ // Stop Watchdog by sending magic character
+ // deviceHandle can have valid value only in case of OSPI
+ if (deviceHandle >= 0) {
+ write(deviceHandle, "V", 1);
+ };
char cmd[1024];
sprintf(cmd, "cd %s & ./updater.sh", get_runtime_path());
system(cmd);
Apply these changes and build OSPI with sudo ./build.sh ospi
command.
To make watchdog work you have to edit /etc/modules file (sudo nano /etc/modules) and add this line to the end:
bcm2708_wdog
After restart the watchdog is operating. To test it stop the software with sudo /etc/init.d/OpenSprinkler.sh stop
command. You will observe that the connection to the OSPI system is lost but will be automatically available again within 30-40 seconds.
I would appreciate if these changes were added to the official release.