Wi-Fi - UART переходник на ESP8266
Wi-Fi - UART переходник на ESP8266 Сделан на модуле ESP-12.
Заливаем Framework NodeMCU в модуль. Скачать можно здесь: https://github.com/avislab/NodeMCUExamples/tree/master/WeatherStation/firmware
Затем в файловую систему NodeMCU заливаем два файла:
init.lua:
print ( "Waiting ...")
tmr.register (0, 10000, tmr.ALARM_SINGLE, function (t) tmr.unregister (0); print ( "Starting ..."); dofile ( "wifiuart.lua") end)
tmr.start (0)
wifiuart.lua:
--Ports setting
TCP_PORT = 333
uart.setup(0, 9600, 8, uart.PARITY_NONE, uart.STOPBITS_1, 1)
--WiFi Settup
wifi.setmode(wifi.STATION)
local cfg={}
cfg.ssid="WiFi"
cfg.pwd="password"
cfg = nil
--WiFi AP Settup
--wifi.setmode(wifi.STATIONAP)
--cfg={}
--cfg.ssid="ESPWIFI"
--cfg.pwd="1234567890"
--wifi.ap.config(cfg)
--cfg = nil
collectgarbage()
-- Close old Server
if sv then
sv:close()
end
--Create Server
sv=net.createServer(net.TCP)
connection=nil
function receiver(sck, data)
-- Print received data
uart.write(0, data)
end
function disconnect(sck)
connection=nil
end
if sv then
sv:listen(TCP_PORT, function(conn)
if connection == nil then
conn:send("Hello!")
conn:on("receive", receiver)
conn:on("disconnection", disconnect)
connection = conn
else
conn:send("Sorry just one connection allowed.\r\n\r\n")
conn:close()
end
end)
end
-- UART
uart.on("data", "\r",
function(data)
connection:send(data.."\n")
end, 0)
Настройки Wi-Fi:
cfg.ssid="WiFi"
cfg.pwd="password"
IP выдает WiFi роутер.
Настройки Порта для подключения:
TCP_PORT = 333
Настройки UART порта:
uart.setup(0, 9600, 8, uart.PARITY_NONE, uart.STOPBITS_1, 1)
Tags
timer meteo pwm capture dma smd brushless sensors 3d-printer examples sms git st-link adc rfid exti web bme280 bmp280 gps options barometer battery lcd dht11 hih-4000 atmega dc-dc piezo solar bluetooth displays mpx4115a bldc websocket eb-500 motor raspberry-pi usb rtc usart max1674 avr soldering mongodb esp8266 programmator mpu-6050 remap rs-232 pmsm bkp gpio i2c eeprom encoder stm32 css docker flask nodemcu ssd1331 tim flash servo nvic ssd1306 mpu-9250 ethernet led foc python ngnix watchdog books html java-script wifi uart
Архіви