summaryrefslogtreecommitdiffstats
path: root/linz/oekofen_thermo/src/main.cpp
blob: 5713a0bd3a3cf195c0690dbb23afa804a193ccc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <Arduino.h>
#include <WiFiManager.h>
#include <ESP8266WebServer.h>

#include "MCP42010.h"

ESP8266WebServer http_service(80);
MCP42010 msp42010(D8);

void setup() {
  Serial.begin(115200);
  msp42010.setup();

  WiFiManager wifiManager;
  wifiManager.setConfigPortalTimeout(600);
  Serial.printf_P(PSTR("Setting up WiFi\n"));
  WiFi.hostname("oekofen");
  if (!wifiManager.autoConnect("oekofen-thermo"))
  {
    Serial.printf_P(PSTR("Failed to connect and hit timeout\n"));
    delay(5000);
    ESP.restart();
  }

  http_service.on("/", HTTP_GET, []() {
    uint8_t val = random(0, 255);
    //msp42010.setPot(MCP42010::P0, val);
    msp42010.setPot(MCP42010::P1, val);
    http_service.send(200, PSTR("text/plain"), String(val));
  });
  http_service.begin();

  Serial.println("Setup done");
}

void loop() {
  //http_service.handleClient();
  if (Serial.available() > 0)
  {
    while (Serial.read() >= 0) {}
    uint8_t val = random(0, 255);
    //msp42010.setPot(MCP42010::P0, val);
    msp42010.setPot(MCP42010::P1, val);
    Serial.println(val, DEC);
  }
}