-
Notifications
You must be signed in to change notification settings - Fork 0
/
smart_solenoid.ino
85 lines (68 loc) · 1.47 KB
/
smart_solenoid.ino
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <Esp.h>
#ifdef ESP8266
#include <esp8266wifi.h>
#include <ESP8266WebServer.h>
#elif defined(ESP32)
#include <WiFi.h>
#include <WebServer.h>
#endif
#include <ArduinoJson.h>
#include <EEPROM.h>
#include "config.h"
#include "memory.h"
#include "wifimanager_adapter.h"
#include "solenoid_server.h"
SolenoidServer solenoid_server;
Configuration config;
void setup()
{
Serial.begin(115200);
init_config();
delay(500);
pinMode(config.output_pin, OUTPUT);
delay(500);
setup_wifi();
delay(500);
solenoid_server.begin();
delay(500);
}
void loop()
{
solenoid_server.Listen(config);
}
void init_config()
{
Memory memory;
WifiManagerAdapter wm;
//Load Config
config = memory.Load();
//TODO: Use an input to trigger the portal and
// default to starting up from saved data
//For now, always run the wm portal
wm.setup(&config);
//Save
memory.Save(config);
}
void setup_wifi()
{
WiFi.begin();
WiFi.setSleep(false);
WiFi.config(IPAddress(config.ip),
IPAddress(config.gateway),
IPAddress(config.subnet));
int loop_limit = 30;
int count = 0;
while (WiFi.status() != WL_CONNECTED && count < loop_limit)
{
Serial.println("-~~<*}(~){*>~~-\n");
delay(500);
count++;
}
if (count == loop_limit)
{
//ESP.restart();
}
Serial.println("WiFi connected, IP = ");
Serial.println(WiFi.localIP());
delay(500);
}