Posts: 367
Threads: 83
Joined: Jun 2017
Reputation:
8
Hi,
here is SMS message possibility describe, and latest CSQ (signal level was added):
https://forum.logicmachine.net/showthrea...hlight=CSQ
Can we somehow add
ATD modem command (
call to number ) to modem library?
SMS/Telegram/E-mail is not always take attention when we are busy, but if we can initiate call to showed in script number and enter how many rings can be done - such way can be used for security or fire alarm notification.
Info found about AT commands:
https://m2msupport.net/m2msupport/voice-...oice-call/
I think to user.sms library we need to add something like this - very simple
call to number command:
function call(number)
cmd = string.format('ATD', number)
send(cmd)
sleep(8)
send('ATH')
end
but where and how do it correctly with line/answer check I still not experienced to do
Error I have:
User library sms:472: attempt to call global 'send' (a nil value)
stack traceback:
User library sms:472: in function 'call'
Alex
Posts: 8097
Threads: 43
Joined: Jun 2015
Reputation:
471
Try this (not tested):
Code:
1 2 3 4 5
function AT :
call (
number )
self :
send (
'ATD' ..
number ..
';' )
os.sleep (
8 )
self :
send (
'ATH' )
end
Posts: 367
Threads: 83
Joined: Jun 2017
Reputation:
8
(08.08.2023, 08:01) admin Wrote: Try this (not tested):
Code:
1 2 3 4 5
function AT :
call (
number )
self :
send (
'ATD' ..
number ..
';' )
os.sleep (
8 )
self :
send (
'ATH' )
end
Hi, this not working,
If I use in script calling this function:
require('user.sms')
call('3711234567')
I have error
Resident script:3: attempt to call global 'call' (a nil value)
stack traceback:
If I use
require('user.sms')
AT:call('3711234567')
Other error:
User library sms:319: attempt to index field 'port' (a nil value)
stack traceback:
User library sms:319: in function 'send'
User library sms:471: in function 'call'
So something needs to be corrected. If will be time, please look what I need correct in script.
BR, Alex
Posts: 8097
Threads: 43
Joined: Jun 2015
Reputation:
471
It should be combined with the SMS script.
Change
udphandler function in the resident script like 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
udphandler =
function (
server )
local msg =
server :
receive ()
if not msg then
return
end
local sep =
msg :
find (
' ' )
if not sep then
return
end
local num =
msg :
sub (
1 ,
sep -
1 )
local txt =
msg :
sub (
sep +
1 )
if txt ==
'CALL' then
alert (
'calling: ' ..
num )
modem :
call (
num )
else
alert (
'sending sms: ' ..
msg )
modem :
sendsms (
num ,
txt )
end
end
Then try this script (number should probably start with 00):
Code:
1 2
require (
'user.sms' )
sendsms (
'003711234567' ,
'CALL' )
Posts: 367
Threads: 83
Joined: Jun 2017
Reputation:
8
19.08.2023, 11:04
(This post was last modified: 19.08.2023, 11:46 by AlexLV .)
Hi,
it works, but at the end of number semicolon ; should be added at least for my modem (in some descriptions is needed for ATD command in some not shown)
require('user.sms')
sendsms('003711234567;', 'CALL')
Alex
Forgot to add, that one more "end" should be added in udp handler function:
I have such error when tried to add provided script:
Is it possible to check where I need to add it?
Alex
Posts: 4961
Threads: 28
Joined: Aug 2017
Reputation:
228
The message says it, If you want us to look drop full script not screenshot.
------------------------------
Ctrl+F5
Posts: 367
Threads: 83
Joined: Jun 2017
Reputation:
8
(21.08.2023, 07:36) Daniel Wrote: The message says it, If you want us to look drop full script not screenshot.
Hi, sorry. My script:
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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
if not numbers then
require (
'user.sms' )
require (
'json' )
require (
'socket' )
numbers = {
'371xxxxxxx' ,
'371xxxxxxx' }
comport =
'ttyUSB0'
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 (
'0/0/40' ,
quality )
end
csqtime =
os.time ()
handler =
function (
sms )
alert (
'incoming sms: [%s] %s' ,
tostring (
sms.sender ),
tostring (
sms.data ))
if table.contains (
numbers ,
sms.sender )
then
parser (
sms.data ,
sms.sender )
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
local num =
msg :
sub (
1 ,
sep -
1 )
local txt =
msg :
sub (
sep +
1 )
if txt ==
'CALL' then
alert (
'calling: ' ..
num )
modem :
call (
num )
else
alert (
'sending sms: ' ..
msg )
modem :
sendsms (
num ,
txt )
end
end
end
if modem then
if modem :
run ()
then
now =
os.time ()
delta =
math.abs (
now -
csqtime )
if delta >=
15 then
csqtime =
now
readcsq ()
end
udphandler (
server )
else
alert (
'SMS handler lost connection' )
modem :
reinit ()
end
else
alert (
'SMS handler init' )
modem =
AT :
init (
'/dev/' ..
comport ,
doreset )
if modem then
modem :
setsmshandler (
handler )
modem :
send (
'ATE1' )
if pincode then
modem :
send (
'AT+CPIN=' ..
pincode )
modem :
read ()
end
modem :
send (
'AT+CSMS=1' )
modem :
send (
'AT+CMGF=0' )
modem :
send (
'AT+CNMI=1,1,0,0,1' )
modem :
send (
'AT+CSCS="GSM"' )
modem :
send (
'AT+CMGD=1' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=2' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=3' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=4' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=5' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=6' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=7' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=8' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=9' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=10' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=11' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=12' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=13' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=14' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=15' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=16' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=17' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=18' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=19' )
sleep (
0.2 )
modem :
send (
'AT+CMGD=20' )
server =
socket.udp ()
server :
setsockname (
'127.0.0.1' ,
12535 )
server :
settimeout (
0.1 )
alert (
'SMS handler started' )
else
alert (
'SMS USB init failed' )
end
end BR, Alex
Posts: 4961
Threads: 28
Joined: Aug 2017
Reputation:
228
Drop this script to notepad++, select language LUA and it will highlight you which if belongs to which end.
------------------------------
Ctrl+F5