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