Logic Machine Forum
How to integrate a geolocalisation and LM? - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: How to integrate a geolocalisation and LM? (/showthread.php?tid=83)



How to integrate a geolocalisation and LM? - buuuudzik - 27.09.2015

Hello,

Have you any experience in the integration of geolocation of mobile phone and using this service in home logic?

Where can I download an information about the location of user's iPhone? Do I have to install some additionall app on iPhone?


RE: How to integrate a geolocalisation and LM? - admin - 28.09.2015

You can use SVG+JavaScript to access HTML5 Geolocation functions , more info here:
http://www.w3schools.com/html/html5_geolocation.asp


RE: How to integrate a geolocalisation and LM? - buuuudzik - 28.09.2015

(28.09.2015, 06:15)admin Wrote: You can use SVG+JavaScript to access HTML5 Geolocation functions , more info here:
http://www.w3schools.com/html/html5_geolocation.asp

Thank you for your answer but your solution works only when the User cell phone running and browser running on it and we do not know who is it because there can be more than 1 user logged on LM.

I've meant some solution with app running on iPhone and sending its position regularly to a server. And LM would be downloading this information from a server.

Do you know about some Google APIs?


RE: How to integrate a geolocalisation and LM? - admin - 28.09.2015

Can you explain what kind of solution are you trying to make? There are some Android and iOS apps which allow sending GPS coordinates periodically to a server via HTTP or raw TCP.


RE: How to integrate a geolocalisation and LM? - buuuudzik - 29.09.2015

(28.09.2015, 08:07)admin Wrote: Can you explain what kind of solution are you trying to make? There are some Android and iOS apps which allow sending GPS coordinates periodically to a server via HTTP or raw TCP.

Yes, this is what i am searching but do you know some solution where server has some API where you can find HTTP commands to make a communication?

I'd like to use the user's location to e.g. change the mode of HVAC or something else what would be suited and will be a good and comfort solution for my client.

This solution is available in Fibaro. This advertisment shows that function:
https://www.youtube.com/watch?v=K35uFXoa5c0


RE: How to integrate a geolocalisation and LM? - gjniewenhuijse - 29.09.2015

(29.09.2015, 07:34)buuuudzik Wrote:
(28.09.2015, 08:07)admin Wrote: Can you explain what kind of solution are you trying to make? There are some Android and iOS apps which allow sending GPS coordinates periodically to a server via HTTP or raw TCP.

Yes, this is what i am searching but do you know some solution where server has some API where you can find HTTP commands to make a communication?

I'd like to use the user's location to e.g. change the mode of HVAC or something else what would be suited and will be a good and comfort solution for my client.

This solution is available in Fibaro. This advertisment shows that function:
https://www.youtube.com/watch?v=K35uFXoa5c0

You can look at the Traccar Client app.


RE: How to integrate a geolocalisation and LM? - edgars - 15.11.2016

Here is a ready example for Geolocalization with LogicMachine based on Traccar service:
http://openrb.com/geolocalization-with-lm-based-on-traccar-service

Thanks to buuuudzik for this nice step-by-step guide! Smile


RE: How to integrate a geolocalisation and LM? - gjniewenhuijse - 15.11.2016

nice code Smile

The code string.split doesn't work for me:
time = string.split(time, '.')[1]


RE: How to integrate a geolocalisation and LM? - buuuudzik - 15.11.2016

(15.11.2016, 15:43)gjniewenhuijse Wrote: nice code Smile

The code string.split doesn't work for me:
time = string.split(time, '.')[1]

If you have some devices and some data received from them this should work. Firstly check errors and alerts.

If this won't be a solution then log the whole response by insert this line:
log(response)

but you must add above line after this code:
Code:
-- decoding received data
response = table.concat(t)
response = json.decode(response)

And please check what is in "Logs" section.


RE: How to integrate a geolocalisation and LM? - gjniewenhuijse - 15.11.2016

yes i have data, for example:
[fixTime]
   * string: 2016-11-15T16:04:04.000+0000

But i think the problem is the general loaded string.split function:
Code:
-- split a string into a table
function string:split( inSplitPattern, outResults )
 if not outResults then
   outResults = { }
 end
 local theStart = 1
 local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
 while theSplitStart do
   table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
   theStart = theSplitEnd + 1
   theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
 end
 table.insert( outResults, string.sub( self, theStart ) )
 return outResults
end



RE: How to integrate a geolocalisation and LM? - buuuudzik - 15.11.2016

(15.11.2016, 16:13)gjniewenhuijse Wrote: yes i have data, for example:
[fixTime]
   * string: 2016-11-15T16:04:04.000+0000

But i think the problem is the general loaded string.split function:
Code:
-- split a string into a table
function string:split( inSplitPattern, outResults )
 if not outResults then
   outResults = { }
 end
 local theStart = 1
 local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
 while theSplitStart do
   table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
   theStart = theSplitEnd + 1
   theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
 end
 table.insert( outResults, string.sub( self, theStart ) )
 return outResults
end

What are the symptoms of problem? This function should work especially stringConfusedplit(it produce the table of a few data which before was in one string separated via separator).


RE: How to integrate a geolocalisation and LM? - admin - 16.11.2016

Or you can use a single regexp instead of many splits Smile

Code:
date = '2016-11-15T16:04:04.000+0000'
d = {}
d.year, d.month, d.day, d.hour, d.min, d.sec = date:match('(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)')
time = os.time(d)



RE: How to integrate a geolocalisation and LM? - buuuudzik - 16.11.2016

(16.11.2016, 07:35)admin Wrote: Or you can use a single regexp instead of many splits Smile

Code:
date = '2016-11-15T16:04:04.000+0000'
d = {}
d.year, d.month, d.day, d.hour, d.min, d.sec = date:match('(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)')
time = os.time(d)

Very short and elegant solutionWink string:match is powerful toolWink