Posts: 342
Threads: 130
Joined: May 2020
Reputation:
0
Hello
I asked for the 4g modem to be installed in the reactor, since a customer has only provided me with 4g sim, when the APN returns and the internet connects, I send the emails but I have an error in sending the SMS.
Does the SMS library also have to be modified in order to manage the new modem?
below the error reported in the offending lines
Code:
1 2 3 4 5
function sendsms (
number ,
message )
require (
'socket' )
client =
socket.udp ()
client :
sendto (
number ..
' ' ..
message ,
'127.0.0.1' ,
12535 )
end
Posts: 8159
Threads: 43
Joined: Jun 2015
Reputation:
472
This script has nothing to do with the SMS sending via modem it simply sends message to the resident script. Post your full resident SMS script and a screenshot from System config > Status > System status > Serial ports.
Posts: 342
Threads: 130
Joined: May 2020
Reputation:
0
(31.01.2022, 15:30) admin Wrote: This script has nothing to do with the SMS sending via modem it simply sends message to the resident script. Post your full resident SMS script and a screenshot from System config > Status > System status > Serial ports.
resident sms
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 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
if not numbers then
require (
'user.sms' )
require (
'json' )
require (
'socket' )
numbers = {
'3332958126' }
comport =
'ttyACM3'
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
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 )
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
if not numbers then
require (
'user.sms' )
require (
'json' )
require (
'socket' )
numbers = {
'3332958126' }
comport =
'ttyACM3'
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
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 )
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 user library
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 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
AT = {
alphabet = {
64 ,
163 ,
36 ,
165 ,
232 ,
233 ,
249 ,
236 ,
242 ,
199 ,
10 ,
216 ,
248 ,
13 ,
197 ,
229 ,
10 ,
95 ,
10 ,
10 ,
10 ,
10 ,
10 ,
10 ,
10 ,
10 ,
10 ,
38 ,
198 ,
230 ,
223 ,
201 ,
32 ,
33 ,
34 ,
35 ,
164 ,
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 ,
161 ,
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 ,
196 ,
214 ,
209 ,
220 ,
167 ,
191 ,
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 ,
228 ,
246 ,
241 ,
252 ,
224
},
parsepdu =
function (
pdu )
local data ,
len ,
msg ,
data ,
sender ,
offset ,
ntype ,
timestamp
msg = {}
offset =
tonumber (
pdu :
sub (
1 ,
2 ),
16 ) *
2
len =
tonumber (
pdu :
sub (
offset +
5 ,
offset +
6 ),
16 )
len =
math.ceil (
len /
2 ) *
2
ntype =
tonumber (
pdu :
sub (
offset +
7 ,
offset +
8 ),
16 )
ntype =
bit.band (
bit.rshift (
ntype ,
4 ),
0x07 )
sender =
pdu :
sub (
offset +
9 ,
offset +
len +
8 )
msg.sender =
AT.decodesender (
sender ,
ntype )
offset =
offset +
len +
13
timestamp =
pdu :
sub (
offset ,
offset +
13 )
timestamp =
AT.decodeswapped (
timestamp )
msg.timestamp =
AT.decodetime (
timestamp )
len =
tonumber (
pdu :
sub (
offset +
14 ,
offset +
15 ),
16 )
data =
pdu :
sub (
offset +
16 )
msg.data =
AT.decode7bit (
data ,
len )
return msg
end ,
decodesender =
function (
sender ,
ntype )
if ntype ==
5 then
return AT.decode7bit (
sender )
else
return AT.decodeswapped (
sender )
end
end ,
decodetime =
function (
timestamp )
local offset ,
year ,
time
offset =
tonumber (
timestamp :
sub (
13 ,
14 ))
or 0
offset =
offset *
15 *
60
year =
tonumber (
timestamp :
sub (
1 ,
2 ))
time =
os.time ({
year =
year <
70 and (
2000 +
year )
or (
1900 +
year ),
month =
tonumber (
timestamp :
sub (
3 ,
4 )),
day =
tonumber (
timestamp :
sub (
5 ,
6 )),
hour =
tonumber (
timestamp :
sub (
7 ,
8 )),
min =
tonumber (
timestamp :
sub (
9 ,
10 )),
sec =
tonumber (
timestamp :
sub (
11 ,
12 ))
})
or os.time ()
return time
end ,
decodeswapped =
function (
data )
local i ,
nr ,
len ,
buf
buf = {}
len =
math.floor (
data :
len () /
2 )
for i =
1 ,
len do
nr =
tonumber (
data :
sub (
i *
2 ,
i *
2 ))
if nr then
table.insert (
buf ,
tostring (
nr ))
end
nr =
tonumber (
data :
sub (
i *
2 -
1 ,
i *
2 -
1 ))
if nr then
table.insert (
buf ,
tostring (
nr ))
end
end
return table.concat (
buf )
end ,
from7bit =
function (
c )
if c <
128 then
return string.char (
AT.alphabet [
c +
1 ])
else
return ' '
end
end ,
decode7bit =
function (
data ,
len )
local i ,
o ,
byte ,
prev ,
curr ,
mask ,
buf ,
res
data =
lmcore.hextostr (
data ,
true )
o =
0
prev =
0
buf = {}
for i =
1 ,
data :
len ()
do
byte =
data :
byte (
i ,
i )
mask =
bit.lshift (
1 ,
7 -
o ) -
1
curr =
bit.band (
byte ,
mask )
curr =
bit.lshift (
curr ,
o )
curr =
bit.bor (
curr ,
prev )
prev =
bit.rshift (
byte ,
7 -
o )
table.insert (
buf ,
AT.from7bit (
curr ))
if o ==
6 then
table.insert (
buf ,
AT.from7bit (
prev ))
prev =
0
end
o = (
o +
1 ) %
7
end
if prev >
0 then
table.insert (
buf ,
AT.from7bit (
prev ))
end
res =
table.concat (
buf )
if len then
res =
res :
sub (
1 ,
len )
end
return res
end
}
function AT :
init (
dev ,
reset )
require (
'serial' )
local t =
setmetatable ({}, {
__index =
AT })
t.dev =
dev
while true do
if t :
reinit (
30 ,
reset )
then
break
else
if reset then
t :
reset ()
else
return nil
end
end
end
return t
end
function AT :
open (
timeout )
local port
while true do
if io.exists (
self.dev )
then
port =
serial.open (
self.dev )
if port then
break
end
end
if timeout then
timeout =
timeout -
1
if timeout <=
0 then
return false
end
end
os.sleep (
1 )
end
self.port =
port
self.buffer = {}
return true
end
function AT :
reset ()
os.execute (
'usbreset /dev/bus/usb/001/001' )
end
function AT :
reinit (
timeout ,
reset )
local res
if reset then
self :
reset ()
end
res =
self :
open (
timeout )
self.buffer = {}
return res
end
function AT :
close ()
if self.port then
self.port :
close ()
self.port =
nil
end
end
function AT :
read (
timeout )
local char ,
err ,
timeout ,
deftimeout ,
line
timeout =
tonumber (
timeout )
or 1
timeout =
timeout *
10
deftimeout =
timeout
while timeout >
0 do
char ,
err =
self.port :
read (
1 ,
0.1 )
if char then
if char ==
'\n' then
line =
table.concat (
self.buffer )
self.buffer = {}
line =
line :
trim ()
if #
line >
0 then
return line
else
timeout =
deftimeout
end
elseif char ~=
'\r' then
table.insert (
self.buffer ,
char )
end
elseif err ==
'timeout' then
timeout =
timeout -
1
else
break
end
end
print (
'error' ,
err )
return nil ,
err
end
function AT :
readuntil (
cmd ,
timeout )
local line ,
err
timeout =
timeout or 5
while timeout >
0 do
line ,
err =
self :
read ()
if line then
if line ==
cmd or line ==
'COMMAND NOT SUPPORT' or line :
match (
'ERROR' )
then
return line
else
timeout =
timeout -
1
err =
'invalid line'
end
elseif err ==
'timeout' then
timeout =
timeout -
1
else
break
end
end
return nil ,
err
end
function AT :
send (
cmd )
local res ,
err =
self.port :
write (
cmd ..
'\r\n' )
if res then
res ,
err =
self :
readuntil (
cmd )
self :
read ()
end
return res ,
err
end
function AT :
run ()
local res ,
err ,
cmd ,
pos ,
sms
res ,
err =
self :
read ()
if err then
return err ==
'timeout'
end
if res :
sub (
1 ,
1 ) ~=
'+' then
return true
end
pos =
res :
find (
':' ,
1 ,
true )
if not pos then
return true
end
cmd =
res :
sub (
2 ,
pos -
1 )
if cmd ~=
'CMTI' then
return
end
sms =
self :
incsms (
res )
if sms and self.smshandler then
self.smshandler (
sms )
end
return true
end
function AT :
incsms (
res )
local chunks ,
index ,
sms
chunks =
res :
split (
',' )
if #
chunks ==
2 then
index =
tonumber (
chunks [
2 ])
sms =
self :
readsms (
index )
self :
deletesms (
index )
end
return sms
end
function AT :
deletesms (
index )
local cmd ,
res
cmd =
'AT+CMGD=' ..
index
res =
self :
send (
cmd )
return res
end
function AT :
readsms (
index )
local cmd ,
res ,
sms
cmd =
'AT+CMGR=' ..
index
res =
self :
send (
cmd )
if res ==
'OK' then
return nil ,
'not found'
end
sms =
self :
read ()
res ,
sms =
pcall (
AT.parsepdu ,
sms )
if not res then
return nil ,
sms
end
self :
readuntil (
'OK' )
return sms
end
function AT :
sendsms (
number ,
message )
local cmd ,
res
self :
send (
'AT+CMGF=1' )
cmd =
string.format (
'AT+CMGS="%s"' ,
number )
res =
self :
send (
cmd )
if res ~=
'ERROR' then
self.port :
write (
message ..
string.char (
0x1A ))
res =
self :
readuntil (
'OK' )
end
self :
send (
'AT+CMGF=0' )
return res
end
function AT :
setsmshandler (
fn )
if type (
fn ) ==
'function' then
self.smshandler =
fn
end
end
table.contains =
function (
t ,
v )
for _ ,
i in pairs (
t )
do
if i ==
v then
return true
end
end
end
function sendsms (
number ,
message )
require (
'socket' )
client =
socket.udp ()
client :
sendto (
number ..
' ' ..
message ,
'127.0.0.1' ,
12535 )
end
Attached Files
Thumbnail(s)
Posts: 8159
Threads: 43
Joined: Jun 2015
Reputation:
472
Replace ttyACM3 with ttyUSB2
Posts: 342
Threads: 130
Joined: May 2020
Reputation:
0
(01.02.2022, 08:20) admin Wrote: Replace ttyACM3 with ttyUSB2
Nothing
I have this error when i try send sms
User library sms:465: attempt to index global 'client' (a nil value)
stack traceback:
User library sms:465: in function 'sendsms'
but in other reactor works
thanks
Posts: 8159
Threads: 43
Joined: Jun 2015
Reputation:
472
Replace the whole
sendsms function with this and check if it works. Also check if you have any messages in Logs.
Code:
1 2 3 4 5 6 7 8 9
function sendsms (
number ,
message )
local client ,
err =
require (
'socket' ).
udp ()
if client then
client :
sendto (
number ..
' ' ..
message ,
'127.0.0.1' ,
12535 )
client :
close ()
else
log (
'failed to created socket: ' ..
tostring (
err ))
end
end
Posts: 342
Threads: 130
Joined: May 2020
Reputation:
0
(01.02.2022, 12:18) admin Wrote: Replace the whole sendsms function with this and check if it works. Also check if you have any messages in Logs.
Code:
1 2 3 4 5 6 7 8 9
function sendsms (
number ,
message )
local client ,
err =
require (
'socket' ).
udp ()
if client then
client :
sendto (
number ..
' ' ..
message ,
'127.0.0.1' ,
12535 )
client :
close ()
else
log (
'failed to created socket: ' ..
tostring (
err ))
end
end
nothinig in log but nothing sms send
Posts: 8159
Threads: 43
Joined: Jun 2015
Reputation:
472
You have the same code in the resident script twice, this can lead to errors. You've also commented out all alerts so there's no way of knowing if the script is working or not.
Replace your resident script with this and post what you get in alerts:
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
if not numbers then
require (
'user.sms' )
require (
'json' )
require (
'socket' )
numbers = {
'3332958126' }
comport =
'ttyACM3'
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
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
alert (
'sending sms: ' ..
msg )
modem :
sendsms (
msg :
sub (
1 ,
sep -
1 ),
msg :
sub (
sep +
1 ))
end
end
if modem then
if modem :
run ()
then
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 )
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 )
alert (
'SMS handler started' )
else
alert (
'SMS USB init failed' )
end
end
Posts: 342
Threads: 130
Joined: May 2020
Reputation:
0
(01.02.2022, 13:35) admin Wrote: You have the same code in the resident script twice, this can lead to errors. You've also commented out all alerts so there's no way of knowing if the script is working or not.
Replace your resident script with this and post what you get in alerts:
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
if not numbers then
require (
'user.sms' )
require (
'json' )
require (
'socket' )
numbers = {
'3332958126' }
comport =
'ttyACM3'
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
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
alert (
'sending sms: ' ..
msg )
modem :
sendsms (
msg :
sub (
1 ,
sep -
1 ),
msg :
sub (
sep +
1 ))
end
end
if modem then
if modem :
run ()
then
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 )
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 )
alert (
'SMS handler started' )
else
alert (
'SMS USB init failed' )
end
end
problem to init
Attached Files
Thumbnail(s)
Posts: 8159
Threads: 43
Joined: Jun 2015
Reputation:
472
Sorry, that was an old script. Replace ttyACM3 with ttyUSB2 and restart the script via disable/enable.
Posts: 342
Threads: 130
Joined: May 2020
Reputation:
0
(01.02.2022, 14:56) admin Wrote: Sorry, that was an old script. Replace ttyACM3 with ttyUSB2 and restart the script via disable/enable.
Same error , need som in init script ?
Posts: 8159
Threads: 43
Joined: Jun 2015
Reputation:
472
Can you provide remote access to your LM?
Posts: 342
Threads: 130
Joined: May 2020
Reputation:
0
(02.02.2022, 09:13) admin Wrote: Can you provide remote access to your LM?
via zerotier is ok ?
Posts: 8159
Threads: 43
Joined: Jun 2015
Reputation:
472
Yes, send your network ID, LM ZeroTier IP and admin password via PM.
Posts: 8159
Threads: 43
Joined: Jun 2015
Reputation:
472
Check if it's working now. You had a space after the serial port name so it did not work:
Posts: 342
Threads: 130
Joined: May 2020
Reputation:
0
(02.02.2022, 09:53) admin Wrote: Check if it's working now. You had a space after the serial port name so it did not work:
tanks a lot
Posts: 342
Threads: 130
Joined: May 2020
Reputation:
0
Hello
For the problem of sending sms I solved with your help in 2 reactor out of 3, in the third with the same scripts, if I text the sms calling send it works, while if it is called from the script the alalrme event does not work, while the mails from the same script do
The alalrme event scripts I checked it are like in the reactor it works in, I'm getting lost and I don't know where.
I accept advice
Thank you
Posts: 8159
Threads: 43
Joined: Jun 2015
Reputation:
472
Have you replaced the sendsms function as specified?
https://forum.logicmachine.net/showthrea...1#pid24831
Do you have anything in alerts and logs?
Posts: 342
Threads: 130
Joined: May 2020
Reputation:
0
(03.02.2022, 07:27) admin Wrote: Have you replaced the sendsms function as specified? https://forum.logicmachine.net/showthrea...1#pid24831
Do you have anything in alerts and logs?Hello
I found the problem, the phone number had a space at the end for which it was not valid, now I try how to remove the spaces before and after, both for the phone number and if I can also for the email address so as to no longer have the problem.
Thank you
Posts: 46
Threads: 14
Joined: Dec 2016
Reputation:
0
Hi,
We are having the same problem that Frank68 sending SMS.
The LM was working fine but from one day to the other it stop working. We tried changing the comport, factory reset the LM and even tried it on other LM with no result.
On Alert tab we keep getting SMS USB init failed.
Another thing I find strange is that the serial ports don't show on system status (view image).
Our firmware is Version : 20230612.
Thanks for your hel p,
BR,
Neves
Attached Files
Thumbnail(s)