218
17. 3G modem connection with LM
LogicMachine has a regular 3G modem driver built-in (Huawei and other vendor supported).
Currently this can be used for SMS notifications only receiving and sending commands. The
modem has to be plugged into USB port. We suggest to use external 5V powering for the
modem because by USB2.0 standard the output current on USB is 0.75A, but some modems
requires up to 2A which is out of standard so the modem can lack the power and get
disconnected.
List of supported 3G modems can be found here:
http://openrb.com/wp-content/uploads/2015/12/3G_USB_device_reference.txt
First thing is to lower the modem speed by adding the following code in Start-up / Init script:
1.
os.execute('echo 1 > /sys/bus/platform/devices/ci_hdrc.0/force_full_speed')
2.
os.execute('echo 1 > /sys/bus/platform/devices/ci_hdrc.1/force_full_speed')
3.
os.execute('usbreset /dev/bus/usb/001/001')
After you need to add SMS handler program a resident script with sleep interval 0.
Note!
1.
-- init
2.
ifnot
modem
then
3.
-- allowed numbers, SMS message from other number will be ignored
4.
numbers
={'1234567890'
,
'0123456789'}
5.
-- replace 0000 with SIM pin number, or remove the line below if PIN check is disabled
6.
pincode
='0000'
7.
-- modem communication port, ttyUSB2 for Huawei E173
8.
comport
='ttyUSB2'
9.
-- open serial port
10.
modem
=
AT:init
('/dev/'
.. comport
)
11.
-- command parser
12.
parser
=function(
cmd, sender
)
13.
local
find, pos, name, mode, offset, value, jvalue, obj
14.
cmd
=
cmd:trim
()
15.
mode
=
cmd:sub
(
1, 1
)
:upper
()
16.
if
mode
=='W'or
mode
=='R'then
17.
cmd
=
cmd:sub
(3)
:trim
()
18.
-- parse object name/address
19.
find
=
cmd:sub
(1
,
1)=='"'and'"'or' '
20.
offset
=
find
=='"'and
1
or0
21.
-- pad with space when in read mode
22.
if
mode
=='R'and
find
==' 'then
23.
cmd
=
cmd ..
' '
24.
end
25.
-- find name
26.
pos
=
cmd:find
(
find, 1 + offset,
true)
27.
-- name end not found, stop