Skip to content

Commit

Permalink
Added support dynamic interval timers on config page
Browse files Browse the repository at this point in the history
  • Loading branch information
onewithhammer committed Feb 22, 2021
1 parent 13ae65c commit 310cad9
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 115 deletions.
84 changes: 64 additions & 20 deletions ESP8266-MyWidget-Demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Version: 1.1.1
Version: 1.1.2
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
Expand Down Expand Up @@ -140,7 +140,7 @@ void handleWebSocketMessage(AsyncWebSocket *server, AsyncWebSocketClient *client
buffer[len] = 0;
Serial.printf("Handle WS: %s - len: %d\n", buffer, len);

char * token = strtok(buffer, ":");
char *token = strtok(buffer, ":");

if(!strcmp("cmd", token)) {
// Serial.println("cmd");
Expand All @@ -158,18 +158,42 @@ void handleWebSocketMessage(AsyncWebSocket *server, AsyncWebSocketClient *client
// status
client->text("cmd:get:status:" + String(ledState1));
} else if (!strcmp("speed", token)) {
String speed;
// speed
if(interruptInterval1 == INT_SLOW)
speed = "1";
else if(interruptInterval1 == INT_MED)
speed = "2";
else if(interruptInterval1 == INT_FAST)
speed = "3";
else if(interruptInterval1 == INT_FASTEST)
speed = "4";

client->text("cmd:get:speed:" + String(speed));
String speed = "1";
// speed - cmd:get:speed:interrupt:speed
char *intNum = strtok(NULL, ":");
Serial.println("interrupt:" + String(intNum));
if(intNum[0] == '1') {
// interrupt - 1
if(interruptInterval1 == INT_SLOW)
speed = "1";
else if(interruptInterval1 == INT_MED)
speed = "2";
else if(interruptInterval1 == INT_FAST)
speed = "3";
else if(interruptInterval1 == INT_FASTEST)
speed = "4";
} else if(intNum[0] == '2') {
// interrupt - 2
if(interruptInterval2 == INT_SLOW)
speed = "1";
else if(interruptInterval2 == INT_MED)
speed = "2";
else if(interruptInterval2 == INT_FAST)
speed = "3";
else if(interruptInterval2 == INT_FASTEST)
speed = "4";
} else if(intNum[0] == '3') {
// interrupt - 3
if(interruptInterval3 == INT_SLOW)
speed = "1";
else if(interruptInterval3 == INT_MED)
speed = "2";
else if(interruptInterval3 == INT_FAST)
speed = "3";
else if(interruptInterval3 == INT_FASTEST)
speed = "4";
}
client->text("cmd:get:speed:" + String(intNum) + ":" + String(speed));
} else if (!strcmp("config", token)) {
// config
String fileData;
Expand Down Expand Up @@ -197,10 +221,14 @@ void handleWebSocketMessage(AsyncWebSocket *server, AsyncWebSocketClient *client
ledState1 = !ledState1;
client->text("cmd:set:toggle:" + String(ledState1));
} else if (!strcmp("speed", token)) {
unsigned long tmpSpeed;
// speed
// default to slow
unsigned long tmpSpeed = INT_SLOW;
// speed - cmd:set:speed:interrupt:speed
char *intNum = strtok(NULL, ":");
Serial.println("interrupt:" + String(intNum));
char *speed = strtok(NULL, ":");
Serial.println(speed);
Serial.println("speed:" + String(speed));

if(strlen(speed) == 1) {
if(speed[0] == '1')
tmpSpeed = INT_SLOW;
Expand All @@ -210,14 +238,30 @@ void handleWebSocketMessage(AsyncWebSocket *server, AsyncWebSocketClient *client
tmpSpeed = INT_FAST;
else if (speed[0] == '4')
tmpSpeed = INT_FASTEST;

}
if(intNum[0] == '1') {
// interrupt - 1
if(tmpSpeed != interruptInterval1) {
interruptInterval1 = tmpSpeed;
// update the interval for ledTimerISR
// update the interval
ISR_Timer.changeInterval(timer1_idx, interruptInterval1);
}
} else if(intNum[0] == '2') {
// interrupt - 2
if(tmpSpeed != interruptInterval2) {
interruptInterval2 = tmpSpeed;
// update the interval
ISR_Timer.changeInterval(timer2_idx, interruptInterval2);
}
} else if(intNum[0] == '3') {
// interrupt - 3
if(tmpSpeed != interruptInterval2) {
interruptInterval3 = tmpSpeed;
// update the interval
ISR_Timer.changeInterval(timer3_idx, interruptInterval3);
}
}
client->text("cmd:set:speed:" + String(speed));
client->text("cmd:set:speed:" + String(intNum) + ":" + String(speed));
} else if (!strcmp("config", token)) {
String(buf);
// config
Expand Down
20 changes: 11 additions & 9 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ <h2>Web Services</h2>
</ul>
<br>
<ul>
<li>Speed - Returns flash speed of onboard LED</li>
<li>Request: ''cmd:get:speed''</li>
<li>Response: ''cmd:get:speed:N''</li>
<li>Speed - Returns timer speed of the interrupt handler</li>
<li>Request: ''cmd:get:speed:X''</li>
<li>Response: ''cmd:get:speed:X:N''</li>
<ul>
<li>where N is "1" to "4" representing representing flash speed of onboard LED</li>
<li>where X is the "1" to "3" representing the number of the interrupt handler</li>
<li>where N is "1" to "4" representing the speed of the interrupt timer</li>
</ul>
</ul>
<br>
Expand All @@ -120,11 +121,12 @@ <h2>Web Services</h2>
</ul>
<br>
<ul>
<li>Speeds - Sets the flash speed of onboard LED</li>
<li>Request: ''cmd:set:speed''</li>
<li>Response: ''cmd:set:speed:N''</li>
<li>Speeds - Sets the timer speed of interrupt handler</li>
<li>Request: ''cmd:set:speed:X:N''</li>
<li>Response: ''cmd:set:speed:X:N''</li>
<ul>
<li>where N is "1" to "4" representing the flash speed of onboard LED</li>
<li>where X is the "1" to "3" representing the number of the interrupt handler</li>
<li>where N is "1" to "4" representing the speed of the interrupt timer</li>
</ul>
</ul>
<br>
Expand Down Expand Up @@ -582,7 +584,7 @@ <h2>Future Enhancements</h2>
<br>
<ul>
<li>[X] Support multiple interrupt timers (ESP8266TimerInterrupt)</li>
<li>[&nbsp] Support dynamic interval timers on config page</li>
<li>[X] Support dynamic interval timers on config page</li>
<li>[X] Support HTTP GET INTERRUPT COUNT with optional parameters</li>
<li>[&nbsp] Asynch NTP support</li>
<li>[&nbsp] More code comments</li>
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ Extract the folder in each of these zip files and place it in the "library" fold
- Response: ''cmd:get:status:N''
- where N is "0" or "1" representing "OFF" or "ON" of light

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

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

- Speed - Sets the flash speed of onboard LED
- Request: ''cmd:set:speed''
- Response: ''cmd:set:speed:N''
- where N is "1" to "4" representing flash speed of onboard LED
- Speed - Sets the timer speed of interrupt handler
- Request: ''cmd:set:speed:X:N''
- Response: ''cmd:set:speed:X:N''
- where X is the "1" to "3" representing the number of the interrupt handler
- where N is "1" to "4" representing speed of the interrupt timer

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

- [X] Support multiple interrupt timers (ESP8266TimerInterrupt)
- [ ] Support dynamic interval timers on config page
- [X] Support dynamic interval timers on config page
- [X] Support HTTP GET INTERRUPT COUNT with optional parameters
- [ ] Asynch NTP support
- [ ] More code comments
Expand Down
Loading

0 comments on commit 310cad9

Please sign in to comment.