Reputation: 91
I am using a Simado GDT11 modem and Prolific USB to Serial port driver. The new connection appears in my Device Manager > Ports list. However, I am unable to send messages using smslib.
I am using the basic class as specified in the smslib examples, but there is always some error which states that there is no response from the device. I have added the polling parameters because of the use of USB port but to no avail. Commtest Utility is able to connect to the same port, so I don't think the port number is an issue.
Stacktrace:
log4j:WARN No appenders could be found for logger (smslib).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
org.smslib.TimeoutException: No response from device.
at org.smslib.modem.AModemDriver$CharQueue.get(AModemDriver.java:535)
at org.smslib.modem.AModemDriver.getResponse(AModemDriver.java:338)
at org.smslib.modem.AModemDriver.getResponse(AModemDriver.java:313)
at org.smslib.modem.athandler.ATHandler.getSimStatus(ATHandler.java:145)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:132)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:189)
at org.smslib.Service$1Starter.run(Service.java:277)
Code:
public class SendMessage {
public void doIt() throws Exception
{
SerialModemGateway gateway = new SerialModemGateway("modem.com4", "COM4", 115200, "Simado", "GDT11");
try {
OutboundNotification outboundNotification = new OutboundNotification();
System.out.println("Example: Send message from a serial gsm modem.");
System.out.println(Library.getLibraryDescription());
System.out.println("Version: " + Library.getLibraryVersion());
gateway.setInbound(false);
gateway.setOutbound(true);
gateway.setSimPin("0000");
// Explicit SMSC address set is required for some modems.
// Below is for VODAFONE GREECE - be sure to set your own!
gateway.setSmscNumber("+919560734413");
Service.getInstance().setOutboundMessageNotification(outboundNotification);
Service.getInstance().addGateway(gateway);
Service.getInstance().S.SERIAL_NOFLUSH = true;
Service.getInstance().S.SERIAL_POLLING = true;
Service.getInstance().S.SERIAL_POLLING_INTERVAL = 200;
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() + "%");
System.out.println();
// Send a message synchronously.
OutboundMessage msg = new OutboundMessage("+918095065000", "Hello from SMSLib!");
Service.getInstance().sendMessage(msg);
System.out.println(msg);
} finally {
gateway.stopGateway();
Service.getInstance().stopService();
}
}
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[])
{
SendMessage app = new SendMessage();
try
{
app.doIt();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Upvotes: 0
Views: 1314
Reputation: 91
I resolved the issue. The code is correct. Apparently, using a SIM card which is on roaming isn't the best idea. I shifted to a local SIM card, and the message was sent.
Furthermore, I was using a USB to COM port emulator (Prolific USB-Serial) due to which the modem was not initializing while running the code.
To solve this, I ran the initialization command(AT + CMGF = 1
) on server start up.
Upvotes: 1