smslib not sending sms why?

我们两清 提交于 2019-12-06 03:44:55

This example has extra line of code about SMSC-number. I have played with this same library and in my code there is not any SMSC - at any line of my code.

It is a suggestion, "if needed", and I certainly believe getting rid of it solves your problem. You most probably don't know what you exactly have to put on it, so better leaving it out. Then modem will not try to do this routing manually to given number but it can make it to the correct, what it knows by SIM settings on the SIM card.

Another thing I would check is that the modem really answers from COM4 port. Although now it seems to do so, because the signal strength is read. But check this always, because every startup of server can map the device to different port. I was at least having this kind of problem on Linux side.

Maybe you have not taken care enough (yet) to the SerialModemGateway constructor arguments, as you left "Huawei" as vendor whereas you use a Nokia device. That parameter is not important but the baud rate is. According to SMSlib documentation, most devices only works properly in a preset/uniq baudrate.

I propose you open other software settings to get or confirm parameters you have used:

  • baud rate
  • gateway SMSC number - maybe from Connection history menu according to Nokia user guide

As you get your code from an Huawei example, this example set the gateway SMSC number but this parameter is supposed to be optional for most devices, only Huawei devices may require it. Try a run without gateway.setSmscNumber !

I also invite you to monitor serial port traffic with Portmon for instance and report it here and on SMSlib forum to get support.

Finally, you should ask SMSlib maintainer its option about your device, as it is in the compatibility list (yet)

Following is a sample code I used and tested. You can re-use it.

package com.stackoverflow.smstest;

import java.net.URL;

import org.smslib.AGateway;
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.OutboundMessage;
import org.smslib.OutboundWapSIMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;

public class Main {

    public void sendMessage() throws Exception {
        OutboundNotification outboundNotification = new OutboundNotification();
        System.out.println("Sample of Send message from a serial gsm modem.");
        System.out.println(Library.getLibraryDescription());
        System.out.println("Version: " + Library.getLibraryVersion());
        SerialModemGateway gateway = new SerialModemGateway("modem.com4",
                "COM4", 57600, "Huawei", "E160");
        gateway.setInbound(false);
        gateway.setOutbound(true);
        // gateway.setSimPin("");
        Service.getInstance().setOutboundMessageNotification(
                outboundNotification);
        Service.getInstance().addGateway(gateway);
        Service.getInstance().startService();
        System.out.println();
        System.out.println("Modem Information:");
        System.out.println("  Manufacturer: " + gateway.getManufacturer());
        System.out.println("  Model: " + gateway.getModel());
        System.out.println("  Serial No: " + gateway.getSerialNo());
        System.out.println("  SIM IMSI: " + gateway.getImsi());
        System.out.println("  Signal Level: " + gateway.getSignalLevel()
                + " dBm");
        System.out.println("  Battery Level: " + gateway.getBatteryLevel()
                + "%");

        // Send a message synchronously.
        OutboundMessage msg = new OutboundMessage("+94123456789",
                "SMS test: sample message from StackOverflow");

        Service srvice = Service.getInstance();
        // Service.getInstance().sendMessage(msg);
        System.out.println(msg);
        // Or, send out a WAP SI message.
        OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("+94123456789",
                new URL("http://stackoverflow.com/"),
                "WAP test: sample message from StackOverflow!");
        // gateway.setFrom("chandpriyankara");
        // wapMsg.setFrom("chandpriyankara");
        srvice.queueMessage(wapMsg);

        Service.getInstance().stopService();
    }

    /**
     * Outbound Message informations handler
     * 
     * @author chandpriyankara
     * 
     */
    public class OutboundNotification implements IOutboundMessageNotification {
        public void process(AGateway gateway, OutboundMessage msg) {
            System.out.println("Outbound handler called from Gateway: "
                    + gateway.getGatewayId());
            System.out.println(msg);
        }
    }

    public static void main(String args[]) {
        Main app = new Main();
        try {
            app.sendMessage();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!