Created
October 21, 2023 18:30
-
-
Save csm10495/fa30ac13cf51475963cd468db4acf2f6 to your computer and use it in GitHub Desktop.
weatherflow_listtener.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A simple script to listen to a local weatherflow UDP broadcast and print out any received data. | |
(C) Charles Machalow via the MIT License (2023) .. See https://opensource.org/license/mit/ for details. | |
""" | |
import json | |
import logging | |
from pprint import pformat | |
from socket import AF_INET, IPPROTO_UDP, SOCK_DGRAM, socket | |
# pip install rich | |
from rich.logging import RichHandler | |
logging.basicConfig( | |
level="NOTSET", format="%(message)s", handlers=[RichHandler(show_path=False)] | |
) | |
logger = logging.getLogger(__name__) | |
if __name__ == "__main__": | |
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) | |
s.bind(("", 50222)) | |
s.settimeout(1) | |
while True: | |
try: | |
data = s.recv(65535) | |
except TimeoutError: | |
continue | |
jdata = json.loads(data.decode()) | |
logger.info(pformat(jdata)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment