forked from markfickett/minecraftstatus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mc_blinkt_fade2.py
executable file
·85 lines (68 loc) · 2.59 KB
/
mc_blinkt_fade2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
"""Checks the status (availability, logged-in players) on a Minecraft server.
Display the count of user on a Blinkt! using ambiant color with all LED.
This is exactly like previous version, but fade is not done using brightness, but by turning on and off from 0 to 8 LEDs. Since the Blinkt! is supposed to be inside a FADO lamp from IKEA, individual LEDs are not visible.
Fading indication to avoid annoying blinking:
Fade-in Fade-out of red mean the server is not reachable.
Fade-in Fade-out of green mean the server is up but noone is connected.
Fade-in Fade-out of green with a number of fade of blue that indicate the number of connected user.
Example:
$ %(prog)s host [port]
available, 3 online: mf, dignity, viking
Based on:
https://gist.github.com/barneygale/1209061
Protocol reference:
http://wiki.vg/Server_List_Ping
By default the code log on the terminal the number of connected user.
This can be disabled by removing the hash in front of the folowing line:
#logging.getLogger().setLevel(logging.CRITICAL)
"""
import argparse
import logging
from mcstatus import McServer
DEFAULT_PORT = 25565
from blinkt import set_pixel, show, set_brightness
from time import sleep
def fade_count(n, r, g, b, fast=None, bright=1.0):
if fast is None:
delay=0.125
else:
delay=0.0625
for j in range (n):
for i in range(8):
set_pixel(i, r, g, b, bright)
show()
sleep(delay)
for i in range(8):
set_pixel(i, 0, 0, 0, bright)
show()
sleep(delay)
logging.basicConfig(
format='%(levelname)s %(asctime)s %(filename)s:%(lineno)s: %(message)s',
level=logging.DEBUG)
#logging.getLogger().setLevel(logging.CRITICAL)
summary_line, _, main_doc = __doc__.partition('\n\n')
parser = argparse.ArgumentParser(
description=summary_line,
epilog=main_doc,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(
'--port', type=int, default=DEFAULT_PORT,
help='defaults to %d' % DEFAULT_PORT)
parser.add_argument('host')
args = parser.parse_args()
logging.info('querying %s:%d', args.host, args.port)
while True:
server = McServer(args.host, port=args.port)
server.Update()
if server.available:
logging.info(
'available, %d online: %s',
server.num_players_online,
', '.join(server.player_names_sample))
n=server.num_players_online
fade_count(n,0,0,255) # Fast blue fade for number of player
fade_count(1,0,255,0) # Slow green fade to say the server is OK
else:
logging.info('unavailable')
fade_count(1,255,0,0) # Slow red fade to say the server is OK