05.01.2023, 13:16
1. Modify the user library send function so it returns the command reply/result:
2. Add before handler = function(sms) in the resident script:
3. Add before udphandler(server) in the resident script:
This will read the signal quality every 15 seconds and will set global variable quality that you can use in the SMS reply message.
Code:
-- send command to terminal
function AT:send(cmd)
local res, err = self.port:write(cmd .. '\r\n')
local reply
-- write ok, get local echo
if res then
res, err = self:readuntil(cmd)
reply = self:read()
end
return res, err, reply
end
2. Add before handler = function(sms) in the resident script:
Code:
readcsq = function()
local res, err, reply = modem:send('AT+CSQ')
local rssi
if reply then
rssi = reply:match('%+CSQ:%s+(%d+),(%d+)')
end
rssi = tonumber(rssi) or 0
if 2 <= rssi and rssi <= 9 then
quality = 'marginal'
elseif 10 <= rssi and rssi <= 14 then
quality = 'ok'
elseif 15 <= rssi and rssi <= 19 then
quality = 'good'
elseif 20 <= rssi and rssi <= 30 then
quality = 'excellent'
else
quality = 'unknown'
end
end
csqtime = os.time()
3. Add before udphandler(server) in the resident script:
Code:
now = os.time()
delta = math.abs(now - csqtime)
if delta >= 15 then
csqtime = now
readcsq()
end
This will read the signal quality every 15 seconds and will set global variable quality that you can use in the SMS reply message.