revpi connect , use watchdog with python3

Topics about the Hardware of Revolution Pi
Post Reply
DRi
Posts: 7
Joined: 26 Sep 2019, 16:58
Answers: 0

revpi connect , use watchdog with python3

Post by DRi »

Hi guys,
I have some trouble using the watchdog with python3.

I unpluged the wire betwen 6 & 7 (put a switch for convinience ).
The watchdog restarts the device, so that's fine at this point.

But when I want to control it in python that's a mess.
For instance, I want to get temperature and humidity (that's OK) and send them.
The wathdog should restart the device if the time is up for each call (assuming that the call is scheduled every 5 seconds and begins with a wd "restart" ).
But I don't get why it doesn't work: is "rpi.core.wd.value=True" the correct statement ?
The following piece of code worked perfectly when the watchdog wasn't enabled.

Thanks guys :D

Code: Select all

#!/usr/bin/env python3
import time
from timeloop import Timeloop
from datetime import timedelta
import revpimodio2
import requests

tl = Timeloop()
rpi = revpimodio2.RevPiModIO(autorefresh=False)
rpi.handlesignalend()


@tl.job(interval=timedelta(seconds=5))
def sample_job_every_5s():
    rpi.core.wd.value=True
    temperature = int.from_bytes(rpi.io.RS485Input_2.get_value(), "little") / 20
    humidity = int.from_bytes(rpi.io.RS485Input_1.get_value(), "little") / 100
   # r = requests.post('http://192.168.1.50:8080', data={'temperature': temperature, 'humidity': humidity})
    print("ON : {}".format(time.ctime()))


if __name__ == "__main__":
    tl.start(block=True)
User avatar
dirk
KUNBUS
Posts: 1947
Joined: 15 Dec 2016, 13:19
Answers: 4

Re: revpi connect , use watchdog with python3

Post by dirk »

Hi DRi, have a look at the watchdog tutorial. You may view the script "/home/pi/connect/revpi-connect-watchdog.sh" for an example. You have to disconnect the wire between the pins 6 & 7 to activate the watchdog.
DRi
Posts: 7
Joined: 26 Sep 2019, 16:58
Answers: 0

Re: revpi connect , use watchdog with python3

Post by DRi »

Hi,
I read the tutorial and the watchdog is doing his job fine.
I want to restart the countdown (of the watchdog) on my own with python3, but I didn't find any information about how to do that.
Thanks,
DRi
DRi
Posts: 7
Joined: 26 Sep 2019, 16:58
Answers: 0

Re: revpi connect , use watchdog with python3

Post by DRi »

what was I doing wrong ?
1 - not switching wd.value from true to false and then false to true ... the chip is looking for value changes not a "true" value
2 - So i didn't read the value each to time
3 - didn't write the right value

The fact is that I didn't find any clear example about how to do that

Code: Select all


rpi.readprocimg()
a = rpi.core.wd.get_value()
#Do your things
# eg : temperature = int.from_bytes(rpi.io.RS485Input_2.get_value(), "little") / 20
# print(temperature)

#then switch the wd value 
    if a:
        rpi.core.wd.set_value(False)
    else:
        rpi.core.wd.set_value(True)
rpi.writeprocimg()

Post Reply