Python network monitor. Or Node Red...
Python network monitor. Or Node Red...
Hi,
I'm looking to build a networkmonitor in python that pings all my devices at home and set DO on the RevPi DIO module depending on reply.
Does anyone have any pointers of where to look and read up on to make this a reality.
I have a RevPi Connect and a RevPi DIO.
Thank you and have a great day!
I'm looking to build a networkmonitor in python that pings all my devices at home and set DO on the RevPi DIO module depending on reply.
Does anyone have any pointers of where to look and read up on to make this a reality.
I have a RevPi Connect and a RevPi DIO.
Thank you and have a great day!
Last edited by Truos on 02 Jul 2019, 10:39, edited 1 time in total.
- RevPiModIO
- KUNBUS
- Posts: 335
- Joined: 20 Jan 2017, 08:44
- Contact:
Hi Truos!
You can do this with this code. All you have to do is install RevPiModIO and maybe RevPiPyLoad to execute this script:
Important! You have to configure the IOs in piCtory and set the Names of IOs on your DIO in the "ip_io" directory.
This Program will switch on the IO if the ping fails. If you like to switch Output on if ping is successful just change:
to
Regards, Sven
You can do this with this code. All you have to do is install RevPiModIO and maybe RevPiPyLoad to execute this script:
Code: Select all
# -*- coding: utf-8 -*-
"""Ping IP addresses and set an IO to True on failure."""
__author__ = "Sven Sager"
__copyright__ = "Copyright (C) 2019 Sven Sager"
__license__ = "GPLv3"
import revpimodio2
from os import system
from threading import Event
# Event to exit the while loop
evt_exit = Event()
# RevPiModIO to communicate to process image
rpi = revpimodio2.RevPiModIO(autorefresh=True)
rpi.handlesignalend(evt_exit.set)
# This is our IP - Output-List
# TODO: CHANGE THIS TO YOUR NEEDS !!!
ip_io = {
"127.0.0.1": "O_12",
"192.168.1.1": "O_13",
"192.168.1.55": "O_14",
}
# Our mainloop - Executed every 5 seconds - Exit with Ctrl+C
while not evt_exit.wait(5):
# This is our ip check
for ip in ip_io:
# Do the Ping - Return code 0 = success
exit_code = system("ping -c 1 {0}".format(ip))
# Bool value of IO will the set to True on error
rpi.io[ip_io[ip]].value = exit_code
# Clean up process image
rpi.cleanup()
Important! You have to configure the IOs in piCtory and set the Names of IOs on your DIO in the "ip_io" directory.
This Program will switch on the IO if the ping fails. If you like to switch Output on if ping is successful just change:
Code: Select all
rpi.io[ip_io[ip]].value = exit_code
to
Code: Select all
rpi.io[ip_io[ip]].value != exit_code
Regards, Sven
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
Thank you Sven!
Could I extend this and use it to instead write to a modbus register in pictory?
In that case I might get it to work with my HMI at home that I use for modbus already to read other data.
Could I extend this and use it to instead write to a modbus register in pictory?
In that case I might get it to work with my HMI at home that I use for modbus already to read other data.
hi I've been playing around with your script and changed it to set "Output_1" for Modbus and it shows value 256.
Is it possible to change this?
Also in the prompt it show the ping commands running isn't that going to be a problem if I run it to monitor say 42 hosts?
--- 192.168.1.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.567/0.567/0.567/0.000 ms
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.071 ms
--- 127.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.071/0.071/0.071/0.000 ms
PING 192.168.1.40 (192.168.1.40) 56(84) bytes of data.
64 bytes from 192.168.1.40: icmp_seq=1 ttl=64 time=2.48 ms
Is it possible to change this?
Also in the prompt it show the ping commands running isn't that going to be a problem if I run it to monitor say 42 hosts?
--- 192.168.1.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.567/0.567/0.567/0.000 ms
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.071 ms
--- 127.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.071/0.071/0.071/0.000 ms
PING 192.168.1.40 (192.168.1.40) 56(84) bytes of data.
64 bytes from 192.168.1.40: icmp_seq=1 ttl=64 time=2.48 ms
The RPi crashes after a few hours of runtime.
I think I'll start investigating NodeRed as a ping system instead
I think I'll start investigating NodeRed as a ping system instead
-
- Posts: 2
- Joined: 21 Jul 2017, 09:11
Hello
Please have a look at Fping, its a free configurable variant to Ping, making it able to gain a lot of processing speed.
Works both on Linux and Windows
Please have a look at Fping, its a free configurable variant to Ping, making it able to gain a lot of processing speed.
Works both on Linux and Windows
I've setup Node Red instead and so far not involved any revolution pi specifics.
It's running on a RevPi Connect and I've also set it up on a RPi 3A+
It works fine for days on the RPi 3A+ and crashed with the screen attached after a few hours on the RevPi Connect
Have anyone else encountered this?
I'm reflashing a second RevPi Connect to set them off simultaneously.
It's running on a RevPi Connect and I've also set it up on a RPi 3A+
It works fine for days on the RPi 3A+ and crashed with the screen attached after a few hours on the RevPi Connect
Have anyone else encountered this?
I'm reflashing a second RevPi Connect to set them off simultaneously.
Re: Python network monitor. Or Node Red...
Hi Truos, this seams serious. Please verify that you have the latest updates. Have a look at this post here.