Created
June 28, 2022 20:36
-
-
Save 8none1/1c95a6894858db9ffdbb88e52083b78f to your computer and use it in GitHub Desktop.
This file contains 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
import paho.mqtt.client as mqtt | |
import json | |
import os | |
def on_connect(client, userdata, flags, rc): | |
print("Connected with result code "+str(rc)) | |
client.subscribe("triones/control/global") | |
def on_message(client, userdata, msg): | |
#print(msg.topic+" "+str(msg.payload)) | |
payload = json.loads(msg.payload) | |
if "action" in payload and "rgb" in payload and "mac" in payload: | |
if payload['mac'] == "23:02:04:00:01:c6": | |
r,g,b = payload['rgb'] | |
hex_col = f'{r:02x}' + f'{g:02x}' + f'{b:02x}' | |
cmd = "ratbagctl cheering-viscacha led 0 set color " + hex_col | |
print(cmd) | |
os.system(cmd) | |
client = mqtt.Client() | |
client.on_connect = on_connect | |
client.on_message = on_message | |
client.connect("mqtt", 1883, 60) | |
client.loop_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment