kindle
一起的对比照https://gitee.com/openLuat/LuatOS/tree/master/script/turnkey/eink-calendar
https://gitee.com/dreamcmi/LuatOS-ESP32/blob/master/doc/VDD_SPI_AS_GPIO.md
https://wiki.luatos.com/peripherals/eink_1.54/software.html#id4
https://api.luatos.org/#eink
https://tianqiapi.com/
感兴趣的可以自己制作:在合宙官网购买一块ESP32C3开发板+1.54电子墨水屏即可制作。成本:
9.9
+16.8
LuatOS工具:
https://wiki.luatos.com/pages/tools.html
GPIO 1
解锁依赖
Python
,需要电脑安装了Python。
COM13
对应的是串口端口号)espefuse.py -p COM13 burn_efuse VDD_SPI_AS_GPIO 1
代码中需要自己添加的信息有3处如下:
local wifiName,wifiPassword = "你的2.4gwifi","wifi密码"
local location = "你的属地代码"
local appid,appsecret = "api的id","api的密钥"
eink.setWin(200, 200, 2)--0代表不旋转,1,代表选择90度,2,代表选择180度
基于VSCode平台,使用
luatIDE
编译
PROJECT = "wifidemo"
VERSION = "1.0.0"
--测试支持硬件:ESP32C3
--测试固件版本:LuatOS-SoC_V0003_ESP32C3.soc
local sys = require "sys"
--需要自行填写的东西
--wifi信息
local wifiName,wifiPassword = "你的2.4gwifi","wifi密码"
--地区id,请前往https://api.luatos.org/luatos-calendar/v1/check-city/ 查询自己所在位置的id
local location = "你的属地代码"
--天气接口信息,需要自己申请,具体参数请参考https://api.luatos.org/ 页面上的描述
local appid,appsecret = "api的id","api的密钥"
local function connectWifi()
log.info("wlan", "wlan_init:", wlan.init())
wlan.setMode(wlan.STATION)
wlan.connect(wifiName,wifiPassword)
-- 等待连上路由,此时还没获取到ip
result, _ = sys.waitUntil("WLAN_STA_CONNECTED")
log.info("wlan", "WLAN_STA_CONNECTED", result)
-- 等到成功获取ip就代表连上局域网了
result, data = sys.waitUntil("IP_READY")
log.info("wlan", "IP_READY", result, data)
end
local function requestHttp()
local rd = {}
local httpc = esphttp.init(esphttp.GET, "http://apicn.luatos.org:23328/luatos-calendar/v1?mac=111&battery=10&location="..location.."&appid="..appid.."&appsecret="..appsecret)
if httpc then
local ok, err = esphttp.perform(httpc, true)
if ok then
while 1 do
local result, c, ret, data = sys.waitUntil("ESPHTTP_EVT", 20000)
--log.info("httpc", result, c, ret)
if c == httpc then
if esphttp.is_done(httpc, ret) then
break
end
if ret == esphttp.EVENT_ON_DATA and esphttp.status_code(httpc) == 200 then
table.insert(rd,data)
end
end
end
else
log.warn("esphttp", "bad perform", err)
end
esphttp.cleanup(httpc)
if ok then
return table.concat(rd)
end
end
end
function refresh()
log.info("refresh","start!")
local data
for i=1,5 do--重试最多五次
data = requestHttp()
if #data > 100 then
break
end
log.info("load fail","retry!")
end
if #data < 100 then
log.info("load fail","exit!")
return
end
eink.model(eink.MODEL_1in54)
log.info("eink.setup",eink.setup(0, 2,11,10,6,7))
eink.setWin(200, 200, 2)
eink.clear(1)
log.info("eink", "end setup")
eink.drawXbm(0, 0, 200, 200, data)
-- 刷屏幕
eink.show()
eink.sleep()
log.info("refresh","done")
end
sys.taskInit(function()
--先连wifi
connectWifi()
while true do
refresh()
sys.wait(3600*1000)--一小时刷新一次吧
end
end)
-- 用户代码已结束---------------------------------------------
-- 结尾总是这一句
sys.run()
-- sys.run()之后后面不要加任何语句!!!!!