From Mark CLohesy, 3 Weeks ago, written in C++.
This paste will die in 10 Months.
Embed
  1. #!/usr/bin/python
  2. # This pings Google's DNS server 8.8.8.8 on WAN and strobes LED's red and blue to signal if the internet is down
  3. # The flashing code is hard coded on the arduino so we just need to send an ASCII code for each state message
  4. # With A being up and B being down
  5. ####################################################################################################
  6. import os
  7. import serial
  8. import time
  9. # Ping for State and send state to arduino
  10. # Hostname = IP or name of device on network, up/down = ASCII code sent to arduino for up/down State
  11. def pingDev (hostname, up, down):
  12.         response = os.system("ping -c 1 -W 2 " + hostname)
  13.         if response == 0:
  14.                 byteSer = up
  15.         else:
  16.                 byteSer = down
  17.         time.sleep(1)
  18.         ser.write(chr(byteSer))
  19.         time.sleep(4)
  20. # Initial Commands before main loop ################################################################
  21. # Send Null to wake up arduino serial
  22. ser = serial.Serial('/dev/ttyUSB0', 9600)
  23. ser.write(chr(0))
  24. time.sleep(2)
  25. #Main Loop #########################################################################################
  26. # We can add hosts to ping here and use different colours of LED or maybe an LCD screen etc
  27. while True:
  28.         pingDev( hostname="8.8.8.8", up=65, down=66 ); #Google
  29. ####################################################################################################
  30. # EOF
  31.