コード例 #1
0
def is_online():
    # check if the device is online
    ping_host = '8.8.8.8'
    server = PingServer(ping_host)
    b = server.is_active
    server.close()
    return b
コード例 #2
0
def PingServer_checker():
    global app_running

    print("-----------------------------------------------------")
    print("                 Start Host Checking")
    print("-----------------------------------------------------")
    for host in HostList:
        status = PingServer(host).is_active
        print(host + "   " + str(status))

    root.after(2000, PingServer_checker)
コード例 #3
0
def PingServer_checker():
    print("-----------------------------------------------------")
    print("                 Start Host Checking")
    print("-----------------------------------------------------")
    online_counter = 0

    for host in HostList:
        status = PingServer(host).is_active
        print(host + "   " + str(status))
        if (status):
            online_counter += 1

    for i in range(0, online_counter, 1):
        GPIO.output(LED_PIN, 1)
        sleep(led_blink_delay)
        GPIO.output(LED_PIN, 0)
        sleep(led_blink_delay)

    root.after(10000, PingServer_checker)
コード例 #4
0
from gpiozero import StatusBoard, PingServer
from gpiozero.tools import negated, smoothed
from signal import pause

sb = StatusBoard('mum', 'dad', 'alice')

statuses = {
    PingServer('192.168.1.5'): sb.mum,
    PingServer('192.168.1.6'): sb.dad,
    PingServer('192.168.1.7'): sb.alice,
}

for server, strip in statuses.items():
    strip.lights.green.source = smoothed(
        server.values, 2, any)  # allow 1 false negative out of 2
    strip.lights.green.source_delay = 60
    strip.lights.red.source = negated(strip.lights.green.values)

pause()
コード例 #5
0
            temp_C, temp_F = getCPUtemperature()
            show_message("CPU {}C / {}F".format(temp_C, temp_F), operation)

        elif operation == 5:
            show_message('Wifi Networks', operation)
            cells = scanForCells()
            for cell in cells:
                if operation == 5:
                    show_message(cell.summary, operation)

        elif operation == 6:
            blue_led.off()
            for host in hosts_to_monitor:
                if operation == 6:
                    nickname, server, match = host
                    pinger = PingServer(server)
                    if pinger.value:
                        status = "UP"
                        blue_led.off()
                    else:
                        status = "DOWN"
                        blue_led.blink()

                    show_message("Ping to {} - {}".format(server, status),
                                 operation)

                    for i in range(0, ping_delay):
                        if operation == 6:
                            time.sleep(1)

        elif operation == 7:
コード例 #6
0
from gpiozero import LED, PingServer
from gpiozero.tools import negated
from signal import pause

green = LED(17)
red = LED(18)

google = PingServer('google.com')

google.when_activated = green.on
google.when_deactivated = green.off
red.source = negated(green)

pause()
コード例 #7
0
from gpiozero import StatusZero, PingServer
from gpiozero.tools import negated, smoothed
from signal import pause

sz = StatusZero('mum', 'dad', 'alice')

statuses = {
    PingServer('192.168.1.5'): status.mum,
    PingServer('192.168.1.6'): status.dad,
    PingServer('192.168.1.7'): status.alice,
}

for server, strip in statuses.items():
    strip.green.source = smoothed(server.values, 2,
                                  any)  # allow 1 false negative out of 2
    strip.green.source_delay = 60
    strip.red.source = negated(leds.green.values)

pause()
コード例 #8
0
from gpiozero import PingServer
from signal import pause
mom = PingServer('192.168.1.36')
me = PingServer('192.168.1.34')
arda = PingServer('192.168.1.37')

print('Arda:', arda.value)
print('Mom:', mom.value)
print('Me:', me.value)
コード例 #9
0
from gpiozero import LED, PingServer
from gpiozero.tools import negated
from signal import pause

green = LED(19)
red = LED(5)

google = PingServer('google.com')

green.source = google
green.source_delay = 20
red.source = negated(green)

pause()
コード例 #10
0
ファイル: three.py プロジェクト: ebrargomer/water_saving
import subprocess
from gpiozero import DistanceSensor, MotionSensor, PingServer
from gpiozero.tools import negated
from signal import pause

arda = PingServer('192.168.1.37')  #android
me = PingServer('192.168.1.34')  #iphone
mom = PingServer('192.168.1.36')  #android

if (arda.value and mom.value and not (me.value)):

    pir = MotionSensor(4)
    dis = DistanceSensor(20, 21)

    def calculatedist():
        print('Hareket eden cisim', dis.distance, 'm uzaklıkta')
        dis.wait_for_in_range(10000)

    #	subprocess.call("./izle.sh")

    pir.when_motion = calculatedist

pause()
コード例 #11
0
ファイル: statusboard.py プロジェクト: spardinas/statusboard
#def website_up(url):
#    try:
#        r = requests.get(url)
#        return r.ok
#    except:
#        return False

sb = StatusBoard('DDNS', 'VPN', 'CAM', 'WEB', 'APAGADO')  # only using 4 strips

sb.on()  # all leds on
sleep(1)
sb.off()  # all leds off
sleep(1)

statuses = {
    PingServer('10.0.10.253'): sb.CAM,
    PingServer('http://bocata.ddns.net/'): sb.DDNS,
}
#if website_up('http://bocata.ddns.net/'):
#            sb.DDNS.lights.green.on()
#            sb.DDNS.lights.red.off()
#       else:
#            sb.DDNS.lights.red.on()
#            sb.DDNS.lights.green.off()

for server, strip in statuses.items():
    strip.lights.green.source = smoothed(
        server.values, 2, any)  # allow 1 false negative out of 2
    strip.lights.green.source_delay = 60
    strip.lights.red.source = negated(strip.lights.green.values)
    # for strip in sb:
コード例 #12
0
from gpiozero import StatusZero, PingServer
from gpiozero.tools import negated
from signal import pause

sz = StatusZero()

websites = ['raspberrypi.org', 'codeclub.org.uk', 'coderdojo.com']
servers = [PingServer(web) for web in websites]

for strip, server in zip(sz, servers):
    strip.green.source = server.values
    strip.red.source = negated(strip.green.values)

pause()
コード例 #13
0
#!/usr/bin/python3

from gpiozero import LED, PingServer
from gpiozero.tools import negated
from signal import pause

green = LED(17)
red = LED(22)

RPIold = PingServer('192.168.2.106')

green.source = RPIold
green.source_delay = 5
red.source = negated(green)

pause()
コード例 #14
0
from gpiozero import PingServer, StatusBoard
from time import sleep

device = PingServer('192.168.1.29')
google = PingServer('google.com')

sb = StatusBoard('google', 'device')

while True:
    if google.is_active:
        sb.google.lights.green.blink()
    else:
        sb.google.lights.green.off()

    if device.is_active:
        sb.device.lights.green.on()
        sb.device.lights.red.off()
    else:
        sb.device.lights.green.off()
        sb.device.lights.red.on()
    sleep(3)
	
コード例 #15
0
from gpiozero import StatusZero, PingServer
from time import sleep

sz = StatusZero('raspberrypi', 'codeclub', 'coderdojo')

raspberrypi = PingServer('raspberrypi.org')
codeclub = PingServer('codeclub.org.uk')
coderdojo = PingServer('coderdojo.com')

while True:
    if raspberrypi.is_active:
        sz.raspberrypi.green.on()
        sz.raspberrypi.red.on()
    else:
        sz.raspberrypi.red.on()
        sz.raspberrypi.green.off()

    if codeclub.is_active:
        sz.codeclub.green.on()
        sz.codeclub.red.on()
    else:
        sz.codeclub.red.on()
        sz.codeclub.green.off()

    if coderdojo.is_active:
        sz.coderdojo.green.on()
        sz.coderdojo.red.on()
    else:
        sz.coderdojo.red.on()
        sz.coderdojo.green.off()
コード例 #16
0
from gpiozero import StatusZero, PingServer
from time import sleep

sz = StatusZero('mum', 'dad', 'alice')

mum = PingServer('192.168.1.3')
dad = PingServer('192.168.1.4')
alice = PingServer('192.168.1.5')

while True:
    if mum.is_active:
        sz.mum.green.on()
        sz.mum.red.on()
    else:
        sz.mum.red.on()
        sz.mum.green.off()

    if dad.is_active:
        sz.dad.green.on()
        sz.dad.red.on()
    else:
        sz.dad.red.on()
        sz.dad.green.off()

    if alice.is_active:
        sz.alice.green.on()
        sz.alice.red.on()
    else:
        sz.alice.red.on()
        sz.alice.green.off()
コード例 #17
0
with pytest.raises(StopIteration):
    next(build_queue)

# Test adding another package
assert list(db.get_all_packages()) == ['abc']
db.add_new_package('def')
assert list(db.get_all_packages()) == ['abc', 'def']
db.add_new_package_version('def', '1.0')
assert db.get_total_number_of_packages() == 2
assert db.get_total_number_of_package_versions() == 3
assert db.get_build_queue() == [['def', '1.0']]

build_queue = db.build_queue_generator()
assert next(build_queue) == ['def', '1.0']

pypi_server = PingServer('pypi.python.org')

if pypi_server.is_active:
    # Test PyPI information functions
    #packages = list_pypi_packages()
    #assert len(packages) > 0

    gpiozero_info = get_package_info('gpiozero')
    assert 'releases' in gpiozero_info
    assert '1.0.0' in gpiozero_info['releases']

    gpiozero_versions = get_package_versions('gpiozero')
    assert '1.0.0' in gpiozero_versions

    # Test wheel building
    db.add_new_package('gpiozero')
コード例 #18
0
def main():
  lumi_sensor = utils.LuminositySensor()
  cpu_temp = CPUTemperature()
  load_average = LoadAverage()
  
  cache = []
  
  last_luminosity = -1
  last_co2 = -1
  update_frequency = 30 # in s
  
  while True:
    with open ("config.json", "r") as f:
        config = json.loads(f.read())
  
    ping_router = PingServer(config["MQTT_SERVER"])
    online = ping_router.value
  
    luminosity = lumi_sensor.get_luminosity(keep_open=update_frequency < 31)
  
    sensor_values = mh_z19.read_all(True)
    sensor_values["time"] = datetime.now().astimezone().isoformat()
    sensor_values["online"] = online
    sensor_values["luminosity"] = luminosity
    sensor_values["cpu_temperature"] =  cpu_temp.temperature
    sensor_values["cpu_load_percent"] = load_average.load_average * 100
    sensor_values["mem_percent"] = psutil.virtual_memory().percent
  
    #print(sensor_values)
   
    # MQTT publish
    if online:
        try:
          publish.single(config["MQTT_PATH"], json.dumps(sensor_values), hostname=config["MQTT_SERVER"])
        except Exception as e:
            print(e)
            sensor_values["exception"] = str(e)
            online = False
  
    # if not online, write to cache
    if not online:
        cache += [sensor_values]
    if len(cache) > 59 or (online and len(cache) > 0):
      with open (f"""cache/sensors-{datetime.now().strftime("%Y%m%d-%H%M%S")}.json""", "w") as f:
        f.write(json.dumps(cache))
      cache = []
  
    # change off/online depending on luminosity
    if luminosity < config["DISABLE_WIFI_LUMINOSITY"]:
        if online:
            utils.disable_wifi()
        online = False
    else:
        if not online:
            utils.activate_wifi()
            for i in range(30):
                online = ping_router.value
                if not online:
                    time.sleep(1)
                    continue
                break
  
    if online:
        utils.turn_led_on()
        utils.upload_cache()
    else:
        utils.turn_led_off()
  
    delta_luminosity = luminosity - last_luminosity
    last_luminosity = luminosity
    delta_co2 = sensor_values["co2"] - last_co2 
    last_co2 = sensor_values["co2"]
  
    if abs(delta_luminosity) > 0.01 or abs(delta_co2) > 10:
        update_frequency = 30
    else:
        if luminosity > 0.1:
            update_frequency = 60
        else:
            update_frequency = 60 * 5

  
    utils.wait_for_next_run(seconds=update_frequency)
コード例 #19
0
#!/usr/bin/python3

from gpiozero import LED, PingServer
from gpiozero.tools import negated
from signal import pause

green = LED(17)
red = LED(4)

google = PingServer('8.8.8.8')

green.source = google
green.source_delay = 60
red.source = negated(green)

pause()
コード例 #20
0
ファイル: gateway.py プロジェクト: ray33ee/chpi
 def pingGateway():
     return PingServer(Gateway.gateway()).value