I had to keep the following somewhere other than my memory since I know how unreliable it is.
There was a need to send and receive SMS for an app and people were wondering if we need to buy a separate GSM modem for that. Easier solution was to use a dongle (which is, well, basically a GSM modem J )
After a little research I thought of using SMSLib as recommended by many folks on internet. (http://smslib.org/)
SMSLib is a SMS messaging library. As mentioned in their home page two SMSLib versions currently available. The old, stable v3.x and the newer v4. SMSLib v4 is under development.
I used smslib-3.5.4.jar.
Downloads can be found at http://smslib.org/download/. Some of the paths given for artifacts in installation directory are not working, so I used the downloads page.
Used
- HUAWEI Mobile HSPA+ dongle
- Win64
- smslib-3.5.4
- java 7
1. Plug in dongle to USB port and find port number (Control Panel -> Device Manage -> Ports) It was COM11 in my case
2. Add RXTXcomm library as mentioned below
3. Create a sample java project and add smslib-3.5.4.jar in lib
4. Run the following java code. (Update port)
import org.smslib.*; import org.smslib.modem.SerialModemGateway; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class SmsSenderReceiver { public void sendMessage() throws Exception { SerialModemGateway gateway = new SerialModemGateway("", "COM11", 9600, "", ""); gateway.setInbound(true); gateway.setOutbound(true); OutboundNotification outboundNotification = new OutboundNotification(); InboundNotification inboundNotification = new InboundNotification(); Service service = Service.getInstance(); service.setOutboundMessageNotification(outboundNotification); service.setInboundMessageNotification(inboundNotification); service.addGateway(gateway); service.startService(); OutboundMessage msg = new OutboundMessage("0722452122", "test111"); service.sendMessage(msg); } public class InboundNotification implements IInboundMessageNotification { @Override //Get triggered when a SMS is received public void process(AGateway gateway, Message.MessageTypes messageTypes, InboundMessage inboundMessage) { System.out.println(inboundMessage); try { gateway.deleteMessage(inboundMessage); } catch (Exception e) { e.printStackTrace(); } } } public class OutboundNotification implements IOutboundMessageNotification { //Get triggered when a SMS is sent public void process(AGateway gateway, OutboundMessage outboundMessage) { System.out.println(outboundMessage); } } public static void main(String args[]) { SmsSenderReceiver app = new SmsSenderReceiver(); try { app.sendMessage(); } catch (Exception e) { e.printStackTrace(); } } }
A prerequisite of using SMSLib is having Java Communications library as mentioned in http://smslib.org/doc/installation/.
They list two options
1. Win32 :-> Java Comm v2
2. For others :-> Java Comm v3 or RxTx
Java Comm didn't work for me. Use RxTx.
linux 32bit, 64 bit, Win32 : http://rxtx.qbang.org/pub/rxtx/rxtx-2.1-7-bins-r2.zip
(Above are found at http://smslib.org/download/)
File RXTXcomm.jar should go under JDKDIR/jre/lib/ext/
The necessary library (e.g.the librxtxSerial.so) should go under JDKDIR/jre/bin/
In Linux
Tried to do the same in Linux environment, but unfortunately I kept receiving NoSuchPortException.
Tailed /var/log/messages to view updates.
Device was first identified as "usb-storage". usb_modeswitch was used
usb_modeswitch -H -v 0x12d1 -p 0x1506
View changes.
lsusb
View the port numbers and their permissions. Can see the ports that are mapped to GSM modem.
ls /dev/tty* -l
Added read write permissions
chmod o+rw /dev/ttyUSB*
chmod o+rw /dev/ttyS*
Can use minicom to see if the dongle is functioning as expected.
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread "Thread-3" java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)
librxtxSerial.so had to be added to JDKDIR/jre/lib/amd64 instead of JDKDIR/jre/bin/ to solve the above.
As suggested in http://smslib.org/doc/smslib/troubleshooting/ added the soft links to something resembling a standard serial port.
ln -s /dev/ttyUSB_utps_diag /dev/ttyS20
ln -s /dev/ttyUSB_utps_modem /dev/ttyS21
ln -s /dev/ttyUSB_utps_pcui /dev/ttyS23
The above hack and more useful infor can be found at http://rxtx.qbang.org/wiki/index.php/Trouble_shooting too.
View "How does rxtx detect ports? Can I override it?" Section.
Kept on getting the following warning too.
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
Adding my user to group uucp didn’t solve it L
usermod -aG uucp myUser
vim /etc/group
Hi!
ReplyDeleteCan you tell me how can I choose the location where the inboundSMS gets the received SMS? I think the default is in SIM. How can I change it to local storage of the GSM modem or make it both? By the way, I'm using a broadband stick as my GSM modem.
Thanks.
Hi Kal
ReplyDeleteThis was relly helpfull. Anyways i was able to run the code in linux. :)
HI I found exception
ReplyDeleteException in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Priority
at org.smslib.Service.listSystemInformation(Service.java:113)
at org.smslib.Service.initializeService(Service.java:103)
at org.smslib.Service.(Service.java:95)
at org.smslib.Service.(Service.java:90)
at SmsSenderReceiver.sendMessage(SmsSenderReceiver.java:23)
at SmsSenderReceiver.main(SmsSenderReceiver.java:68)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Priority
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
Seems u have missing dependencies in your project. "java.lang.ClassNotFoundException: org.apache.log4j.Priority"
DeleteI also get an exceptions. How can I fix it ?
DeleteHi Kal,Sending sms working fine. But receiving SMS not triggering InboundNotification class. Do I need to enable something on dongle settings?
ReplyDeleteI am facing this error.
ReplyDeleteException in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Priority
at org.smslib.Service.listSystemInformation(Service.java:113)
at org.smslib.Service.initializeService(Service.java:103)
at org.smslib.Service.(Service.java:95)
at org.smslib.Service.(Service.java:90)
at SendSMS.SmsSender.sendMessage(SmsSender.java:22)
at SendSMS.SmsSender.main(SmsSender.java:57)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Priority
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
@Abdulrehman Javed That is an indication of one of the required files not being in the proper location. Now, is there anyone who has done an incoming sms listener on Linux?
DeleteThis comment has been removed by the author.
ReplyDeleteWe have two types of sms api Java ; XML and JSON for sending SMS in bulk to your prospects from our gateway.
ReplyDelete2020-07-15 18:28:17,977 GTW: modem.com8: Framing Error!
ReplyDelete2020-07-15 18:28:18,046 GTW: modem.com8: Framing Error!
2020-07-15 18:28:18,128 GTW: modem.com8: Framing Error!
2020-07-15 18:28:18,210 GTW: modem.com8: Framing Error!
2020-07-15 18:28:18,308 GTW: modem.com8: Framing Error!
2020-07-15 18:28:18,396 GTW: modem.com8: Framing Error!
2020-07-15 18:28:18,492 GTW: modem.com8: Framing Error!
2020-07-15 18:28:18,575 GTW: modem.com8: Framing Error!
2020-07-15 18:28:18,666 GTW: modem.com8: Framing Error!
2020-07-15 18:28:18,758 GTW: modem.com8: Framing Error!
2020-07-15 18:28:18,849 GTW: modem.com8: Framing Error!
2020-07-15 18:28:18,908 GTW: modem.com8: SEND :(27)
2020-07-15 18:28:18,956 GTW: modem.com8: Framing Error!
2020-07-15 18:28:19,050 GTW: modem.com8: Framing Error!
2020-07-15 18:28:19,124 GTW: modem.com8: SEND :+++
2020-07-15 18:28:19,150 GTW: modem.com8: Framing Error!
2020-07-15 18:28:19,274 GTW: modem.com8: Framing Error!
2020-07-15 18:28:19,335 GTW: modem.com8: SEND :ATZ(cr)
2020-07-15 18:28:19,372 GTW: modem.com8: Framing Error!
2020-07-15 18:28:19,372 GTW: modem.com8: Framing Error!
2020-07-15 18:28:19,469 GTW: modem.com8: Framing Error!
2020-07-15 18:28:19,552 GTW: modem.com8: clearBuffer() called.
2020-07-15 18:28:19,571 GTW: modem.com8: Framing Error!
2020-07-15 18:28:19,670 GTW: modem.com8: Framing Error!
2020-07-15 18:28:19,771 GTW: modem.com8: Framing Error!
2020-07-15 18:28:19,856 GTW: modem.com8: Framing Error!
2020-07-15 18:28:19,956 GTW: modem.com8: Framing Error!
2020-07-15 18:28:20,032 GTW: modem.com8: Framing Error!
2020-07-15 18:28:20,084 GTW: modem.com8: Framing Error!
2020-07-15 18:28:20,134 GTW: modem.com8: Framing Error!
2020-07-15 18:28:20,174 GTW: modem.com8: Framing Error!
can anyone help me what is the issue here.
DeleteIf I connect GPRS modem to laptop, framing Error is coming.
Thank You and I have a super present: How Much Are House Renovations Stardew Valley house renovation before and after
ReplyDelete