Skip to content

Commit 310cad9

Browse files
committed
Added support dynamic interval timers on config page
1 parent 13ae65c commit 310cad9

File tree

6 files changed

+175
-115
lines changed

6 files changed

+175
-115
lines changed

ESP8266-MyWidget-Demo.ino

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2323
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424
SOFTWARE.
2525
26-
Version: 1.1.1
26+
Version: 1.1.2
2727
*/
2828
#include <ESP8266WiFi.h>
2929
#include <WiFiClient.h>
@@ -140,7 +140,7 @@ void handleWebSocketMessage(AsyncWebSocket *server, AsyncWebSocketClient *client
140140
buffer[len] = 0;
141141
Serial.printf("Handle WS: %s - len: %d\n", buffer, len);
142142

143-
char * token = strtok(buffer, ":");
143+
char *token = strtok(buffer, ":");
144144

145145
if(!strcmp("cmd", token)) {
146146
// Serial.println("cmd");
@@ -158,18 +158,42 @@ void handleWebSocketMessage(AsyncWebSocket *server, AsyncWebSocketClient *client
158158
// status
159159
client->text("cmd:get:status:" + String(ledState1));
160160
} else if (!strcmp("speed", token)) {
161-
String speed;
162-
// speed
163-
if(interruptInterval1 == INT_SLOW)
164-
speed = "1";
165-
else if(interruptInterval1 == INT_MED)
166-
speed = "2";
167-
else if(interruptInterval1 == INT_FAST)
168-
speed = "3";
169-
else if(interruptInterval1 == INT_FASTEST)
170-
speed = "4";
171-
172-
client->text("cmd:get:speed:" + String(speed));
161+
String speed = "1";
162+
// speed - cmd:get:speed:interrupt:speed
163+
char *intNum = strtok(NULL, ":");
164+
Serial.println("interrupt:" + String(intNum));
165+
if(intNum[0] == '1') {
166+
// interrupt - 1
167+
if(interruptInterval1 == INT_SLOW)
168+
speed = "1";
169+
else if(interruptInterval1 == INT_MED)
170+
speed = "2";
171+
else if(interruptInterval1 == INT_FAST)
172+
speed = "3";
173+
else if(interruptInterval1 == INT_FASTEST)
174+
speed = "4";
175+
} else if(intNum[0] == '2') {
176+
// interrupt - 2
177+
if(interruptInterval2 == INT_SLOW)
178+
speed = "1";
179+
else if(interruptInterval2 == INT_MED)
180+
speed = "2";
181+
else if(interruptInterval2 == INT_FAST)
182+
speed = "3";
183+
else if(interruptInterval2 == INT_FASTEST)
184+
speed = "4";
185+
} else if(intNum[0] == '3') {
186+
// interrupt - 3
187+
if(interruptInterval3 == INT_SLOW)
188+
speed = "1";
189+
else if(interruptInterval3 == INT_MED)
190+
speed = "2";
191+
else if(interruptInterval3 == INT_FAST)
192+
speed = "3";
193+
else if(interruptInterval3 == INT_FASTEST)
194+
speed = "4";
195+
}
196+
client->text("cmd:get:speed:" + String(intNum) + ":" + String(speed));
173197
} else if (!strcmp("config", token)) {
174198
// config
175199
String fileData;
@@ -197,10 +221,14 @@ void handleWebSocketMessage(AsyncWebSocket *server, AsyncWebSocketClient *client
197221
ledState1 = !ledState1;
198222
client->text("cmd:set:toggle:" + String(ledState1));
199223
} else if (!strcmp("speed", token)) {
200-
unsigned long tmpSpeed;
201-
// speed
224+
// default to slow
225+
unsigned long tmpSpeed = INT_SLOW;
226+
// speed - cmd:set:speed:interrupt:speed
227+
char *intNum = strtok(NULL, ":");
228+
Serial.println("interrupt:" + String(intNum));
202229
char *speed = strtok(NULL, ":");
203-
Serial.println(speed);
230+
Serial.println("speed:" + String(speed));
231+
204232
if(strlen(speed) == 1) {
205233
if(speed[0] == '1')
206234
tmpSpeed = INT_SLOW;
@@ -210,14 +238,30 @@ void handleWebSocketMessage(AsyncWebSocket *server, AsyncWebSocketClient *client
210238
tmpSpeed = INT_FAST;
211239
else if (speed[0] == '4')
212240
tmpSpeed = INT_FASTEST;
213-
241+
}
242+
if(intNum[0] == '1') {
243+
// interrupt - 1
214244
if(tmpSpeed != interruptInterval1) {
215245
interruptInterval1 = tmpSpeed;
216-
// update the interval for ledTimerISR
246+
// update the interval
217247
ISR_Timer.changeInterval(timer1_idx, interruptInterval1);
218248
}
249+
} else if(intNum[0] == '2') {
250+
// interrupt - 2
251+
if(tmpSpeed != interruptInterval2) {
252+
interruptInterval2 = tmpSpeed;
253+
// update the interval
254+
ISR_Timer.changeInterval(timer2_idx, interruptInterval2);
255+
}
256+
} else if(intNum[0] == '3') {
257+
// interrupt - 3
258+
if(tmpSpeed != interruptInterval2) {
259+
interruptInterval3 = tmpSpeed;
260+
// update the interval
261+
ISR_Timer.changeInterval(timer3_idx, interruptInterval3);
262+
}
219263
}
220-
client->text("cmd:set:speed:" + String(speed));
264+
client->text("cmd:set:speed:" + String(intNum) + ":" + String(speed));
221265
} else if (!strcmp("config", token)) {
222266
String(buf);
223267
// config

README.html

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ <h2>Web Services</h2>
8989
</ul>
9090
<br>
9191
<ul>
92-
<li>Speed - Returns flash speed of onboard LED</li>
93-
<li>Request: ''cmd:get:speed''</li>
94-
<li>Response: ''cmd:get:speed:N''</li>
92+
<li>Speed - Returns timer speed of the interrupt handler</li>
93+
<li>Request: ''cmd:get:speed:X''</li>
94+
<li>Response: ''cmd:get:speed:X:N''</li>
9595
<ul>
96-
<li>where N is "1" to "4" representing representing flash speed of onboard LED</li>
96+
<li>where X is the "1" to "3" representing the number of the interrupt handler</li>
97+
<li>where N is "1" to "4" representing the speed of the interrupt timer</li>
9798
</ul>
9899
</ul>
99100
<br>
@@ -120,11 +121,12 @@ <h2>Web Services</h2>
120121
</ul>
121122
<br>
122123
<ul>
123-
<li>Speeds - Sets the flash speed of onboard LED</li>
124-
<li>Request: ''cmd:set:speed''</li>
125-
<li>Response: ''cmd:set:speed:N''</li>
124+
<li>Speeds - Sets the timer speed of interrupt handler</li>
125+
<li>Request: ''cmd:set:speed:X:N''</li>
126+
<li>Response: ''cmd:set:speed:X:N''</li>
126127
<ul>
127-
<li>where N is "1" to "4" representing the flash speed of onboard LED</li>
128+
<li>where X is the "1" to "3" representing the number of the interrupt handler</li>
129+
<li>where N is "1" to "4" representing the speed of the interrupt timer</li>
128130
</ul>
129131
</ul>
130132
<br>
@@ -582,7 +584,7 @@ <h2>Future Enhancements</h2>
582584
<br>
583585
<ul>
584586
<li>[X] Support multiple interrupt timers (ESP8266TimerInterrupt)</li>
585-
<li>[&nbsp] Support dynamic interval timers on config page</li>
587+
<li>[X] Support dynamic interval timers on config page</li>
586588
<li>[X] Support HTTP GET INTERRUPT COUNT with optional parameters</li>
587589
<li>[&nbsp] Asynch NTP support</li>
588590
<li>[&nbsp] More code comments</li>

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ Extract the folder in each of these zip files and place it in the "library" fold
8484
- Response: ''cmd:get:status:N''
8585
- where N is "0" or "1" representing "OFF" or "ON" of light
8686

87-
- Speed - Returns flash speed of onboard LED
88-
- Request: ''cmd:get:speed''
89-
- Response: ''cmd:get:speed:N''
90-
- where N is "1" to "4" representing flash speed of onboard LED
87+
- Speed - Returns timer speed of interrupt handler
88+
- Request: ''cmd:get:speed:X''
89+
- Response: ''cmd:get:speed:X:N''
90+
- where X is the "1" to "3" representing the number of the interrupt handler
91+
- where N is "1" to "4" representing speed of the interrupt timer
9192

9293
- Config - Returns current configuration parameters. Read from /cfg.txt file.
9394
- Request: ''cmd:get:config''
@@ -101,10 +102,11 @@ Extract the folder in each of these zip files and place it in the "library" fold
101102
- Response: ''cmd:set:toggle:N''
102103
- where N is "0" or "1" representing "OFF" or "ON" of light
103104

104-
- Speed - Sets the flash speed of onboard LED
105-
- Request: ''cmd:set:speed''
106-
- Response: ''cmd:set:speed:N''
107-
- where N is "1" to "4" representing flash speed of onboard LED
105+
- Speed - Sets the timer speed of interrupt handler
106+
- Request: ''cmd:set:speed:X:N''
107+
- Response: ''cmd:set:speed:X:N''
108+
- where X is the "1" to "3" representing the number of the interrupt handler
109+
- where N is "1" to "4" representing speed of the interrupt timer
108110

109111
- Config - Sets current configuration parameters. Saved to /cfg.txt file.
110112
- Request: ''cmd:set:config:config:channels:ports:user1:user2''
@@ -170,7 +172,7 @@ Extract the folder in each of these zip files and place it in the "library" fold
170172
- Query string parameters (optional):
171173
- Request:
172174
- 1=true, 2=true, 3=true
173-
- Response::
175+
- Response:
174176
- Interrupt Counter(s) based on query string
175177
- Name value pairs are delimited using colon ":".
176178
- Name and value fields are delimited using a equal "=" sign.
@@ -394,7 +396,7 @@ Later I went back and added an HTTP GET with JSON response example without any J
394396
## Future Enhancements
395397

396398
- [X] Support multiple interrupt timers (ESP8266TimerInterrupt)
397-
- [ ] Support dynamic interval timers on config page
399+
- [X] Support dynamic interval timers on config page
398400
- [X] Support HTTP GET INTERRUPT COUNT with optional parameters
399401
- [ ] Asynch NTP support
400402
- [ ] More code comments

0 commit comments

Comments
 (0)