24.05.2024, 09:27
Connect script fails because of "NO CARRIER" message meaning that there's no mobile connection.
Run this updated script and post what you get in Logs:
Run this updated script and post what you get in Logs:
Code:
io.writefile('/sys/class/gpio/export', 8)
io.writefile('/sys/class/gpio/export', 71)
io.writefile('/sys/class/gpio/gpio8/direction', 'high')
os.sleep(1)
io.writefile('/sys/class/gpio/gpio8/direction', 'low')
io.writefile('/sys/class/gpio/gpio71/direction', 'high')
tty1 = '/dev/ttyACM3'
tty2 = '/dev/ttyUSB2'
for i = 1, 20 do
os.sleep(1)
if io.exists(tty1) then
tty = tty1
break
elseif io.exists(tty2) then
tty = tty2
break
end
end
if not tty then
log('init failed')
return
end
buf = {}
function send(cmd, timeout)
port:flush()
port:write(cmd .. '\r\n')
local res, err = port:read(1000, timeout or 1)
return res, err
end
function sendlog(cmd, timeout)
local res = send(cmd, timeout)
if res then
buf[ #buf + 1 ] = res
end
return res
end
port = require('serial').open(tty)
log('open port', tty)
for i = 1, 20 do
res = send('AT')
if res then
break
end
end
if not res then
log('no response')
return
end
sendlog('AT&F', 10) -- reset settings
sendlog('ATE1') -- echo enabled
function readstatus()
local data, res, simok, network
data = sendlog('AT+CSQ')
if data then
res = data:match('+CSQ: (%d+)')
res = tonumber(res)
if res then
log('Signal: ' .. tostring(res))
else
log('Signal: no response')
end
else
log('Signal: no data from port')
end
data = sendlog('AT+CPIN?') or ''
if data:find('CME ERROR') then
log('SIM: not found')
elseif data:find('+CPIN: READY') then
log('SIM: OK')
simok = true
else
log('SIM: unknown')
end
data = sendlog('AT+COPS?')
if data then
res = data:match('+COPS: %d+,%d+,"(.*)",%d+')
if res then
log('Network: ' .. tostring(res))
network = res
else
log('Network: no info')
end
else
log('Network: no data from port')
end
return simok and network
end
for i = 1, 20 do
if readstatus() then
break
end
end
res = table.concat(buf)
log(res)