Posts: 341
Threads: 130
Joined: May 2020
Reputation:
0
HI
I followed the instructions I found in the forum on how to evaluate the modem signal, I modified the user and sms (resident) scripts as recommended, now how can I read the global variable quality to be able to represent it in visual display?
is it stored in storage?
A thousand thanks
Posts: 8069
Threads: 43
Joined: Jun 2015
Reputation:
470
Posts: 341
Threads: 130
Joined: May 2020
Reputation:
0
(18.04.2024, 09:33) admin Wrote: Add grp.update like in this script (line #119): https://forum.logicmachine.net/showthrea...4#pid31874
This is my script code
I have try to log the varibale quality but log nothing ???
Code:
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
if not numbers then
require (
'user.sms' )
require (
'json' )
require (
'socket' )
numbers = {
'3332958126' }
comport =
'ttyUSB2'
doreset =
false
parser =
function (
cmd ,
sender )
local find ,
pos ,
name ,
mode ,
offset ,
value ,
dvalue ,
obj ,
message
cmd =
cmd :
trim ()
mode =
cmd :
sub (
1 ,
1 ):
upper ()
if mode ~=
'W' and mode ~=
'R' then
return
end
cmd =
cmd :
sub (
3 ):
trim ()
find =
cmd :
sub (
1 ,
1 ) ==
'"' and '"' or ' '
offset =
find ==
'"' and 1 or 0
if mode ==
'R' and find ==
' ' then
cmd =
cmd ..
' '
end
pos =
cmd :
find (
find ,
1 +
offset ,
true )
if not pos then
return
end
name =
cmd :
sub (
1 +
offset ,
pos -
offset ):
trim ()
if mode ==
'W' then
value =
cmd :
sub (
pos +
offset ):
trim ()
if #
value >
0 then
dvalue =
json.pdecode (
value )
if dvalue ~=
nil then
value =
dvalue
end
grp.write (
name ,
value )
end
else
obj =
grp.find (
name )
if not obj then
return
end
obj :
read ()
os.sleep (
1 )
value =
grp.getvalue (
name )
if value ==
nil then
return
end
if obj.name then
name =
string.format (
'%s (%s)' ,
obj.name ,
obj.address )
end
message =
string.format (
'Value of %s is %s' ,
name ,
json.encode (
value ))
modem :
sendsms (
'+' ..
sender ,
message )
end
end
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
grp.write (
'32/0/0' ,
quality )
end
csqtime =
os.time ()
handler =
function (
sms )
if table.contains (
numbers ,
sms.sender )
then
end
end
now =
os.time ()
delta =
math.abs (
now -
csqtime )
if delta >=
15 then
csqtime =
now
readcsq ()
end
udphandler =
function (
server )
local msg =
server :
receive ()
if not msg then
return
end
local sep =
msg :
find (
' ' )
if not sep then
return
end
modem :
sendsms (
msg :
sub (
1 ,
sep -
1 ),
msg :
sub (
sep +
1 ))
end
end
if modem then
if modem :
run ()
then
udphandler (
server )
else
modem :
reinit ()
end
else
modem =
AT :
init (
'/dev/' ..
comport ,
doreset )
if modem then
modem :
setsmshandler (
handler )
if pincode then
modem :
send (
'AT+CPIN=' ..
pincode )
modem :
read ()
end
modem :
send (
'AT+CMGF=0' )
modem :
send (
'AT+CNMI=1,1,0,0,0' )
modem :
send (
'AT+CSCS="GSM"' )
modem :
send (
'AT+CMGD=1,4' )
server =
socket.udp ()
server :
setsockname (
'127.0.0.1' ,
12535 )
server :
settimeout (
0.1 )
else
end
end
Posts: 8069
Threads: 43
Joined: Jun 2015
Reputation:
470
Try this:
Code:
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
if not numbers then
require (
'user.sms' )
require (
'json' )
require (
'socket' )
numbers = {
'3332958126' }
comport =
'ttyUSB2'
doreset =
false
parser =
function (
cmd ,
sender )
local find ,
pos ,
name ,
mode ,
offset ,
value ,
dvalue ,
obj ,
message
cmd =
cmd :
trim ()
mode =
cmd :
sub (
1 ,
1 ):
upper ()
if mode ~=
'W' and mode ~=
'R' then
return
end
cmd =
cmd :
sub (
3 ):
trim ()
find =
cmd :
sub (
1 ,
1 ) ==
'"' and '"' or ' '
offset =
find ==
'"' and 1 or 0
if mode ==
'R' and find ==
' ' then
cmd =
cmd ..
' '
end
pos =
cmd :
find (
find ,
1 +
offset ,
true )
if not pos then
return
end
name =
cmd :
sub (
1 +
offset ,
pos -
offset ):
trim ()
if mode ==
'W' then
value =
cmd :
sub (
pos +
offset ):
trim ()
if #
value >
0 then
dvalue =
json.pdecode (
value )
if dvalue ~=
nil then
value =
dvalue
end
grp.write (
name ,
value )
end
else
obj =
grp.find (
name )
if not obj then
return
end
obj :
read ()
os.sleep (
1 )
value =
grp.getvalue (
name )
if value ==
nil then
return
end
if obj.name then
name =
string.format (
'%s (%s)' ,
obj.name ,
obj.address )
end
message =
string.format (
'Value of %s is %s' ,
name ,
json.encode (
value ))
modem :
sendsms (
'+' ..
sender ,
message )
end
end
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
grp.write (
'32/0/0' ,
quality )
end
csqtime =
os.time ()
handler =
function (
sms )
if table.contains (
numbers ,
sms.sender )
then
end
end
udphandler =
function (
server )
local msg =
server :
receive ()
if not msg then
return
end
local sep =
msg :
find (
' ' )
if not sep then
return
end
modem :
sendsms (
msg :
sub (
1 ,
sep -
1 ),
msg :
sub (
sep +
1 ))
end
end
if modem then
if modem :
run ()
then
udphandler (
server )
now =
os.time ()
delta =
math.abs (
now -
csqtime )
if delta >=
15 then
csqtime =
now
readcsq ()
end
else
modem :
reinit ()
end
else
modem =
AT :
init (
'/dev/' ..
comport ,
doreset )
if modem then
modem :
setsmshandler (
handler )
if pincode then
modem :
send (
'AT+CPIN=' ..
pincode )
modem :
read ()
end
modem :
send (
'AT+CMGF=0' )
modem :
send (
'AT+CNMI=1,1,0,0,0' )
modem :
send (
'AT+CSCS="GSM"' )
modem :
send (
'AT+CMGD=1,4' )
server =
socket.udp ()
server :
setsockname (
'127.0.0.1' ,
12535 )
server :
settimeout (
0.1 )
else
end
end
Posts: 341
Threads: 130
Joined: May 2020
Reputation:
0
nothing return nil from rssi
but not possible message sms work fine
Posts: 8069
Threads: 43
Joined: Jun 2015
Reputation:
470
Log the raw reply (around line 97):
Code:
1 2
local res ,
err ,
reply =
modem :
send (
'AT+CSQ' )
log (
res ,
err ,
reply )
Posts: 341
Threads: 130
Joined: May 2020
Reputation:
0
(18.04.2024, 11:11) admin Wrote: Log the raw reply (around line 97):
Code:
1 2
local res ,
err ,
reply =
modem :
send (
'AT+CSQ' )
log (
res ,
err ,
reply )
Yes found problem in this line
as always thank you very much