### Create a Simple HTTP Server Source: https://nodemcu.readthedocs.io This snippet demonstrates how to create a basic TCP server that listens on port 80 and responds to incoming HTTP requests with a 'Hello, NodeMCU.' message. ```lua -- a simple HTTP server srv = net.createServer(net.TCP) srv:listen(80, function(conn) conn:on("receive", function(sck, payload) print(payload) sck:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n

Hello, NodeMCU.

") end) conn:on("sent", function(sck) sck:close() end) end) ``` -------------------------------- ### Manipulate Hardware GPIO Pins Source: https://nodemcu.readthedocs.io Demonstrates basic hardware manipulation by configuring a GPIO pin as an output, setting its state to high, and then reading its current state. ```lua -- manipulate hardware like with Arduino pin = 1 gpio.mode(pin, gpio.OUTPUT) gpio.write(pin, gpio.HIGH) print(gpio.read(pin)) ``` -------------------------------- ### Connect to WiFi Access Point Source: https://nodemcu.readthedocs.io Configures the NodeMCU to connect to a WiFi access point using the provided SSID and password. The configuration is not saved to flash. ```lua -- connect to WiFi access point (DO NOT save config to flash) wifi.setmode(wifi.STATION) station_cfg={} station_cfg.ssid = "SSID" station_cfg.pwd = "password" station_cfg.save = false wifi.sta.config(station_cfg) ``` -------------------------------- ### Register WiFi Event Callbacks Source: https://nodemcu.readthedocs.io Registers event callbacks for WiFi events, specifically for when the station interface connects to an access point. It prints connection details upon successful connection. ```lua -- register event callbacks for WiFi events wifi.eventmon.register(wifi.eventmon.STA_CONNECTED, function(T) print("\n\tSTA - CONNECTED".."\n\tSSID: "..T.SSID.."\n\tBSSID: "..T.BSSID.."\n\tChannel: "..T.channel) end) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.