2022-2-23-EC-01G

发布时间 2023-09-17 20:47:14作者: Yecgaa1
layout: post
title: EC-01G模块
categories: 日志
tags: 
    - 比赛 
    - 大二
BGImage: 'https://github.xutongxin.me/https://raw.githubusercontent.com/xutongxin1/PictureBed/master/img0/20220310123346.png'
jekyll-theme-WuK:
    musicid: '34367899'

安信可EC-01G NB-IoT模块

9600波特率!!!

115200会看到boot什么的字眼,但是AT不响应的

烧录:

https://aithinker.blog.csdn.net/article/details/120757243

上网:

https://aithinker.blog.csdn.net/article/details/120765734

tcp传数据

先鉴权(产品!ID,key(自定义字符串),讲用的Lua的脚本),然后发数据,由Lua脚本解析

例子:https://blog.csdn.net/nkd50000/article/details/104745660

EC-01G要把字符转化为16进制才能发

所以脚本也改过了,否则会直接存入16进制的数字到数据点里

function string.fromhex(str)
        return (str:gsub('..', function (cc)
            return string.char(tonumber(cc, 16))
        end))
end

function add_val(t, i, a, v, c)
    if type(t)~="table" then
            return false
    elseif type(i)~="string" then
            return false
    elseif type(a)~="number" then
            return false
    else
            local o = type(v)
            if o~="boolean" and o~="number" and o~="string" and o~="table" then
                    return false
            end
            
            if o~="number" then
                v=string.fromhex(tostring(v))
            end

            local n = {i=i,v=to_hex(v)}
--                n.v = n.v .. "("..o..")"
            if a~=0 and a~=nil then
                    n["a"]=a
            end
            if c~=nil then
                    n["c"]=c
            end

            -- list push_back --
            if t.h==nil then
                    t.h={nil,n}
                    t.t=t.h
            else
                    t.t[1]={nil,n}
                    t.t=t.t[1]
            end
    end

    return true
end