Search code examples
javalinuxsmssms-gatewaygammu

Gammu send sms using two or more java app from ssh at the same time


I'm using gammu to send sms, and I was wondering if it is possible to send messages at the same time using two or more computer with java app. I tried it 10 times and 1 out of 10 times the message successfully sent from both computer. 9 times only one computer can send the sms with the other one failing to send. Is there some kind of setting or command so I can send message from both of this computers at the same time? For the config I use the default config from Gammu

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;

public class TestingSms {



public static void main(String[] args) {
        // TODO Auto-generated method stub
        String host = "MY GAMMU IP";
        String user = "MY USERNAME";
        String password = "MY PASSWORD";
        int port = 22;
        String sms ="haloo";

        JSch jsch = new JSch();
        try {
            Session session = jsch.getSession(user, host, port);
            session.setPassword(password);
            session.setConfig("StrictHostKeyChecking", "no");
            session.connect();

            ChannelExec exec = (ChannelExec) session.openChannel("exec");
            exec.setCommand("gammu sendsms TEXT 08xxxxxxxxxx -text \""+sms+"\"");
            exec.setErrStream(System.err);

            exec.connect();

            BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream()));
            String temp;
            while((temp=reader.readLine())!=null) {
                System.out.println(temp);
            }
            exec.disconnect();
            session.disconnect();

            System.out.println("\n\nFinish");
        } catch (JSchException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

Failed Message:

Warning: No configuration read, using builtin defaults!
No response in specified timeout. Probably phone not connected.

Thank you in advance


Solution

  • Maybe you rather want to use Gammu SMSD for this - it runs on the server and sends/receives messages from/to database. This way you can easily send messages from other hosts just by inserting them to the database.

    The error Warning: No configuration read, using builtin defaults! indicates that Gammu didn't find the configuration file, maybe you're running it as different user? Or try to specify path to configuration file using --config parameter.