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
mpu-6050 options encoder dc-dc lcd ssd1331 css tim uart bmp280 i2c remap dma motor dht11 avr pwm mongodb sensors flash rtc sms solar websocket mpu-9250 adc battery led timer web java-script piezo stm32 hih-4000 docker esp8266 wifi usart rfid exti bluetooth foc st-link ssd1306 displays flask usb ngnix html bme280 gpio max1674 brushless git raspberry-pi programmator watchdog bldc 3d-printer barometer eeprom bkp servo examples nvic meteo ethernet python soldering mpx4115a atmega nodemcu books rs-232 eb-500 pmsm capture smd gps
Архіви