Fork me on GitHub
WiFiMCU概要

WiFiMCU基于庆科最新WiFi模块EMW3165。直接运行Lua脚本,操作硬件资源,实现IOT快速开发。 EMW3165 是由上海庆科信息技术有限公司开发的一款低功耗嵌入式WIFI 模块。它集成了 一个无线射频芯片和一个型号为STM32F411CE 的Cortex-M4 微控制器,内置了独一无二的 “self-hosted” WIFI 网络函数库以及应用组件。此外,还提供2M 字节的片外flash、512K 字节的片内flash、128K 字节的RAM 以及丰富的外设资源。

WiFiMCU的设计和实现都借鉴了NodeMCU开源项目,在此感谢。

功能特点
脚本交互,软硬件开源,接口丰富,低成本,30秒快速IOT

比Arduino更简单的交互:通过UART/Telnet交互,屏蔽MCU寄存器设置,脚本操作硬件,无需编译直接运行;

硬件可靠,接口丰富:STM32 MCU品质,可外接多种类型传感器、显示器和执行器;

用Lua编写IOT应用:30秒实现WiFi模块连接无线路由器,发送数据到远程服务器;提供丰富的WiFi和网络操作函数,实现复杂网络应用

硬件特点

Cortex-M4微控制器
STM32F411CE
100MHz的Cortex-M4内核
2M字节片外SPI flash和512K字节片内flash
128K字节RAM
丰富外设
22个GPIO复用管脚
3个UART
ADC/SPI/I2C/USB
SWD调试接口
PWM
博通IEEE 802.11 b/g/n 射频芯片
支持802.11 b/g/n
WEP,WPA/WPA2,PSK/Enterprise
16.5dBm@11b,14.5dBm@11g,13.5dBm@11n
接收灵敏度:-87 dBm
Station,Soft AP以及Station+Soft AP共存
CE,FCC 适用
工作温度:-30℃ ~ +85℃
软件特点

封装标准Lua解释器、串口交互、WiFi和Net模块、文件系统、外设模块

调试工具

串口工具(putty、Tera Term Pro等),串口参数:115200,n,8,1

启动画面

_     _   _____ _ _ _   __  _    __
' )   /     /  '' ) ) ) /  )' )  /
 / / / o ,-/-, o / / / /     /  /
(_(_/ <_(_/   <_/ ' (_(__/  (__/
@_@Design_by_doit_based_on_Lua_5.1.4

cannot open init.lua
>

案例

建立热点
>cfg={ssid='Doit_3165',pwd=''}
>wifi.startap(cfg)
WebServer
>cfg={ssid='Doit_3165',pwd=''} wifi.startap(cfg)
>function listen_cb(c,ip,port)
    c:on("disconnect",function(c) end)
    c:on("sent",function(con) end)
    c:on("receive",function(c,pl)
    c:send([[HTTP/1.1 200 OK
Server: WiFiMCU
Content-Type:text/html
Content-Length: 19
Connection: close]]..'\r\n\r\n'..[[
Welcome to WiFiMCU!]]) end)
end
>sk=net.new(net.TCP,net.SERVER) sk:listen(80,listen_cb)
连接无线路由器
>print(wifi.sta.getip())
0.0.0.0
>cfg={ssid="Doit",pwd="123456789"} wifi.startsta(cfg)
>print(wifi.sta.getip())
192.168.1.112
连接到云端
>sk2=net.new(net.TCP,net.CLIENT)
>sk2:on("connect",function(c) print("client connected") c:send("From WiFiMCU") end)
>sk2:on("receive",function(c,pl) print("receive data:"..pl) c:send("Hello WiFiMCU")end)
>sk2:connect(6579,"115.29.109.104")
操作GPIO
>gpio.mode(6,gpio.INPUT)
>print(gpio.read(6))
0
>print(gpio.read(6))
1
>gpio.mode(6,gpio.OUTPUT)
>gpio.write(6,gpio.HIGH)
定时操作
> function tmr_cb() print('tmr1 is called') end
> tmr.start(1,1000,tmr_cb)
> tmr1 is called
文件读写
> file.open ("test.lua","w+")
> file.write("this is a test")
> file.close()
> file.open ("test.lua","r")
> data=file.read()
> print(data)
this is a test
> file.close()
>
自启动
>file.open ("init.lua","w+")
>file.write("print('Hello world!')")
>file.close()
>mcu.reboot()