Пример #1
0
 def test_has(self):
     c = ep_config.config()
     c.config = c.make_sample_config()
     self.assertTrue(c.has("wifi_config"))
     self.assertTrue(c.has("wifi_config/dhcp_hostname"))
     self.assertFalse(c.has("wifi_confi"))
     self.assertTrue(c.has("wifi_nets/0"))
     self.assertFalse(c.has("wifi_nets/2"))
Пример #2
0
 def test_get(self):
     c = ep_config.config()
     c.config = c.make_sample_config()
     self.assertEqual(c.get("wifi_config/dhcp_hostname"), "ESP32")
     self.assertEqual(c.get("wifi_nets/0"), {
         "ssid": "ssid1",
         "pass": "******",
         "bssid": "123456"
     })
     self.assertIsNone(c.get("wifi_nets/2"))
 def put(self, path, req, sock):
     config = ep_config.config(self.config_file)
     config.load()
     created = not config.has(path)
     config.set(path, req["fields"])
     config.save()
     if created:
         self.send_response(sock, 201)
     else:
         self.send_response(sock, 200)
Пример #4
0
    def test_set(self):
        c = ep_config.config()
        c.config = c.make_sample_config()

        c.set("wifi_config/dhcp_hostname", "ESP")
        self.assertEqual(c.get("wifi_config/dhcp_hostname"), "ESP")

        c.set("test", "test")
        self.assertEqual(c.get("test"), "test")

        c.set("foo/bar", "test")
        self.assertEqual(c.get("foo"), {"bar": "test"})

        c.set("wifi_nets/0", "test")
        self.assertEqual(c.get("wifi_nets/0"), "test")

        self.assertRaises(KeyError, c.set, "wifi_nets/2", "test")

        self.assertRaises(KeyError, c.set, "wifi_nets/a", "test")
Пример #5
0
import machine
import ubinascii
import statemachine

wifi = ep_wifi.wifi("./network_config.json", max_time_wait_for_connect=10)
wlan, ssid, bssid = wifi.connect()

logger = ep_logging.colored_logger(appname="main")
logger.notice("WiFi connected")

logger_http = ep_logging.colored_logger(appname="http")

ow = onewire.OneWire(machine.Pin(4))
ds = ds18x20.DS18X20(ow)

ht_config = ep_config.config("ht_config.json")
ht_config.load()
thresh = ht_config.get("")

ds_config = ep_config.config("ds_config.json")
ds_config.load()
temps = ds_config.get("")

sm = statemachine.setup(
    lambda name: temps[name]["value"]
    if (name in temps) and ("value" in temps[name]) else 0,
    lambda name: thresh.get(name, 0))
sm.init()
sm.step_until_stationary()

Пример #6
0
_thread.stack_size(8192)

wifi = ep_wifi.wifi("./network_config.json", max_time_wait_for_connect=10)
wlan, ssid, bssid = wifi.connect()
ip = wlan.ifconfig()[0]

logger = ep_logging.colored_logger(appname="main")
logger.notice("WiFi connected")

logger_http = ep_logging.colored_logger(appname="http")

ow = onewire.OneWire(machine.Pin(4))
ds = ds18x20.DS18X20(ow)

ht_config = ep_config.config("ht_config.json")
ht_config.load()
thresh = ht_config.get("")

ds_config = ep_config.config("ds_config.json")
ds_config.load()
temps = ds_config.get("")
get_temp = lambda name: temps[name]["value"] if (name in temps) and (
    "value" in temps[name]) else 0
sm, pump_state = statemachine.setup(get_temp, lambda name: thresh.get(name, 0))
sm.init()
sm.step_until_stationary()


def read_temps(timer, ds, temps, sm):
    ds.convert_temp()
 def get(self, path, req, sock):
     config = ep_config.config(self.config_file)
     config.load()
     data = config.get(path)
     self.send_response(sock, code=200, data=data)