Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <WiFiClient.h>
- #include <WebSocketsServer.h>
- #include <Hash.h>
- #include <Metro.h> // Include the Metro library
- #include <AsyncPrinter.h>
- #include <ESPAsyncTCP.h>
- #include <ESPAsyncTCPbuffer.h>
- #include <SyncClient.h>
- /* Set these to your desired credentials. */
- const char *ssid = "ESPap2";
- const char *password = "123123123123";
- WebSocketsServer webSocket = WebSocketsServer(81);
- void sendMessage(uint8_t num) {
- webSocket.sendTXT(num, "received some stuff dude");
- }
- // WebSOcket Events
- void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
- switch (type) {
- case WStype_DISCONNECTED:
- break;
- case WStype_CONNECTED:
- {
- IPAddress ip = webSocket.remoteIP(num);
- }
- break;
- case WStype_TEXT:
- {
- String text = String((char *) &payload[0]);
- sendMessage(num);
- yield();
- }
- break;
- case WStype_BIN:
- hexdump(payload, length);
- // echo data back to browser
- webSocket.sendBIN(num, payload, length);
- break;
- }
- }
- void setup() {
- IPAddress address(10, 10, 100, 254);
- IPAddress subnet(255, 255, 255, 0);
- byte channel = 11;
- float wifiOutputPower = 20.5; //Max power
- WiFi.setOutputPower(wifiOutputPower);
- WiFi.setPhyMode(WIFI_PHY_MODE_11B);
- WiFi.setSleepMode(WIFI_NONE_SLEEP);
- WiFi.disconnect(true);
- WiFi.mode(WIFI_AP);
- WiFi.persistent(false);
- WiFi.softAPConfig(address, address, subnet);
- WiFi.softAP(ssid, password, channel);
- IPAddress myIP = WiFi.softAPIP();
- // Serial.print("AP IP address: ");
- // Serial.println(myIP);
- webSocket.begin();
- webSocket.onEvent(webSocketEvent);
- }
- void loop() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement