Search code examples
javasms-gatewaysmslib

SMSLib sending message, using multiple gateways


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


Solution

  • 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);