0

I'm using SMSLib for sending and receiving messages. Everything's working great, but now I'd like to plug more than one modem. I want to receive messages by all of my modems and do something with them (I can do that, I think). I also want to send messages, but only through the selected modem (there's my problem). Until I had one gateway i did sending like this:

OutboundMessage msg = new OutboundMessage(recipientNumber, text);
Service.getInstance().sendMessage(msg);

But now, how can I select the one specific gateway, that I want to use to send my message?

I found a topic with a problem a bit like mine, but not exactly: Use multiple gateway with SMSLIB

Community
  • 1
  • 1
Radziasss
  • 193
  • 1
  • 1
  • 11

3 Answers3

1

Each modem is a AGatway object in SMSLib so you need to set it up first:

SerialModemGateway modemGateway = new  SerialModemGateway("FirstGateway", "/dev/ttyM0", "9600", "WAVECOM", "Fastrack");
Service.getInstance().addGateway(modemGateway);

Where FirstGateway is ID of your modem which is called gatewayId in SMSLib. All you have to do now is pass your gatewayId to sendMessage method or queueMessage (if you send messages asynchronously):

OutboundMessage msg = new OutboundMessage(recipientNumber, text);
Service.getInstance().sendMessage(msg, "FirstGateway");

or:

OutboundMessage msg = new OutboundMessage(recipientNumber, text);
msg.setGatewayId("FirstGateway");
Service.getInstance().sendMessage(msg);
Lukasz
  • 41
  • 1
0

I didnt notice that there is such a method sendMessage() which takes gatewayId as a second agrument. If so, there will be perfect. I'll check that tomorrow, are you sure about that? I'm using SmsLib 3.x

EDIT:

It's exactly as you said. I just put gatewayId as a second argument and it's working. Another options is that you can set gatewayId of created OutboundMessage:

OutboundMessage msg = new OutboundMessage(recipientNumber, text);
msg.setGatewayId("FirstGateway");
Service.getInstance().sendMessage(msg);

So easy.. Thanks!

Radziasss
  • 193
  • 1
  • 1
  • 11
0

I would't use sendMessage method with multiple gateways, use queueMessage it adds your msg to SMSLib service queue and sends it asynchronously.

Also , if you start your application with:

-Dsmslib.queuedir=yourQueuedMessagesDirectory

you will be able to store all unsent messages on hard drive and give SMSLib service facility to send them after application restart.

Lukasz
  • 41
  • 1
  • I've never used queueMessage, but I'll check how it works. I'm planning to put outgoing messages in a database table, run a task for example once a minute, send them and change their status if they were sent properly. And there is a place to use queueMessage and IOutboundMessageNotification, which I won't be able to use when sending via sendMessage. Cool ! :-) – Radziasss Mar 15 '16 at 10:19