def display(msg): senderName = msg.topic[len('disp/'):] print("Received display message from", senderName) if senderName not in knownApps: knownApps.append(senderName) print("Updated known apps to", knownApps) if currentApp is not None and senderName != knownApps[currentApp]: print("Ignoring call from", senderName) return #ignore call try: msgDecoded = str(msg.payload.decode("utf-8", "ignore")) msgRoot = json.loads(msgDecoded) if type(msgRoot) is not dict: raise AttributeError("Not JSON") except: print("Bad format for topic disp/#") return # ignore it if 'color' in msgRoot: sense.clear(msgRoot['color']) elif 'image' in msgRoot: sense.set_pixels(msgRoot['image']) elif 'text' in msgRoot: messageAsync(msgRoot['text']) else: print("Unexpected format for topic disp/#")
def banner(): try: text = request.get_json().get('message') except: text = "Unicorn!" messageAsync(text) return text
def should_process(raw_msg): messageAsync("Should Process")
def should_display(disp_msg): messageAsync("Should Display")