Skip to content

Commit

Permalink
working example of webpage with custom scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
say-paul committed Mar 21, 2024
1 parent 652946c commit d0e1b48
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions examples/14_blite_rc_car/14_blite_rc_car.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <blite.h>
#include <ESP8266WebServer.h>
#include <WebSocketsServer.h>
#include "remote.h"

Expand All @@ -14,8 +13,9 @@


Blite mybot;
ESP8266WebServer wifiRemoteControl(80);
WebSocketsServer webSocket = WebSocketsServer(81); // WebSocket server on port 81
String html_string = REMOTE_HTML_CONTENT;

void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length) {
switch (type) {
case WStype_DISCONNECTED:
Expand Down Expand Up @@ -79,19 +79,11 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
void setup(){
mybot.setup();
Serial.begin(115200);
mybot.smartConnectWiFi();
mybot.APServer();
webSocket.begin();
webSocket.onEvent(webSocketEvent);
wifiRemoteControl.on("/", HTTP_GET, []() {
Serial.println("Web Server: received a web page request");
String html = REMOTE_HTML_CONTENT;
wifiRemoteControl.send(200, "text/html", html);
});
wifiRemoteControl.begin();

}
void loop(){
wifiRemoteControl.handleClient();
mybot.smartRenderServer(html_string);
webSocket.loop();

}

0 comments on commit d0e1b48

Please sign in to comment.