import json import network from config import host, ssid, pw, mqtt_id from ssd1306_min import SSD1306 as SSD from umqtt_client import MQTTClient as umc from machine import Pin, I2C try: from location import loc except ImportError: from config import loc print("location =",loc) i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) d = SSD(i2c) d.init_display() d.draw_text(0, 0, "HELLO STEVE") d.display() c = umc(mqtt_id, host) b = bytearray(1) # mtpPublish is a class method that produces a bytes object that is used in # the callback where we can't allocate any memory on the heap quieter = umc.mtpPublish('sonos/'+loc, '{"action":"quieter"}') louder = umc.mtpPublish('sonos/'+loc, '{"action":"louder"}') play_pause = umc.mtpPublish('sonos/'+loc, '{"action":"play_pause"}') def callback_louder(p): if b[0]:
from time import sleep, time import json import network from config import hosts, ssid, pw from ssd1306_min import SSD1306 as SSD from umqtt_client import MQTTClient from machine import Pin, I2C, ADC with open('mqtt_id', 'r') as f: mqtt_id = f.read().strip() host = hosts['other'] i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) d = SSD(i2c) d.init_display() d.draw_text(0, 0, "HELLO NEO") d.display() umc = MQTTClient(mqtt_id, host, 1883) b = bytearray(1) # mtpPublish is a class method that produces a bytes object that is used in # the callback where we can't allocate any memory on the heap rgb1 = umc.mtpPublish('neo', '{"rgb":1}') rgb2 = umc.mtpPublish('neo', '{"rgb":2}') rgb3 = umc.mtpPublish('neo', '{"rgb":3}') #callbacks