Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char webpage[] PROGMEM = R"=====(
- <html>
- <head>
- <script>
- var Socket;
- function init() {
- Socket = new WebSocket('ws://' + window.location.hostname + ':81/');
- }
- function sendangleT(){ //motor
- Socket.send("T"+document.getElementById("valueT").value);
- }
- </script>
- </head>
- <body onload="javascript:init()">
- <div>
- <input type="range" min="0" max="1048" value="0" id="valueT"
- oninput="sendangleT()" />
- </div>
- <hr/>
- </body>
- </html>
- )=====";
- #include <WiFi.h>
- #include <WebSocketsServer.h>
- const char* ssid = "MySSID";
- const char* password = "MyPassword";
- WebSocketsServer webSocket = WebSocketsServer(80);
- void onWebSocketEvent(uint8_t num,WStype_t type,uint8_t * payload,size_t
- length) {
- switch(type) {
- case WStype_DISCONNECTED:
- Serial.printf("[%u] Disconnected!n", num);
- break;
- case WStype_CONNECTED:
- {
- IPAddress ip = webSocket.remoteIP(num);
- Serial.printf("[%u] Connection from ", num);
- Serial.println(ip.toString());
- }
- break;
- case WStype_TEXT:
- Serial.printf("[%u] Text: %sn", num, payload);
- webSocket.sendTXT(num, payload);
- break;
- case WStype_BIN:
- case WStype_ERROR:
- case WStype_FRAGMENT_TEXT_START:
- case WStype_FRAGMENT_BIN_START:
- case WStype_FRAGMENT:
- case WStype_FRAGMENT_FIN:
- default:
- break;
- }
- }
- void setup() {
- Serial.begin(115200);
- Serial.println("Connecting");
- WiFi.begin(ssid, password);
- while ( WiFi.status() != WL_CONNECTED ) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("Connected!");
- Serial.print("My IP address: ");
- Serial.println(WiFi.localIP());
- webSocket.begin();
- webSocket.onEvent(onWebSocketEvent);
- }
- void loop() {
- webSocket.loop();
- }
Add Comment
Please, Sign In to add comment