Guest User

Untitled

a guest
Jan 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. char webpage[] PROGMEM = R"=====(
  2. <html>
  3. <head>
  4. <script>
  5. var Socket;
  6. function init() {
  7. Socket = new WebSocket('ws://' + window.location.hostname + ':81/');
  8. }
  9. function sendangleT(){ //motor
  10. Socket.send("T"+document.getElementById("valueT").value);
  11. }
  12. </script>
  13. </head>
  14. <body onload="javascript:init()">
  15. <div>
  16. <input type="range" min="0" max="1048" value="0" id="valueT"
  17. oninput="sendangleT()" />
  18. </div>
  19. <hr/>
  20. </body>
  21. </html>
  22. )=====";
  23.  
  24. #include <WiFi.h>
  25. #include <WebSocketsServer.h>
  26. const char* ssid = "MySSID";
  27. const char* password = "MyPassword";
  28.  
  29. WebSocketsServer webSocket = WebSocketsServer(80);
  30.  
  31. void onWebSocketEvent(uint8_t num,WStype_t type,uint8_t * payload,size_t
  32. length) {
  33. switch(type) {
  34. case WStype_DISCONNECTED:
  35. Serial.printf("[%u] Disconnected!n", num);
  36. break;
  37. case WStype_CONNECTED:
  38. {
  39. IPAddress ip = webSocket.remoteIP(num);
  40. Serial.printf("[%u] Connection from ", num);
  41. Serial.println(ip.toString());
  42. }
  43. break;
  44. case WStype_TEXT:
  45. Serial.printf("[%u] Text: %sn", num, payload);
  46. webSocket.sendTXT(num, payload);
  47. break;
  48. case WStype_BIN:
  49. case WStype_ERROR:
  50. case WStype_FRAGMENT_TEXT_START:
  51. case WStype_FRAGMENT_BIN_START:
  52. case WStype_FRAGMENT:
  53. case WStype_FRAGMENT_FIN:
  54. default:
  55. break;
  56. }
  57. }
  58. void setup() {
  59. Serial.begin(115200);
  60. Serial.println("Connecting");
  61. WiFi.begin(ssid, password);
  62. while ( WiFi.status() != WL_CONNECTED ) {
  63. delay(500);
  64. Serial.print(".");
  65. }
  66. Serial.println("Connected!");
  67. Serial.print("My IP address: ");
  68. Serial.println(WiFi.localIP());
  69. webSocket.begin();
  70. webSocket.onEvent(onWebSocketEvent);
  71. }
  72. void loop() {
  73. webSocket.loop();
  74. }
Add Comment
Please, Sign In to add comment