Advertisement
Guest User

Untitled

a guest
May 26th, 2016
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <WiFiClient.h>
  3. #include <WebSocketsServer.h>
  4. #include <Hash.h>
  5. #include <Metro.h> // Include the Metro library
  6. #include <AsyncPrinter.h>
  7. #include <ESPAsyncTCP.h>
  8. #include <ESPAsyncTCPbuffer.h>
  9. #include <SyncClient.h>
  10.  
  11.  
  12. /* Set these to your desired credentials. */
  13. const char *ssid = "ESPap2";
  14. const char *password = "123123123123";
  15. WebSocketsServer webSocket = WebSocketsServer(81);
  16.  
  17.  
  18.  
  19. void sendMessage(uint8_t num) {
  20. webSocket.sendTXT(num, "received some stuff dude");
  21. }
  22.  
  23.  
  24. // WebSOcket Events
  25. void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
  26.  
  27. switch (type) {
  28. case WStype_DISCONNECTED:
  29. break;
  30. case WStype_CONNECTED:
  31. {
  32. IPAddress ip = webSocket.remoteIP(num);
  33. }
  34. break;
  35.  
  36. case WStype_TEXT:
  37. {
  38. String text = String((char *) &payload[0]);
  39. sendMessage(num);
  40. yield();
  41. }
  42. break;
  43.  
  44. case WStype_BIN:
  45. hexdump(payload, length);
  46. // echo data back to browser
  47. webSocket.sendBIN(num, payload, length);
  48. break;
  49. }
  50. }
  51.  
  52.  
  53. void setup() {
  54. IPAddress address(10, 10, 100, 254);
  55. IPAddress subnet(255, 255, 255, 0);
  56.  
  57. byte channel = 11;
  58. float wifiOutputPower = 20.5; //Max power
  59. WiFi.setOutputPower(wifiOutputPower);
  60. WiFi.setPhyMode(WIFI_PHY_MODE_11B);
  61. WiFi.setSleepMode(WIFI_NONE_SLEEP);
  62. WiFi.disconnect(true);
  63. WiFi.mode(WIFI_AP);
  64.  
  65. WiFi.persistent(false);
  66. WiFi.softAPConfig(address, address, subnet);
  67. WiFi.softAP(ssid, password, channel);
  68. IPAddress myIP = WiFi.softAPIP();
  69.  
  70. // Serial.print("AP IP address: ");
  71. // Serial.println(myIP);
  72. webSocket.begin();
  73. webSocket.onEvent(webSocketEvent);
  74. }
  75.  
  76. void loop() {
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement