Skip to content

Commit 39f90dc

Browse files
author
gemi254
committed
Updated v1.1.2
1 parent 4e4d651 commit 39f90dc

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

examples/ControlAssist-Simple/ControlAssist-Simple.ino

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
#if defined(ESP32)
55
WebServer server(80);
6-
#include <ESPmDNS.h>
7-
#define ADC_PIN 36
6+
#include <ESPmDNS.h>
7+
#define ADC_PIN 36
88
#else
99
ESP8266WebServer server(80);
1010
#include <ESP8266mDNS.h>
@@ -21,7 +21,7 @@ ControlAssist ctrl; // Control assist class
2121

2222
PROGMEM const char HTML_BODY[] = R"=====(
2323
<body>
24-
<h1>Control Assist sample page</h1>
24+
<h1>ControlAssist sample page</h1>
2525
<table>
2626
<tr>
2727
<td>ADC value</td>
@@ -47,14 +47,14 @@ PROGMEM const char HTML_BODY[] = R"=====(
4747
</tr>
4848
<tr>
4949
<td>Wifi RSSI </td>
50-
<td>Range control</td>
50+
<td>Range control</td>
5151
<td><input title="Range control" type="range" id="range_ctrl" name="range_ctrl" min="-120" max="0" value="0"></td>
5252
</tr>
5353
<tr>
5454
<td>User Button</td>
5555
<td>Button control</td>
5656
<td>
57-
<button type="button" title="Button 1" id="button_ctrl">Button 1</button>
57+
<button type="button" title="Button 1" id="button_ctrl">Button 1</button>
5858
</td>
5959
</tr>
6060
</table>
@@ -64,7 +64,7 @@ PROGMEM const char HTML_BODY[] = R"=====(
6464
// Change handler to handle websockets changes
6565
void changeHandler(uint8_t ndx){
6666
String key = ctrl[ndx].key;
67-
if(key == "check_ctrl" )
67+
if(key == "check_ctrl" )
6868
buttonState = ctrl["check_ctrl"].toInt();
6969
LOG_D("changeHandler: ndx: %02i, key: %s = %s\n",ndx, key.c_str(), ctrl[key].c_str());
7070
}
@@ -73,25 +73,25 @@ void setup() {
7373
Serial.begin(115200);
7474
Serial.print("\n\n\n\n");
7575
Serial.flush();
76-
LOG_I("Starting..\n");
77-
76+
LOG_I("Starting..\n");
77+
7878
// Connect WIFI ?
7979
if(strlen(st_ssid)>0){
8080
LOG_E("Connect Wifi to %s.\n", st_ssid);
8181
WiFi.mode(WIFI_STA);
8282
WiFi.begin(st_ssid, st_pass);
8383
uint32_t startAttemptTime = millis();
84-
while (WiFi.status() != WL_CONNECTED && millis() - startAttemptTime < 15000) {
84+
while (WiFi.status() != WL_CONNECTED && millis() - startAttemptTime < 20000) {
8585
Serial.print(".");
8686
delay(500);
8787
Serial.flush();
88-
}
88+
}
8989
Serial.println();
90-
}
91-
90+
}
91+
9292
// Check connection
9393
if(WiFi.status() == WL_CONNECTED ){
94-
LOG_I("Wifi AP SSID: %s connected, use 'http://%s' to connect\n", st_ssid, WiFi.localIP().toString().c_str());
94+
LOG_I("Wifi AP SSID: %s connected, use 'http://%s' to connect\n", st_ssid, WiFi.localIP().toString().c_str());
9595
}else{
9696
LOG_E("Connect failed.\n");
9797
LOG_I("Starting AP.\n");
@@ -100,57 +100,57 @@ void setup() {
100100
String hostName = "ControlAssist_" + mac.substring(6);
101101
WiFi.mode(WIFI_AP);
102102
WiFi.softAP(hostName.c_str(),"",1);
103-
LOG_I("Wifi AP SSID: %s started, use 'http://%s' to connect\n", WiFi.softAPSSID().c_str(), WiFi.softAPIP().toString().c_str());
104-
if (MDNS.begin(hostName.c_str())) LOG_V("AP MDNS responder Started\n");
103+
LOG_I("Wifi AP SSID: %s started, use 'http://%s' to connect\n", WiFi.softAPSSID().c_str(), WiFi.softAPIP().toString().c_str());
104+
if (MDNS.begin(hostName.c_str())) LOG_V("AP MDNS responder Started\n");
105105
}
106106

107-
107+
108108
// Control assist setup
109109
ctrl.setHtmlBody(HTML_BODY);
110110
ctrl.bind("span_ctrl");
111111
ctrl.bind("input_ctrl");
112112
ctrl.bind("text_ctrl");
113-
ctrl.bind("check_ctrl");
113+
ctrl.bind("check_ctrl");
114114
ctrl.bind("range_ctrl");
115115
ctrl.bind("button_ctrl");
116-
// Every time a variable changed changeHandler will be called
116+
// Every time a variable changed changeHandler will be called
117117
ctrl.setGlobalCallback(changeHandler);
118118
// Add a web server handler on url "/"
119119
ctrl.setup(server);
120120
// Start web sockets
121121
ctrl.begin();
122122
LOG_V("ControlAssist started.\n");
123-
// Setup webserver
124-
server.on("/d", []() { // Dump controls
123+
// Setup webserver
124+
server.on("/d", []() { // Dump controls
125125
ctrl.dump(&server);
126126
});
127-
// Start webs server
127+
// Start webs server
128128
server.begin();
129129
LOG_V("HTTP server started\n");
130-
130+
131131
pinMode(ADC_PIN, INPUT);
132132
}
133133

134134
void loop() {
135135
// Change html control values
136-
if (millis() - pingMillis >= 3000){
136+
if (millis() - pingMillis >= 3000){
137137
// Update control assist variables
138138
ctrl.put("span_ctrl", analogRead(ADC_PIN) );
139139
ctrl.put("input_ctrl", String(ESP.getCycleCount()));
140140
ctrl.put("text_ctrl", chBuff);
141141
ctrl.put("check_ctrl", buttonState );
142-
ctrl.put("range_ctrl", WiFi.RSSI() );
143-
ctrl.put("button_ctrl", buttonState );
144-
#if defined(ESP32)
142+
ctrl.put("range_ctrl", WiFi.RSSI() );
143+
ctrl.put("button_ctrl", buttonState );
144+
#if defined(ESP32)
145145
//ctrl.put("input_ctrl", String((temprature_sens_read() - 32) / 1.8 ) + " °C");
146146
sprintf(chBuff, "Memory Free: heap %u, block: %u, pSRAM %u", ESP.getFreeHeap(), heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL), ESP.getFreePsram());
147147
#else
148148
sprintf(chBuff,"Memory free heap: %u, stack: %u ,block: %u", ESP.getFreeHeap(), ESP.getFreeContStack(), ESP.getMaxFreeBlockSize());
149-
#endif
149+
#endif
150150
buttonState = !buttonState;
151151
pingMillis = millis();
152152
}
153-
153+
154154
#if not defined(ESP32)
155155
if(MDNS.isRunning()) MDNS.update(); // Handle MDNS
156156
#endif

0 commit comments

Comments
 (0)