Python Forum
GPIO high if network IP has good ping
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GPIO high if network IP has good ping
#1
I would like to ping an android phone on my network every 30 minutes and light one of two LEDs according to the ping result.  Can a python program do this?
Reply
#2
Are the LEDs on the phone, or some other device?  You can't just run a script on an android phone, you'll have to create a full application, and that will require a fair amount of android knowledge.
Reply
#3
The LEDs are on the breadboard attached to the raspberry pi. If the pi gets a good ping to the Android phone I want the LEDs to light up
Reply
#4
That's easier (presuming you know the DNSname/IP of the phone).

There are modules that allow for pinging directly from python, but usually only privileged (root) accounts can construct the correct sockets.  Thats suggest that it can often be simpler to just run /usr/bin/ping in subprocess.run() or similar and grab the exit code.  

>>> import subprocess
>>> p = subprocess.run(['ping', '-c', '1', '5.4.3.2'], stdout=subprocess.DEVNULL)
>>> p.returncode
1
>>> p = subprocess.run(['ping', '-c', '1', 'localhost'], stdout=subprocess.DEVNULL)
>>> p.returncode
0
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need some guidance on a script to ping a list of ip's cubangt 11 1,689 Aug-10-2023, 02:39 PM
Last Post: snippsat
  function return boolean based on GPIO pin reading caslor 2 1,131 Feb-04-2023, 12:30 PM
Last Post: caslor
  class Update input (Gpio pin raspberry pi) caslor 2 744 Jan-30-2023, 08:05 PM
Last Post: caslor
  Webhook, post_data, GPIO partial changes DigitalID 2 953 Nov-10-2022, 09:50 PM
Last Post: deanhystad
  non-stop ping script kucingkembar 1 1,321 Aug-23-2022, 06:29 AM
Last Post: menator01
  Win32\ping.exe windows pops up -very annoying... tester_V 9 3,127 Aug-12-2021, 06:54 AM
Last Post: tester_V
  Looking for discord bot to make loop ping for address ip tinkode 0 1,789 Jul-26-2021, 03:51 PM
Last Post: tinkode
  Ping command using python 3.6.5 Martin2998 6 17,254 Apr-19-2021, 06:24 PM
Last Post: blazejwiecha
  Seemingly unstable GPIO output while executing from RetroPie LouF 6 3,860 Feb-19-2021, 06:29 AM
Last Post: LouF
  Picture changing triggered by GPIO q_nerk 2 2,520 Dec-14-2020, 03:32 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020