Пример #1
0
def initialise(settings=configuration.mqtt.settings):
  global client, keepalive, topic_path

  client_id = get_unique_id()
  keepalive = settings["keepalive"]
  topic_path = settings["topic_path"]
  if topic_path == "$me": topic_path = "aiko_esp/" + get_unique_id() + "/0"

  client = MQTTClient(client_id,
    settings["host"], settings["port"], keepalive=keepalive)

  client.set_callback(on_message)
  client.set_last_will(topic_path + "/state", "nil")
  client.connect()  # TODO: Catch exception

  event.add_event_handler(mqtt_ping_handler, keepalive * 1000)

  if settings["mqtt_insecure_exec"]:
    add_message_handler(on_exec_message, "$me/exec")

  for topic in settings["topic_subscribe"]:
    if topic.startswith("$all/"): topic = "+/+/+" + topic[4:]
    if topic.startswith("$me/"): topic = topic_path + topic[3:]
    client.subscribe(topic)

  print("  ###### MQTT: Connected to %s: %s" % (settings["host"], topic_path))
Пример #2
0
def initialise():
    for pin_number in pin_numbers:
        pin = Pin(pin_number, Pin.IN, Pin.PULL_UP)
        pin.irq(lambda p: handle_pin_change(p),
                trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING)
        pins.append(pin)

    event.add_event_handler(handle_pins_active, 50)  # 20 Hz
    event.add_event_handler(handle_blink_led, 500)
Пример #3
0
def initialise():
    global topTempHumid, oneWires, oneWireDevices, airMonitor
    print("initialising Sensors")

    topTempHumid = dht.DHT22(machine.Pin(23))  #DHT22
    oneWires = ds18x20.DS18X20(onewire.OneWire(
        machine.Pin(22)))  #onewire Probe
    oneWireDevices = oneWires.scan()
    i2c = machine.I2C(scl=machine.Pin(21), sda=machine.Pin(19))
    airMonitor = sgp30.SGP30(i2c)

    #print("SGP30 serial #", [hex(i) for i in airMonitor.serial])

    airMonitor.iaq_init()
    airMonitor.set_iaq_baseline(0x8973, 0x8aae)

    event.add_event_handler(event_send_temp, 10000)
Пример #4
0
def initialise():
    event.add_event_handler(handle_leds, step_speed)
    mqtt.add_message_handler(on_audrey_message, "$me/in")
Пример #5
0
import aiko.event as event

import configuration.boot
configuration.globals = globals()  # used by aiko.mqtt.on_exec_message()
parameter = configuration.boot.parameter

import gc


def gc_event():
    gc.collect()
    print("  ###### GC:", gc.mem_free(), gc.mem_alloc())


if parameter("gc_enabled"):  # GC: 86368  9632
    event.add_event_handler(gc_event, 60000)

import aiko.led as led  # GC: 79696 16304
led.initialise()

if parameter("oled_enabled"):  # GC: 73088 22912
    import aiko.oled as oled
    oled.initialise()

import aiko.net as net  # GC: 54304 41696
net.initialise()

if parameter("lolibot_enabled"):
    import lolibot
    lolibot.initialise()
else:
def initialise():
  set_handler(pattern_1)
  event.add_event_handler(handler, 100)
Пример #7
0
def initialise():
    event.add_event_handler(net_led_handler, 100)
    net_thread = Thread(target=net_manager)
    net_thread.start()
Пример #8
0
import aiko.event as event

import configuration.main
configuration.globals = globals()  # used by aiko.mqtt.on_exec_message()
parameter = configuration.main.parameter

import gc


def gc_event():
    gc.collect()
    print("  ###### GC:", gc.mem_free(), gc.mem_alloc())


if parameter("gc_enabled"):  # GC: 86368  9632
    event.add_event_handler(gc_event, 60000)

import aiko.led as led  # GC: 79696 16304
led.initialise()

if parameter("oled_enabled"):  # GC: 73088 22912
    import aiko.oled as oled
    oled.initialise()

import aiko.net as net  # GC: 54304 41696
net.initialise()

if parameter("application"):
    application_name = parameter("application")
    application = __import__(application_name)
    application.initialise()