Has anyone used textlocal in the UK for sms notifications from traccar ver 4.2 http api

Adrian Hodgson6 years ago

There is a provider in the UK that I used many years ago and still have credit with (from 2013) so seeing if I can get my small home traccar server to send sms notifications.

After a quick email to the text centre I got a few answers, the url to send to is:
https://api.txtlocal.com/send
I have an api key for example 1234567890asdfghjkl
I do not need to pass my username or password, just the api key but I do have them if its required.

I am struggling to understand the documentation on HTTP SMS API and the configuration support doc does not list any of these below or indicate what other entries there may be. is there any documentation I have missed?

They do provide some information in the form of Java using POST or GET
here is a java example with POST

    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.net.URL;
    import java.net.URLConnection;
    import java.net.URLEncoder;
     
    public class sendSMS {
        public String sendSms() {
            try {
                // Construct data
                String apiKey = "apikey=" + "yourapiKey";
                String message = "&message=" + "This is your message";
                String sender = "&sender=" + "Jims Autos";
                String numbers = "&numbers=" + "447123456789";
                
                // Send data
                HttpURLConnection conn = (HttpURLConnection) new URL("https://api.txtlocal.com/send/?").openConnection();
                String data = apiKey + numbers + message + sender;
                conn.setDoOutput(true);
                conn.setRequestMethod("POST");
                conn.setRequestProperty("Content-Length", Integer.toString(data.length()));
                conn.getOutputStream().write(data.getBytes("UTF-8"));
                final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                final StringBuffer stringBuffer = new StringBuffer();
                String line;
                while ((line = rd.readLine()) != null) {
                    stringBuffer.append(line);
                }
                rd.close();
                
                return stringBuffer.toString();
            } catch (Exception e) {
                System.out.println("Error SMS "+e);
                return "Error "+e;
            }
        }
    }

I also have a doc in pdf and I could post sections of that but it basically is for php.

Could anyone help point me in the correct direction please.

It may not be able to work at all, but it is worth a try.

Adrian

Adrian Hodgson6 years ago

Sorry was mean to to say the support configuration doc does not list the entry keys used on the http SMS API

Anton Tananaev6 years ago

There are only two parameters you can use:

  • {phone} - phone number
  • {message} - message itself
Adrian Hodgson6 years ago

OK so that sounds like a no then, I believe textlocal used to provide smpp but I can not see any mention of it, so will try asking again tomorrow.

Last question, on the page https://www.traccar.org/http-sms-api/

is there any further explanation of the <entry key = lines anything I can try and understand a bit better?
especially the key <entry key='notificator.sms.manager.class'>org.traccar.sms.HttpSmsClient</entry>

My questions my be dim but I need to understand a bit more.

Cheers

Adrian

Anton Tananaev6 years ago

Your config should look something like this:

<entry key='notificator.sms.manager.class'>org.traccar.sms.HttpSmsClient</entry>
<entry key='sms.http.url'>https://api.txtlocal.com/send/</entry>
<entry key='sms.http.template'>
    apikey=YOUR_API_KEY&message={message}&sender=ANYTHING&numbers={phone}
</entry>
Adrian Hodgson6 years ago

OK thank you I will add that and give it a go.

I really appreciate your time and also appreciate that you are not dealing in your own language when I only know English and some times I can be bad at that!
Also I am not a programmer, so sometimes, some of the answers on the forum go well above my head.

I have managed some of the features of traccar, reverse geocoding, using mysql, run as a service and not as root user, but these are all following docs. I am getting to the more difficult bits for me now of external notifications out to email and phones.

Thanks

Adrian

Adrian Hodgson6 years ago

Ok I failed, the service would not start with the extra lines added to traccar.xml

I had added

    <entry key='notificator.sms.manager.class'>org.traccar.sms.HttpSmsClient</entry>
    <entry key='sms.http.url'>https://api.txtlocal.com/send/</entry>
    <entry key='sms.http.template'>apikey=my key which is numbers and text&message={message}&sender=tracker_server&numbers={phone}</entry>

I checked if traccar was running and got

[sudo] password for adrian: 
● traccar.service - traccar
   Loaded: loaded (/etc/systemd/system/traccar.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/traccar.service.d
           └─run-as-user.conf
   Active: failed (Result: exit-code) since Tue 2019-01-15 19:48:36 GMT; 3min 22s ago
  Process: 1082 ExecStart=/usr/lib/jvm/java-8-openjdk-i386/jre/bin/java -jar tracker-server.jar conf/traccar.xml (code=exited, status=1/FAILURE)
 Main PID: 1082 (code=exited, status=1/FAILURE)

Jan 15 19:48:36 home-tracker traccar[1082]:         at org.traccar.Main.run(Main.java:152)
Jan 15 19:48:36 home-tracker traccar[1082]:         at org.traccar.Main.main(Main.java:104)
Jan 15 19:48:36 home-tracker traccar[1082]: Caused by: java.lang.NullPointerException
Jan 15 19:48:36 home-tracker traccar[1082]:         at org.traccar.helper.Log.setupDefaultLogger(Log.java:160)
Jan 15 19:48:36 home-tracker traccar[1082]:         at org.traccar.Context.init(Context.java:361)
Jan 15 19:48:36 home-tracker traccar[1082]:         at org.traccar.Main.run(Main.java:110)
Jan 15 19:48:36 home-tracker traccar[1082]:         ... 1 more
Jan 15 19:48:36 home-tracker systemd[1]: traccar.service: Main process exited, code=exited, status=1/FAILURE
Jan 15 19:48:36 home-tracker systemd[1]: traccar.service: Unit entered failed state.
Jan 15 19:48:36 home-tracker systemd[1]: traccar.service: Failed with result 'exit-code'.

and I also checked syslog and had very similar messages
Jan 15 19:48:32 home-tracker systemd[1]: Started LSB: Apache2 web server.
Jan 15 19:48:36 home-tracker traccar[1082]: Jan 15, 2019 7:48:36 PM org.traccar.Main run
Jan 15 19:48:36 home-tracker traccar[1082]: SEVERE: Main method error
Jan 15 19:48:36 home-tracker traccar[1082]: java.lang.NullPointerException
Jan 15 19:48:36 home-tracker traccar[1082]: #011at org.traccar.helper.Log.setupDefaultLogger(Log.java:160)
Jan 15 19:48:36 home-tracker traccar[1082]: #011at org.traccar.Context.init(Context.java:361)
Jan 15 19:48:36 home-tracker traccar[1082]: #011at org.traccar.Main.run(Main.java:110)
Jan 15 19:48:36 home-tracker traccar[1082]: #011at org.traccar.Main.main(Main.java:104)
Jan 15 19:48:36 home-tracker traccar[1082]: Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
Jan 15 19:48:36 home-tracker traccar[1082]: #011at org.traccar.Main.run(Main.java:152)
Jan 15 19:48:36 home-tracker traccar[1082]: #011at org.traccar.Main.main(Main.java:104)
Jan 15 19:48:36 home-tracker traccar[1082]: Caused by: java.lang.NullPointerException
Jan 15 19:48:36 home-tracker traccar[1082]: #011at org.traccar.helper.Log.setupDefaultLogger(Log.java:160)
Jan 15 19:48:36 home-tracker traccar[1082]: #011at org.traccar.Context.init(Context.java:361)
Jan 15 19:48:36 home-tracker traccar[1082]: #011at org.traccar.Main.run(Main.java:110)
Jan 15 19:48:36 home-tracker traccar[1082]: #011... 1 more
Jan 15 19:48:36 home-tracker systemd[1]: traccar.service: Main process exited, code=exited, status=1/FAILURE
Jan 15 19:48:36 home-tracker systemd[1]: traccar.service: Unit entered failed state.
Jan 15 19:48:36 home-tracker systemd[1]: traccar.service: Failed with result 'exit-code'.
Jan 15 19:48:37 home-tracker systemd[1]: Started MySQL Community Server.
Jan 15 19:48:37 home-tracker systemd[1]: Reached target Multi-User System.
Jan 15 19:48:37 home-tracker systemd[1]: Reached target Graphical Interface.

The error seems to be in the last entry key line as it will run without that?

Adrian

Anton Tananaev6 years ago

Make sure it's a valid XML file. For example & needs to be escaped as &amp;.

Adrian Hodgson6 years ago

Sorry did not get notification

I just tried to see if traccar would start with this config even though it would not work for me and it did.

    <entry key='database.driver'>com.mysql.jdbc.Driver</entry>
    <entry key='database.url'>jdbc:mysql://localhost:3306/traccardb?useSSL=false&amp;allowMultiQueries=true&amp;autoReconnect=true&amp;useUnicode=yes&amp;characterEncoding=UTF-8&amp;sessionVariables=sq$
    <entry key='database.user'>traccaruser</entry>
    <entry key='database.password'>traccarpass</entry>
    <entry key='filter.invalid'>true</entry>
    <entry key='logger.level'>info</entry>
    <entry key='tcp.timeout'>1200</entry>

    <entry key='geocoder.enable'>true</entry>
    <entry key='geocoder.type'>nominatim</entry>
    <entry key='geocoder.url'>http://nominatim.openstreetmap.org/reverse</entry>
    <entry key='geocoder.ignorePositions'>true</entry>

    <entry key='notificator.sms.manager.class'>org.traccar.sms.HttpSmsClient</entry>
    <entry key='sms.http.url'>https://api.txtlocal.com/send/</entry>
    <entry key='sms.http.template'>
        {
                "to": "{phone}",
                "body": "{message}"
        }
      </entry >
</properties>

So I was wondering about needing to use " but I will change the & to be &amp; and see how that goes, every language seems to have it's own formatting!

Adrian

Adrian Hodgson6 years ago

Well traccar service is running but I seem to have lost the web interface
"Service Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later."

I have not got a clue why, I have gone back to the traccar.xml before trying this and still have the same message. So not sure what is the issue at present, it could be the vhosts set up in apache2 and I can see that I can connect to the server at port 80 and it redirects the browser to https, port 8082 does nothing but that again may be sown to the redirect.

Time for a reboot of everything, I think

Adrian

Adrian Hodgson6 years ago

Think I may have found out why before I reboot.

A quick check of syslog pulled up this

Jan 15 21:52:20 home-tracker traccar[1594]: Exception in thread "main" java.lang.RuntimeException: liquibase.exception.LockException: Could not acquire change log lock.  Currently locked by 192.168.1.135 (192.168.1.135) since 1/15/19 8:06 PM
Jan 15 21:52:20 home-tracker traccar[1594]: #011at org.traccar.Main.run(Main.java:152)
Jan 15 21:52:20 home-tracker traccar[1594]: #011at org.traccar.Main.main(Main.java:104)
Jan 15 21:52:20 home-tracker traccar[1594]: Caused by: liquibase.exception.LockException: Could not acquire change log lock.  Currently locked by 192.168.1.135 (192.168.1.135) since 1/15/19 8:06 PM
Jan 15 21:52:20 home-tracker traccar[1594]: #011at liquibase.lockservice.StandardLockService.waitForLock(StandardLockService.java:230)
Jan 15 21:52:20 home-tracker traccar[1594]: #011at liquibase.Liquibase.clearCheckSums(Liquibase.java:1442)

It may or may not be the issue but I will try and fall back to an earlier mysql database backup and see if that works.
Adrian

Adrian Hodgson6 years ago

OK up and running again, I think that was because traccar had crashed out several times with the wrong xml config, but at least I have backups.

I have last question for tonight then a last try, and then sleep, am I correct in thinking that I need to have:-

<entry key='notificator.types'>web, mail, sms</entry>

and

<entry key='notificator.sms.manager.class'>org.traccar.smpp.SmppClient</entyry>

But I do not need

<entry key='sms.enable'>true</entry>

if I am only using sms for notifications and not sending commands to GPS devices?

When logged in as admin and I check users there are notifications settings there I can not remove, that will be for another day I think.

I will check both configs.

Adrian

Anton Tananaev6 years ago

Yes, you only need sms.enable if you use SMPP and want to send/receive messages to/from devices.

Adrian Hodgson6 years ago

Thank you

Adrian

Adrian Hodgson6 years ago

Gone midnight and still at it, sms is not working, is there a way to tell what I am sending out via https: do I need to change the logging level to debug and would I find the outgoing message in the traccar logs or do I need to look somewhere else?

Cheers

Adrian