Air720搭配Air530实现4G+GPS定位

硬件准备

线路连接

Air530开发板有5条线, 除PPS外均需要连接到Air720, 具体颜色可能不一样,仅供参考

Air530 Air720 颜色
VCC 4V
GND GND
TX U2_RXD
RX U2_TXD

实际连接图如下

Lua代码

从LuaTools的LuaTools\script\script_LuaTask\lib拷贝gps.lua/agps.lua/gpsv2.lua

在调用了gps或gpsv2之前,提示两个点:

例如

1
2
3
4
-- 老的gps库
gps.setUart(2, 9600,8,uart.PAR_NONE,uart.STOP_1)
-- 新版的gps库
gpsv2.open(2, 9600, 2, 5)

完整测试代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
--必须在这个位置定义PROJECT和VERSION变量
--PROJECT:ascii string类型,可以随便定义,只要不使用,就行
--VERSION:ascii string类型,如果使用Luat物联云平台固件升级的功能,必须按照"X.X.X"定义,X表示1位数字;否则可随便定义
PROJECT = "Air720_GPS"
VERSION = "2.0.0"
PRODUCT_KEY = "v32xEAKsGTIEQxtqgwCldp5aPlcnPs3K"

--加载日志功能模块,并且设置日志输出等级
--如果关闭调用log模块接口输出的日志,等级设置为log.LOG_SILENT即可
require "log"
LOG_LEVEL = log.LOGLEVEL_TRACE

require "sys"

require "net"
--每1分钟查询一次GSM信号强度
--每1分钟查询一次基站信息
net.startQueryAll(60000, 60000)

-- 两行代码二选一,测试用
gps_lib = "gps" -- gps 经典gps库
--gps_lib = "gpsv2" -- gpsv2 新版gps库
if gps_lib == "gps" then
require"gps"
require"agps"
local function printGps()
if gps.isOpen() then
local tLocation = gps.getLocation()
local speed = gps.getSpeed()
log.info("testGps.printGps",
gps.isOpen(),gps.isFix(),
tLocation.lngType,tLocation.lng,tLocation.latType,tLocation.lat,
gps.getAltitude(),
speed,
gps.getCourse(),
gps.getViewedSateCnt(),
gps.getUsedSateCnt())
end
end
--gps.setNmeaMode(2,nmeaCb)
gps.setUart(2, 9600,8,uart.PAR_NONE,uart.STOP_1)
gps.open(gps.DEFAULT,{tag="TEST1"})
sys.timerLoopStart(printGps,2000)
else
require "gpsv2"
sys.taskInit(function(...)
gpsv2.open(2, 9600, 2, 5)
while true do
log.info("testGps isFix:", gpsv2.isFix())
log.info("testGps lng,lat:", gpsv2.getIntLocation())
log.info("testGps message:", gpsv2.getAltitude(), gpsv2.getSpeed(),
gpsv2.getAzimuth(), gpsv2.getUsedSateCnt(), gpsv2.getViewedSateCnt())
sys.wait(1000)
end
end)
end

--启动系统框架
sys.init(0, 0)
sys.run()

上次更新 2021-01-28