{"id":15011965,"url":"https://github.com/skaarj1989/mwebsockets","last_synced_at":"2025-07-23T16:05:02.833Z","repository":{"id":48620944,"uuid":"115284629","full_name":"skaarj1989/mWebSockets","owner":"skaarj1989","description":"WebSockets for microcontrollers","archived":false,"fork":false,"pushed_at":"2024-06-06T16:25:24.000Z","size":6397,"stargazers_count":108,"open_issues_count":4,"forks_count":23,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-12-19T20:08:25.806Z","etag":null,"topics":["arduino","arduino-uno","arduino-zero","arm-cortex","client","cpp11","enc28j60","esp32","esp8266","ethernet-shield","mega2560","nucleo","platformio","rfc6455","samd21","server","stm32","w5100","w5500","websockets"],"latest_commit_sha":null,"homepage":"https://skaarj1989.github.io/mWebSockets/autobahn-testsuite/servers/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skaarj1989.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-24T20:02:21.000Z","updated_at":"2024-11-15T08:05:43.000Z","dependencies_parsed_at":"2023-12-21T04:57:32.172Z","dependency_job_id":"2ff63524-8fb7-442e-897c-f49d87d232b0","html_url":"https://github.com/skaarj1989/mWebSockets","commit_stats":{"total_commits":209,"total_committers":4,"mean_commits":52.25,"dds":"0.13875598086124397","last_synced_commit":"7c1efc973e05e9644c5490671fc480679b32c503"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skaarj1989%2FmWebSockets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skaarj1989%2FmWebSockets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skaarj1989%2FmWebSockets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skaarj1989%2FmWebSockets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skaarj1989","download_url":"https://codeload.github.com/skaarj1989/mWebSockets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230494921,"owners_count":18235046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","arduino-uno","arduino-zero","arm-cortex","client","cpp11","enc28j60","esp32","esp8266","ethernet-shield","mega2560","nucleo","platformio","rfc6455","samd21","server","stm32","w5100","w5500","websockets"],"created_at":"2024-09-24T19:41:57.162Z","updated_at":"2024-12-19T20:08:32.552Z","avatar_url":"https://github.com/skaarj1989.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# μWebSockets\r\n\r\n[![arduino-library-badge](https://www.ardu-badge.com/badge/mWebSockets.svg?)](https://www.ardu-badge.com/mWebSockets)\r\n[![Build Status](https://travis-ci.org/skaarj1989/mWebSockets.svg?branch=master)](https://travis-ci.org/skaarj1989/mWebSockets)\r\n[![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/skaarj1989/mWebSockets)](https://www.codefactor.io/repository/github/skaarj1989/mwebsockets/overview/master)\r\n![GitHub](https://img.shields.io/github/license/skaarj1989/mWebSockets.svg)\r\n\r\nSimple to use implementation of WebSockets for microcontrollers.\r\n\r\n**List of supported IDEs:**\r\n\r\n- [Arduino](https://www.arduino.cc/en/Main/Software)\r\n- Visual Studio Code with [Platformio](https://platformio.org/)\r\n- Microsoft Visual Studio with [Visual Micro](https://www.visualmicro.com/)\r\n\r\n**List of supported MCUs:**\r\n\r\n- ATmega328P\r\n- ATmega2560\r\n- Renesas RA4M1 (ARM Cortex-M4)\r\n- SAMD21 (ARM Cortex-M0+)\r\n- STM32 (ARM Cortex-M)\r\n- ESP8266\r\n- ESP32-WROOM-32D\r\n\r\n**WebSocketServer compatible browsers:**\r\n\r\n- Chrome\r\n- Edge\r\n- Firefox\r\n- Opera\r\n\r\n\u003e The **Autobahn**|Testsuite reports for [server](https://skaarj1989.github.io/mWebSockets/autobahn-testsuite/servers/index.html) and [client](https://skaarj1989.github.io/mWebSockets/autobahn-testsuite/clients/index.html) \u003cbr\u003e\u003csup\u003eSome tests will never pass just because of memory lack in ATmega family.\u003c/sup\u003e\r\n\r\n## Table of contents\r\n\r\n- [μWebSockets](#μwebsockets)\r\n  - [Table of contents](#table-of-contents)\r\n  - [Requirements](#requirements)\r\n  - [Installation](#installation)\r\n    - [config.h](#configh)\r\n    - [Physical connection](#physical-connection)\r\n  - [Usage examples](#usage-examples)\r\n    - [Server](#server)\r\n      - [Verify clients](#verify-clients)\r\n      - [Subprotocol negotiation](#subprotocol-negotiation)\r\n    - [Client](#client)\r\n    - [Chat](#chat)\r\n  - [Approx memory usage](#approx-memory-usage)\r\n    - [Ethernet.h (W5100 and W5500)](#etherneth-w5100-and-w5500)\r\n    - [EthernetENC.h (ENC28j60)](#ethernetench-enc28j60)\r\n    - [WiFi](#wifi)\r\n  - [Known issues](#known-issues)\r\n  - [License](#license)\r\n\r\n## Requirements\r\n\r\n- Development board (confirmed working, other boards may or may not work):\r\n  - Arduino Uno (ATmega328P)\r\n  - Arduino Pro Mini (ATmega328P)\r\n  - Arduino Mega2560\r\n  - Arduino Uno R4 Minima/WiFi (ARM Cortex-M4)\r\n  - Arduino Zero / SAMD21 M0 (ARM Cortex-M0)\r\n  - STM Nucleo-64 (ARM Cortex-M)\r\n  - WeMos D1 mini (ESP8266)\r\n  - NodeMCU v3 (ESP8266)\r\n  - ESPDUINO-32 (ESP32-WROOM-32D)\r\n- Ethernet module or shield (confirmed working):\r\n  - Arduino Ethernet Shield (W5100)\r\n  - Arduino Ethernet Shield 2 (W5500)\r\n  - WizNet W5500 module\r\n  - ENC28j60\r\n- Libraries:\r\n  - [EthernetENC](https://github.com/jandrassy/EthernetENC) if you decide to use ENC28j60\r\n\r\n## Installation\r\n\r\nUse [Arduino Download Manager](https://www.ardu-badge.com/mWebSockets) or follow [this](https://www.arduino.cc/en/Guide/Libraries) guide.\r\n\r\n### config.h\r\n\r\nChange the following definition if you use a different network controller:\r\n\r\n```cpp\r\n...\r\n\r\n#define NETWORK_CONTROLLER ETHERNET_CONTROLLER_W5X00\r\n```\r\n\r\n```cpp\r\nETHERNET_CONTROLLER_W5X00\r\nETHERNET_CONTROLLER_ENC28J60\r\nNETWORK_CONTROLLER_WIFI\r\n```\r\n\r\n\u003e `ETHERNET_CONTROLLER_W5X00` stands for the official Arduino Ethernet library.\r\n\r\nUncomment these if you want additional information on the serial monitor:\r\n\r\n```cpp\r\n//#define _DEBUG\r\n//#define _DUMP_HANDSHAKE\r\n//#define _DUMP_FRAME_DATA\r\n//#define _DUMP_HEADER\r\n```\r\n\r\nIncrease the following value if you expect big data frames (or decrease for devices with a small amount of memory).\r\n\r\n```cpp\r\nconstexpr uint16_t kBufferMaxSize{ 256 };\r\n```\r\n\r\n### Physical connection\r\n\r\nIf you have a **WeMos D1** in the size of **Arduino Uno** simply attaching a shield does not work. You have to wire the **ICSP** on an **Ethernet Shield** to proper pins.\r\n\r\n| Ethernet Shield \u003cbr\u003e (W5100/W5500) | Arduino \u003cbr\u003e Pro Mini |  WeMos D1  |\r\n| :--------------------------------: | :-------------------: | :--------: |\r\n|            (ICSP) MISO             |        PIN 12         | D12 / MISO |\r\n|            (ICSP) MOSI             |        PIN 11         | D11 / MOSI |\r\n|             (ICSP) SCK             |        PIN 13         | D13 / SCK  |\r\n|            (SS) PIN 10             |        PIN 10         |  D10 / SS  |\r\n\r\n| W5500 / \u003cbr\u003e ENC28j60 | Arduino Uno / \u003cbr\u003e Pro Mini | Arduino \u003cbr\u003e Mega2560 |\r\n| :-------------------: | :-------------------------: | :-------------------: |\r\n|         MISO          |           PIN 12            |        PIN 50         |\r\n|         MOSI          |           PIN 11            |        PIN 51         |\r\n|          SCS          |           PIN 10            |        PIN 53         |\r\n|         SCLK          |           PIN 13            |        PIN 52         |\r\n\r\n## Usage examples\r\n\r\n### Server\r\n\r\n```cpp\r\n#include \u003cWebSocketServer.h\u003e\r\nusing namespace net;\r\n\r\nWebSocketServer server{3000};\r\n\r\nvoid setup() {\r\n  // Ethernet/WiFi initialization goes here ...\r\n  // ...\r\n\r\n  server.onConnection([](WebSocket \u0026ws) {\r\n    const char message[]{ \"Hello from Arduino server!\" };\r\n    ws.send(WebSocket::DataType::TEXT, message, strlen(message));\r\n\r\n    ws.onClose([](WebSocket \u0026ws, const WebSocket::CloseCode code,\r\n                 const char *reason, uint16_t length) {\r\n      // ...\r\n    });\r\n    ws.onMessage([](WebSocket \u0026ws, const WebSocket::DataType dataType,\r\n                   const char *message, uint16_t length) {\r\n      // ...\r\n    });\r\n  });\r\n\r\n  server.begin();\r\n}\r\n\r\nvoid loop() {\r\n  server.listen();\r\n}\r\n```\r\n\r\n#### Verify clients\r\n\r\n```cpp\r\n// verifyClient callback is called for every header during handshake\r\n// (except for those required by protocol, like \"Connection\", \"Upgrade\" etc.)\r\nserver.begin([](const IPAddress \u0026ip, const char *header, const char *value) {\r\n  // verify ip ...\r\n\r\n  // verify \"Origin\" header:\r\n  if (strcmp_P(header, (PGM_P)F(\"Origin\")) == 0)\r\n    if (strcmp_P(value, (PGM_P)F(\"file://\")) == 0) return false;\r\n\r\n  return true;\r\n});\r\n```\r\n\r\n#### Subprotocol negotiation\r\n\r\n```cpp\r\n// If you won't pass callback for `protocolHandler` then server will use the\r\n// first requested subprotocol if any\r\nwss.begin(nullptr, [](const char *protocols) {\r\n  // iterate csv protocols and return the one that is supported by your server\r\n  // or nullptr to ignore\r\n});\r\n\r\n// You can check client protocol in other callbacks\r\nwss.onConnection([](WebSocket \u0026ws) {\r\n  const auto protocol = ws.getProtocol();\r\n  // ...\r\n  }\r\n});\r\n```\r\n\r\n\u003e Node.js server examples [here](https://github.com/skaarj1989/mWebSockets/tree/master/node.js)\r\n\r\n### Client\r\n\r\n```cpp\r\n#include \u003cWebSocketClient.h\u003e\r\nusing namespace net;\r\n\r\nWebSocketClient client;\r\n\r\nvoid setup() {\r\n  // Ethernet/WiFi initialization goes here ...\r\n  // ...\r\n\r\n  client.onOpen([](WebSocket \u0026ws) {\r\n    const char message[]{ \"Hello from Arduino client!\" };\r\n    ws.send(WebSocket::DataType::TEXT, message, strlen(message));\r\n  });\r\n  client.onClose([](WebSocket \u0026ws, const WebSocket::CloseCode code,\r\n                   const char *reason, uint16_t length) {\r\n    // ...\r\n  });\r\n  client.onMessage([](WebSocket \u0026ws, const WebSocket::DataType dataType,\r\n                     const char *message, uint16_t length) {\r\n    // ...\r\n  });\r\n\r\n  client.open(\"echo.websocket.org\", 80);\r\n}\r\n\r\nvoid loop() {\r\n  client.listen();\r\n}\r\n```\r\n\r\n### Chat\r\n\r\n\u003e Node.js server on Raspberry Pi (/node.js/chat.js)\r\n\r\n\u003cp align=\"center\"\u003e\r\n   \u003cimg src=https://github.com/skaarj1989/mWebSockets/blob/gh-pages/images/rpi-nodejs.png?raw=true\"\u003e\r\n\u003c/p\u003e\r\n\r\n\u003e Browser client (/node.js/chat-client.htm)\r\n\r\n\u003cp align=\"center\"\u003e\r\n   \u003cimg src=https://github.com/skaarj1989/mWebSockets/blob/gh-pages/images/browser-client.PNG?raw=true\"\u003e\r\n\u003c/p\u003e\r\n\r\n\u003e Arduino Uno client (/examples/chat/chat.ino)\r\n\r\n\u003cp align=\"center\"\u003e\r\n   \u003cimg src=https://github.com/skaarj1989/mWebSockets/blob/gh-pages/images/arduino-serial-monitor.png?raw=true\"\u003e\r\n\u003c/p\u003e\r\n\r\n\u003e More examples [here](examples)\r\n\r\n## Approx memory usage\r\n\r\n\u003e `simple-client.ino` example (without debug output, 128 bytes data buffer)\r\n\r\n### Ethernet.h (W5100 and W5500)\r\n\r\n|         Board         |   Program space    |  Dynamic memory   |\r\n| :-------------------: | :----------------: | :---------------: |\r\n|      Arduino Uno      | 24 648 bytes (76%) |  829 bytes (40%)  |\r\n|   Arduino Mega2560    | 25 640 bytes (10%) |  857 bytes (10%)  |\r\n|   Arduino Pro Mini    | 24 648 bytes (80%) |  829 bytes (40%)  |\r\n|     Arduino Zero      | 30 596 bytes (11%) | 3 056 bytes (9%)  |\r\n| Arduino Uno R4 Minima | 63 860 bytes (24%) | 3 620 bytes (11%) |\r\n\r\n### EthernetENC.h (ENC28j60)\r\n\r\n|      Board       |    Program space    |  Dynamic memory   |\r\n| :--------------: | :-----------------: | :---------------: |\r\n|   Arduino Uno    | 31 062 bytes (96%)  | 1 406 bytes (68%) |\r\n| Arduino Mega2560 | 32 074 bytes (12%)  | 1 406 bytes (17%) |\r\n| Arduino Pro Mini | 31 062 bytes (101%) | 1 406 bytes (68%) |\r\n|   Arduino Zero   | 36 796 bytes (14%)  | 3 684 bytes (11%) |\r\n\r\n### WiFi\r\n\r\n|        Board        |    Program space    |   Dynamic memory   |\r\n| :-----------------: | :-----------------: | :----------------: |\r\n|   Generic ESP8266   | 286 328 bytes (29%) | 27 356 bytes (33%) |\r\n|    WeMos D1 mini    | 286 328 bytes (27%) | 27 356 bytes (33%) |\r\n|       NodeMCU       | 286 328 bytes (27%) | 27 356 bytes (33%) |\r\n| Arduino Uno R4 WiFi | 57 596 bytes (21%)  | 4 492 bytes (13%)  |\r\n\r\n## Known issues\r\n\r\n...\r\n\r\n## License\r\n\r\n- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\r\n- [arduino-base64](https://github.com/adamvr/arduino-base64) licensed under licensed under MIT License\r\n- [arduinolibs](https://github.com/rweather/arduinolibs) licensed under the MIT\r\n- [utf8_check](https://www.cl.cam.ac.uk/~mgk25/ucs/utf8_check.c) licensed under the MIT\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskaarj1989%2Fmwebsockets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskaarj1989%2Fmwebsockets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskaarj1989%2Fmwebsockets/lists"}