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
  Seemingly unstable GPIO output while executing from RetroPie LouF 6 315 Feb-19-2021, 06:29 AM
Last Post: LouF
  Picture changing triggered by GPIO q_nerk 2 226 Dec-14-2020, 03:32 PM
Last Post: DeaD_EyE
  raspberry pi tank gpio help jatgm1 1 491 May-06-2020, 09:00 PM
Last Post: Larz60+
  Where should I place GPIO.cleanup() shallanq 2 563 Apr-11-2020, 05:02 AM
Last Post: shallanq
  Create a program that PING a list of IPs skaailet 7 844 Mar-26-2020, 10:46 PM
Last Post: snippsat
  Orange PI Win steering LEDs connect to GPIO djmcg 0 419 Dec-27-2019, 08:26 AM
Last Post: djmcg
  GPIO time in HIGH LOW boris_za 1 578 Dec-07-2019, 01:48 PM
Last Post: Larz60+
  ping with output jacklee26 1 1,066 Nov-28-2019, 01:01 PM
Last Post: Axel_Erfurt
  RPi GPIO Flashing LED nickayres 1 970 Jun-07-2019, 01:32 PM
Last Post: gontajones
  PING PONG GAME akea 0 2,404 May-08-2019, 04:30 PM
Last Post: akea

Forum Jump:

User Panel Messages

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