Giter Club home page Giter Club logo

esp8266-websocket-server's Introduction

esp8266-websocket-server

A somewhat limited use Lua websocket server for use on ESP8266 with a small memory footprint.

This webserver supports parameterless GET request and websockets. The intention is that webpages set up websockets for all communication. In order to reduce the memory footprint, this webserver has been made very simple. As a result, error codes returned are very limited. NOTE: The webserver currently does not explicitly use file handles. You should be careful if you use file IO in the websocket command scripts.

Example Usage

Server Initialization

function websocketOnRxCallback(conn, message)
	print("Received", message)
end

function websocketOnConnectCallback(conn)
	print("Connect")
end

function websocketOnCloseCallback(conn)
	print("Close")
end

local websocketCallbacks = {onConnect=websocketOnConnectCallback, onReceive=websocketOnRxCallback, onClose=websocketOnCloseCallback}
loadfile("WebsocketServer.lua")(websocketCallbacks)

Server Customization

This webserver supports four parameters which, if not defined or defined to nil, will take default values.

  1. websocketCallbacks: Callbacks table. onConnect, onReceive, and onClose are the relavent keys. See the example above for usage. Each can be nil.
  2. connTimeout: Number of seconds without any communication before the server drops the connection. Defaults to 5.
  3. restrictedFiles: A list of files which cannot be retrieved by a GET request. Note that .lua and .lc may not be retrieved by a GET request. Defaults to no restrictions.
  4. fileTXBufferSize: The max number of bytes sent at a time as a response to a GET request. Default 1024.
  5. contentTypeLookup: A table indicating the content type for each type of file that can be loaded by a GET request. Default {css="text/css", ico = "image/x-icon", html = "text/html; charset=utf-8", js = "application/javascript"}

esp8266-websocket-server's People

Watchers

 avatar  avatar

Forkers

mobedu bazooka07

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.