Skip to content

Commit

Permalink
more documentation and small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikN committed Dec 22, 2020
1 parent 4630e5a commit 14e7ef7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The template combines all useful technologies in one:
A demo is really basic:

- control a LED connected to ESP32 by using a button in web UI.
- update cnt value in the web ui every 1s
- ESP32 sends a button state to change a color of the dot in web UI.

To run the project, open Visual Studio Code with Platformio extension and follow these steps:
Expand Down
Binary file modified screenshot_esp32_webui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions src/ESP32-http-websocket.ino
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ void taskWifi(void* parameter) {
static char output[200];
int cnt = 0;
int lastButtonState = digitalRead(BUTTON_PIN);
TickType_t xLastWakeTime = xTaskGetTickCount();

/* Configure Wi-Fi */
for (int i = 0; i < NUM_NETWORKS; i++) {
Expand Down Expand Up @@ -199,10 +200,12 @@ void taskWifi(void* parameter) {

while (1) {
while (WiFi.status() == WL_CONNECTED) {
if ((wsconnected == true) && (lastButtonState != digitalRead(BUTTON_PIN))) {
cnt++;
if ((wsconnected == true) &&
((lastButtonState != digitalRead(BUTTON_PIN)) || (cnt % 100 == 0))) {
lastButtonState = digitalRead(BUTTON_PIN);
jsonDocTx.clear();
jsonDocTx["counter"] = cnt++;
jsonDocTx["counter"] = cnt;
jsonDocTx["button"] = lastButtonState;

serializeJson(jsonDocTx, output, 200);
Expand All @@ -215,7 +218,7 @@ void taskWifi(void* parameter) {
Serial.printf("...queue is full\r\n");
}
} else {
delay(10);
vTaskDelayUntil(&xLastWakeTime, 10 / portTICK_PERIOD_MS);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
function WebSocketBegin() {
if ("WebSocket" in window) {
// Let us open a web socket
ws = new WebSocket(
location.hostname.match(/\.husarnetusers\.com$/) ? "wss://" + location.hostname + "/__port_8000/ws" : "ws://" + location.hostname + ":8000/ws"
);
// ws = new WebSocket(
// location.hostname.match(/\.husarnetusers\.com$/) ? "wss://" + location.hostname + "/__port_8000/ws" : "ws://" + location.hostname + ":8000/ws"
// "wss://fc9434c5513c3543753124468f76fa507-8000.husarnetusers.com/ws"
// );
// ws = new WebSocket(
// "wss://fc9434c5513c3543753124468f76fa507-8000.husarnetusers.com/ws"
// "ws://esp32websocket:8000/ws"
// );
ws = new WebSocket(
"ws://esp32websocket:8000/ws"
);

ws.onopen = function () {
// Web Socket is connected
Expand Down Expand Up @@ -104,7 +104,7 @@ <h1><i class="fas fa-cog"></i> ESP32 control</h1>
<div class="card-body">
<h5 class="card-title">Counter</h5>
<p class="card-text">
A counter value is updated every 100ms by ESP32.
A counter value is updated every 1s by ESP32.
</p>
<p id="cnt" class="font-weight-bold">
0
Expand Down

0 comments on commit 14e7ef7

Please sign in to comment.