Skip to content

SmartHome – Determine GPS data

Reading time 4 minutes

Aktualisiert – March 10, 2025

If you want to determine GPS data using SmartHome, for example to query local weather data, you can do this with a Teltonika router RUTX50 without additional hardware or software using Homematic / RaspberryMatic.

Basics

The Teltonika routers RUTX.. allow sending and receiving SMS via the activated SIM card. Likewise, sending position data in response to an SMS with the content “GPS password„.

You can view the SMS incoming list and SMS content via HTTP request. The current longitude and latitude information can be read from the SMS received in response to the SMS request.

These can now be further processed via script within the Smart Home automation using HomeMatic or RaspberryMatic. When traveling, the constantly changing geodata can be used for a constantly updated weather query based on the current location, for example via the free service from openweathermap.org to use.

Provider SMS-Einstellungen

Je nach Provider muss ggf. noch die im Router eingesetzte SIM-Karte für SMS freigeschaltet werden. Dies geschieht i.d.R. in den zugehörigen Einstellungen nach Einloggen auf der Provider-Webseite.

Während sog. Multi-Card-Angebote das Klingeln und Telefonieren auf allen mit einer solchen SIM-Karte ausgestatteten Geräten umsetzbar ist, wird SMS nur wahlweise auf EINER der SIM-Karten unterstützt!

Setup – Teltonika Router

Services – Mobile Utilities – SMS Gateway

  • Mobile Post/Get Settings – Enabled
  • Username: Login name
  • Password: LoginPassword

Services – Input/Output – Post/Get

  • I/O Post/Get Settings – Enabled
  • Username: Login name
  • Password: LoginPassword

Setup – RaspberryMatic

Install CUx daemon

The CUx daemon is an add-on that provides virtual devices within HomeMatic / RaspberryMatic, which can be used, among other things, as a less burdensome replacement for system calls, here for example for sending SMS via an HTTP request to the router.

The AddOn is installed via Settings - Additional Software, there in the lowest area you can download the AddOn file by clicking on the button Choose a file in the corresponding download folder on the computer and click on the button To install be loaded onto the center and installed.

CUx daemon – create device

The CUx daemon is called via the system by clicking on the button CUx daemon.

Click on the button at the top right Devices opens the interface. Top left, under CUxD Device Type, is from the list below system selected.

As a function the function becomes Exec selected, a corresponding name in the Name field, e.g GPS, entered and then clicked on the button Create device on the CCU, the device saved.

The created device then appears in the right window with its ID, e.g. CUX2801001, and can be addressed in scripts using this ID.

Scripts

Send SMS for GPS data output

The information in square brackets must be replaced with your own data:

string url=“‘http://[IP of the router]/cgi-bin/sms_send?username=[User name]&password=[password]&number=[International phone number]&text=[GPS password]'“;
dom.GetObject(“CUxD.CUX2801001:1.CMD_EXEC”).State(“wget -q -O – “#url);

Please note that the string is enclosed in double (“) AND single (‘) quotes!

This script will be in the program to be created GPS_Loc_Update called and the following script, which in turn calls the GPS_Data program, is offset by 30 seconds to wait for the SMS with the PÜS data to be received:

var programObj = dom.GetObject(“GPS_Data”);
programObj.ProgramExecute();

Program GPS_Loc_Update Can be scheduled once a day or at shorter intervals as required.

Output SMS list

In order to read out the GPS data, the router is asked to output the SMS list via an HTTP request.

This script requires two variables of the type STRING, which must be created under Settings - System Variables below by clicking on the New button:

  • W_Lat (to store the geographical latitude)
  • W_Lon (for storing the geographical longitude)

The content of the script (lines with leading exclamation mark are comments; WriteLine-Instructions are only used for output control and can be deleted.)):

var url = “http://[IP of the router]/cgi-bin/sms_list?username=[User name]&password=[password]“;

! Declaration of the variable
var posValueStart;
var posValueEnd;
var pos;
var data;
var posStart;
var posEnd; string stderr; string stdout;

! WGET command to transmit the HTTP request string to the router
system.Exec(“wget -q -O – ‘“#url#“‚”, &stdout, &stderr);

! Output of the query result for checking
WriteLine(stdout);

! Index: 1
! Date: Fri Jan 26 11:01:02 2024
! Sender: +49xxxxxxxxxxxxx
! Text: Fix time: 2024-01-26, 11:01:01 Latitude: 54.834682 Longitude: 12.040196 http://maps.google.com/?
! q=54.834682,12.040196&om=1speed:0
! Status: read

! Read out GPS data
pos = 0;
! Position of the start of the searched value
posStart = 'Latitude: ';
! Position of the end of the searched value
posEnd = ' Longitude: ';
posValueStart = stdout.Find(posStart) + posStart.Length();
posValueEnd = stdout.Find(posEnd)-posValueStart;
! the string you are looking for is:
string Latitude = stdout.Substr(posValueStart, posValueEnd);
! Conversion of the string (character string) into a floating point number
var lat = Latitude.ToFloat();
! Output of the geographical longitude for control
WriteLine(“Latitude”);WriteLine(Latitude);

! Save the geographical longitude into the variable W_Lat
dom.GetObject('W_Lat').State(lat);

pos = 0;
posStart = 'Longitude: ';
posEnd = 'http';
posValueStart = stdout.Find(posStart) + posStart.Length();
posValueEnd = stdout.Find(posEnd)-posValueStart;
string Longitude = stdout.Substr(posValueStart, posValueEnd);
var lon = Longitude.ToFloat();
WriteLine(“Longitude”);WriteLine(lon);

dom.GetObject('W_Lon').State(lon);

The program does not contain any conditions for execution because it is initiated via the above program or script.

Now the geographical information can be used to query the weather data for this location. For this purpose, another program is created that is started periodically using a timer, which uses a script to insert the two values into the HTTP request string of the above-mentioned weather service and thus takes the changing locations into account in the query.

Program W_Data_OWM

Composing the URL

! Loading the variables filled in GPS_Data W_Lat and W_Lon and assigning to the variables url_1 and url_2

var url_1 = dom.GetObject(“W_Lat”).Value();
WriteLine(“Lat=");WriteLine(url_1);
var url_2 = dom.GetObject(“W_Lon”).Value();
WriteLine(“Lon=");WriteLine(url_2);

! Composing the URL using the variable contents url_1 and url_2
! [xxxxxxxxxxxxxxxxxxxxxxxxx] represents the weather service API key received after registration
var url = “https://api.openweathermap.org/data/2.5/weather?lat=”#url_1#”&lon=”#url_2#”&appid=[xxxxxxxxxxxxxxxxxxxxxxxxxx]&units=metric”;
! Output of the complete string for checking
WriteLine(url);

This is followed by the same procedure of declaring the variables, the WGET command, outputting the query results for checking and reading out the desired weather data (see. documentation) according to the procedure given for GPS data.

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEnglish