一节1.5v电池供电鼠标改装锂电池供电
原生
用一节五号电池1.5v,经过鼠标内部dcdc升压到3v,方案一是用ldo将3.7v降压成3v直接接在dcdc后端,可以工作,但过一会儿就不工作了,不知道什么原因,方案二使用一颗led发光管串联降压直接接到供电焊点,3.7-1.8约等于2v经过原生dcdc降压后供鼠标工作,连续测试几天没问题,lex灯会在移动鼠标时闪烁,鼠标耗电量直接可视
原生
用一节五号电池1.5v,经过鼠标内部dcdc升压到3v,方案一是用ldo将3.7v降压成3v直接接在dcdc后端,可以工作,但过一会儿就不工作了,不知道什么原因,方案二使用一颗led发光管串联降压直接接到供电焊点,3.7-1.8约等于2v经过原生dcdc降压后供鼠标工作,连续测试几天没问题,lex灯会在移动鼠标时闪烁,鼠标耗电量直接可视
module(...,package.seeall)
require"http"
require"misc"
require"mqtt"
require"mqttOutMsg"
require"mqttInMsg"
local torigin =
{
SERVERIP = "182.92.223.22",
PORT = "1883",
DEVICEID = "7735d490-4231-11ec-8470-1bf471b2fd10",
TOKEN = "pWIUd6QEfKl0YUqIiDFj",
}
local function writevalw(filename,value)
local filehandle = io.open(filename,"w")
if filehandle then
filehandle:write(value)
filehandle:close()
else
print("文件不存在或文件输入格式不正确")
end
end
local function deletefile(filename)
os.remove(filename)
end
newfenv = {
print = function( ... )
print(arg[1].."test")
end
}
--读取
local function run_file()
local line =io.readFile("/user_main.lua")
xpcall(function()
local f = loadstring(line)
setfenv(f, newfenv)
f()
end,
function()
print(debug.traceback())
end
)
end
local function cbFnc(result,prompt,head,body)
log.info("testHttp.cbFnc",result,prompt)
if result and head then
for k,v in pairs(head) do
log.info("testHttp.cbFnc",k..": "..v)
end
end
if result and body then
log.info("testHttp.cbFnc","bodyLen="..body:len())
log.info("testHttp.cbFnc",body)
writevalw("/user_main.lua",body)
sys.wait(1000)
sys.restart("下载成功软件重启")
end
end
sys.taskInit(function()
local retryConnectCnt = 0
while not socket.isReady() do
retryConnectCnt=retryConnectCnt+1
sys.wait(1000)
log.info("重连次数",retryConnectCnt)
if retryConnectCnt>20 then sys.restart("程序超时软件重启") end
end
log.info("连接成功")
local jsondata = json.encode(torigin)
writevalw("/user_config.txt",jsondata)
log.info("更新配置")
setmetatable(newfenv,{__index = _G})
run_file()
end)
-- 测试MQTT的任务代码
sys.taskInit(function()
while not socket.isReady() do sys.wait(1000) end
log.info("连接上网络")
sys.wait(2000)
local mqttc = mqtt.client(misc.getImei(),300,torigin["TOKEN"])
log.info("连接上服务器ing")
while not mqttc:connect(torigin['SERVERIP'], 1883) do sys.wait(2000) end
log.info("连接上服务器")
if mqttc:subscribe("v1/devices/me/rpc/request/+") then log.info("订阅成功") end
local msg='{"firmware_type":"jd-iot","firmware_version": "68"}'
log.info("sendMsg",msg)
mqttc:publish("v1/devices/me/attributes",msg)
while true do
result,data = mqttc:receive(5000,"APP_SOCKET_SEND_DATA")
if result then
log.info("mqttInMsg.topic",data.topic)
log.info("mqttInMsg.payload",data.payload)
local cfgdata,result,errinfo = json.decode(data.payload)
url=string.gsub(cfgdata['params']['pathWay'],"https://","")
log.info("mqttInMsg.url",url)
http.request("GET",url,nil,nil,nil,nil,cbFnc)
end
end
mqttc:disconnect()
end)
module(...,package.seeall)
require"utils"
require"pm"
require"sys"
require"mqtt"
require"mqttOutMsg"
require"mqttInMsg"
require "misc"
local UART_ID = 1
local mqttc22
local torigin =
{
SERVERIP = "182.92.223.22",
PORT = "1883",
DEVICEID = "7735d490-4231-11ec-8470-1bf471b2fd10",
TOKEN = "pWIUd6QEfKl0YUqIiDFj",
}
local function writevalw(filename,value)
local filehandle = io.open(filename,"w")
if filehandle then
filehandle:write(value)
filehandle:close()
else
print("文件不存在或文件输入格式不正确")
end
end
local function deletefile(filename)
os.remove(filename)
end
function split(input, delimiter,index)
input = tostring(input)
local pos = 0
local i = 0
for st,sp in function() return string.find(input, delimiter, pos, true) end do
if (i==index) then return string.sub(input, pos, st - 1) end
i= i + 1
pos = sp + 1
end
if i==index then return string.sub(input, pos) end
return nil
end
local function save()
local jsondata = json.encode(torigin)
writevalw("/user_config.txt",jsondata)
log.info("save", "ok")
end
local function read()
local USER_CONFIG=io.readFile("/user_config.txt")
local cfgdata,result,errinfo = json.decode(USER_CONFIG)
torigin=cfgdata
log.info("save", "ok")
end
local function proc(data)
if not data or string.len(data) == 0 then return end
log.info("testUart.read",data)
local a=split(data, " ",0)
local b=split(data, " ",1)
local c=split(data, " ",2)
if(a=="set")
then
if(b=="serverip")then torigin["SERVERIP"]=c end
if(b=="deviceid")then torigin["DEVICEID"]=c end
if(b=="token")then torigin["TOKEN"]=c end
uart_write(data)
end
if(a=="config")
then
if(b=="save") then save() uart_write("save ok") end
if(b=="read") then read() uart_write("read ok") end
end
if(a=="print")
then
local jsondata = json.encode(torigin)
log.info("jsondata", jsondata)
end
log.info(a,b,c)
end
local function read()
local data = ""
while true do
data = uart.read(UART_ID,"*l")
if not data or string.len(data) == 0 then break end
proc(data)
end
end
function uart_write(s)
log.info("testUart.write",s)
uart.write(UART_ID,s.."\r\n")
end
local function writeOk()
log.info("testUart.writeOk")
end
read()
pm.wake("testUart")
local port_mode=0-- 这里改成实际读取的pin脚值
if(port_mode==0)
then
uart.on(UART_ID,"receive",read)
uart.on(UART_ID,"sent",writeOk)
uart.setup(UART_ID,115200,8,uart.PAR_NONE,uart.STOP_1)
end
local revice_data=nil
local function read2()
local data = ""
while true do
data = uart.read(UART_ID,"*l")
if not data or string.len(data) == 0 then break end
log.info("tag", data)
revice_data=data
end
end
if(port_mode==1)
then
sys.taskInit(function()
while not socket.isReady() do sys.wait(1000) log.info(".") end
log.info("连接上网络")
sys.wait(2000)
mqttc2 = mqtt.client(misc.getImei(),300,torigin["TOKEN"])
log.info("连接上服务器ing")
while not mqttc2:connect(torigin['SERVERIP'], 1883) do sys.wait(2000) end
log.info("连接上服务器")
if mqttc2:subscribe("v1/devices/me/rpc/request/+") then log.info("订阅成功") end
uart.on(UART_ID,"receive",read2)
uart.on(UART_ID,"sent",writeOk)
uart.setup(UART_ID,115200,8,uart.PAR_NONE,uart.STOP_1)
while true do
result,data = mqttc2:receive(500,"APP_SOCKET_SEND_DATA")
if result then
log.info("mqttInMsg.topic",data.topic)
log.info("mqttInMsg.payload",data.payload)
uart_write(data.payload)
end
if(revice_data)then
mqttc2:publish("v1/devices/me/telemetry",revice_data)
revice_data=nil
end
end
mqttc2:disconnect()
end)
end
尝试 ssh -p 29418 @gerrit......com. 如果看到 下面文字表示成功。
Welcome to Gerrit Code Review **
Hi xxx, you have successfully connected over SSH.
Unfortunately, interactive shells are disabled.
To clone a hosted Git repository, use:
可能遇到的问题。