2021年11月

一节1.5v电池供电鼠标改装锂电池供电

原生
用一节五号电池1.5v,经过鼠标内部dcdc升压到3v,方案一是用ldo将3.7v降压成3v直接接在dcdc后端,可以工作,但过一会儿就不工作了,不知道什么原因,方案二使用一颗led发光管串联降压直接接到供电焊点,3.7-1.8约等于2v经过原生dcdc降压后供鼠标工作,连续测试几天没问题,lex灯会在移动鼠标时闪烁,鼠标耗电量直接可视IMG_20211114_214156.jpg

IMG_20211114_210304.jpg

IMG_20211114_205841.jpg

IMG_20211114_210300.jpg

lua 固件更新部分 利用lua 虚拟机加载

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)

lua mqtt透传部分

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

gerrit 认证总是提示输入密码的问题解决

  1. 首先登陆gerrit 注册(激活)自己的账号。
  2. 生成SSH KEY。 run ssh-keygen -t dsa -b 1024 。 提示Enter file in which to save the key: 输入任意一文件名(例如id_dsa)。 提示Enter file in which to save the key, 连续输入两次回车。 ls /home 或者 /.ssh 。 可以发现俩文件。 id_dsa 和 id_dsa.pub. 前者是密钥,后者是公钥.
  3. 添加public key到gerrit。 打开id_isa.pub, 复制内容。进入 gerrit->settings->SSH Publick key->add key, 粘贴公钥内容。点击add。
  4. 修改 id_dsa id_dsa.pub .ssh 的权限. chmod 700
  5. 尝试 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:
    可能遇到的问题。

  6. 提示 could not create directory .ssh... 原因可能是你的cygwin 环境没有初始化。 从开始菜单打开cygwin, 会看到会有一些初始化的工作。
  7. 如果遇到Permission denied (publickey). 那可能是你没有添加密钥到ssh-agent. 尝试ssh-add id_dsa. 在add的时候如果遇到Could not open a connection to your authentication agent. 尝试ssh-agent bash. 然后再 ssh-add. add 成功后再run ssh -p 29418 @gerrit......com 应该就可以看到 welcome的提示了。
    3、测试了如上方法都不行依然提示 权限错误或者其他错误,看到协议使用ssh 不妨想到 ssh 终端连接 两个协议应该一样,便 使用xshell 使用证书方式连接 果不其然 可以连接上微信截图_20211112105715.png
    但是 。。。无法克隆 遂 再找到sourcetree 添加ppk 证书 再在 gerrit 服务器提交 微信截图_20211112105825.png
    ok 可以下拉了,但是无法上传 应该是审核问题