Beispiel #1
0
_temperature_sensor = temperature_sensor.TemperatureSensor(
    machine.Pin(config.D6))


def timeout1minute(timer):
    _temperature_sensor.update()
    _temperature_sensor.upload()


def timeout10minutes(timer):
    utils.syncDatetime()


tim0 = machine.Timer(0)
tim0.init(period=60000, mode=machine.Timer.PERIODIC, callback=timeout1minute)
tim1 = machine.Timer(1)
tim1.init(period=600000,
          mode=machine.Timer.PERIODIC,
          callback=lambda t: timeout10minutes())
timeout1minute(None)
timeout10minutes(None)

pinServerController = pin_server_controller.PinServerController(
    [config.D1, config.D2, config.D5, config.D7, config.D8])
controllers = [pinServerController]
statusController = status_server_controller.StatusServerController(
    'Remote Socket', controllers)
_server = server.Server(33455, controllers + [statusController])
_server.run()
Beispiel #2
0
import machine
import sonoff_server_controller
import server
import status_server_controller
import utils
import network

utils.printLog("NODEMCU", "sonoff")

statusPin = machine.Pin(13, machine.Pin.OUT)

def timeout1seconds():
    isconnected = network.WLAN(network.STA_IF).isconnected()
    statusPin.value(1 if not isconnected else 0)

def timeout10minutes():
    utils.syncDatetime()

tim0 = machine.Timer(0)
tim0.init(period=1000, mode=machine.Timer.PERIODIC, callback=lambda t: timeout1seconds())
tim1 = machine.Timer(1)
tim1.init(period=600000, mode=machine.Timer.PERIODIC, callback=lambda t: timeout10minutes())
timeout10minutes()

sonoffServerController = sonoff_server_controller.getInstance()
controllers = [sonoffServerController]
statusController = status_server_controller.StatusServerController('Sonoff', controllers)
_server = server.Server(33455, controllers + [statusController])
_server.run()
Beispiel #3
0
import config
import machine
import server
import status_server_controller
import temperature_sensor
import thermostat_server_controller
import utils

utils.printInfo("THERMOSTAT", "boot up")
utils.createSyncDateTimeTimer()
_temperature_sensor = temperature_sensor.TemperatureSensor(machine.Pin(config.DS18B20_PIN))
_relay_pin = machine.Pin(config.THERMOSTAT_RELAY_PIN, machine.Pin.OUT)
_switch_pin = machine.Pin(config.THERMOSTAT_SWITCH_PIN, machine.Pin.IN)
_led_pin = machine.Pin(config.THERMOSTAT_LED_PIN, machine.Pin.OUT)
_thermostat_server_controller = thermostat_server_controller.ThermostatServerController(_temperature_sensor, _relay_pin, _switch_pin, _led_pin)
_controllers = [_thermostat_server_controller]
_statusController = status_server_controller.StatusServerController('Thermostat', _controllers)
_server = server.Server(config.SERVER_PORT, _controllers + [_statusController])

try:
    _server.run()
except KeyboardInterrupt:
    utils.printInfo("THERMOSTAT", "stopped by the user")
    utils.deleteTimers()
except Exception as e:
    utils.printWarn("THERMOSTAT", "exception during server run: %s" % e)
    machine.reboot()
Beispiel #4
0
    _temperature_sensor.update()
    hour = utime.localtime(utime.time())[3]
    _display.setBacklight(7 <= hour and hour <= 22)
    _display.update()


def timeout1minute(timer):
    _temperature_sensor.upload()


def timeout10minutes(timer):
    utils.syncDatetime()


timeout1minute(None)
timeout10minutes(None)

tim1 = machine.Timer(0)
tim1.init(period=1000, mode=machine.Timer.PERIODIC, callback=timeout1second)
tim2 = machine.Timer(1)
tim2.init(period=60000, mode=machine.Timer.PERIODIC, callback=timeout1minute)
tim3 = machine.Timer(2)
tim3.init(period=600000,
          mode=machine.Timer.PERIODIC,
          callback=timeout10minutes)

statusController = status_server_controller.StatusServerController(
    'Thermometer', [])
_server = server.Server(config.SERVER_PORT, [statusController])
_server.run()
Beispiel #5
0
import animator_server_controller
import config
import machine
import server
import status_server_controller
import utils

utils.printInfo("ANIMATOR", "boot up")
utils.createSyncDateTimeTimer()
animatorServerController = animator_server_controller.AnimatorServerController(
    machine.Pin(config.ANIMATOR_PIN, machine.Pin.OUT))
statusController = status_server_controller.StatusServerController(
    'Animator', [animatorServerController])
_server = server.Server(config.SERVER_PORT,
                        [statusController, animatorServerController])

try:
    _server.run()
except KeyboardInterrupt:
    utils.printInfo("ANIMATOR", "stopped by the user")
    utils.deleteTimers()
except Exception as e:
    utils.printWarn("ANIMATOR", "exception during server run: %s" % e)
    machine.reboot()
Beispiel #6
0
import config
import temperature_sensor
import machine
import pin_scheduler
import server
import status_server_controller
import utils

utils.printLog("NODEMCU", "water can boot up")

_temperature_sensor = temperature_sensor.TemperatureSensor()
pinScheduler = pin_scheduler.PinScheduler(
    machine.Pin(config.D5, machine.Pin.OUT), [((19, 0, 0), 36)])
statusController = status_server_controller.StatusServerController(
    'Pin Scheduler', [])
_server = server.Server(config.SERVER_PORT, [statusController])


def timeout1second(timer):
    _temperature_sensor.update()
    pinScheduler.update()


def timeout1minute(timer):
    if not pinScheduler.isTimeNearScheduler():
        _temperature_sensor.upload()


def timeout10minutes(timer):
    pass