Author |
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 12 2014 at 07:39 | IP Logged
|
|
|
on this page there is described how to Calculate distance, bearing and more between Latitude/Longitude points. If I would want to have PH calculate how far I am away from my home, how would I try to accomplish this using the link as a guide.
- my home lat/long is known in PH or could be stored as a GV
- my current place can be read by my android and sent through the internet to PH and also stored in a gv... perhaps through the browser or an APP...
- first PH has to be able to calculate the distance in a macro with the lats and longs in a gv...
Peter
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: November 12 2014 at 10:38 | IP Logged
|
|
|
Peter,
Already have you covered. Look at the ph_latlongdist function in the Help file.
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 12 2014 at 11:27 | IP Logged
|
|
|
Thanks Dave!
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: November 12 2014 at 17:44 | IP Logged
|
|
|
Wow! What made you add that, Dave?
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: November 12 2014 at 21:52 | IP Logged
|
|
|
Tony,
I was working on a plugin for PowerHome based upon Google latitude (before it went away) so that I could trigger events based upon how far away I was from home .
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 13 2014 at 00:38 | IP Logged
|
|
|
Can we resume work on this plugin based on new situations?
that is exactly what I thinking of.
Peter
Edited by krommetje - November 13 2014 at 00:45
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 14 2014 at 04:59 | IP Logged
|
|
|
I found this android app called GSPLOGGER 5.5 and this app is capable of various thing linke FTP, Email, but even openstreetmap and other servers. It is even capable of sending data to own URL's.
now what I would like to try is make the app call my own PH-server URL and write to 3 globals (Lat, Long, Serial)
first I tried:
Code:
From: 95.96.108.241
GET /ph-cgi/evalformula?formula=ph_setglobal_a("plat",
51.4567362)+ph_setglobal_a("plong",5.6372774)+ph-setglobal_a ("serial",0.0) HTTP/1.1
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.4.2; GT-I9205 Build/KOT49H)
Host: powerhome.krommetje.nl:9600
Connection: Keep-Alive
Accept-Encoding: gzip
|
|
|
[code]
url being used is:
http://username:password@myurl.com/ph-cgi/evalformula?formul a=ph_setglobal_a("plat"......
but no global is updated.... Anyone help?
Edited by krommetje - November 14 2014 at 06:49
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: November 14 2014 at 06:51 | IP Logged
|
|
|
You need to use something that passes your credentials with the formula.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 14 2014 at 07:24 | IP Logged
|
|
|
TonyNo wrote:
You need to use something that passes your credentials with the formula. |
|
|
isn't this enough?
http://username:password@myurl.com
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 14 2014 at 07:45 | IP Logged
|
|
|
I am getting:
Syntax Error in Formula: ph_setglobal_s(~"plat~",
~"51.4593756~") ph_setglobal_s(~"plong~",~"5.6332753~")
the + sign used in the formula is not transferred
Edited by krommetje - November 14 2014 at 07:52
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 14 2014 at 08:35 | IP Logged
|
|
|
ph_settemps("%LAT","%LONG"," ",0,0) is also an error evenb though it evaluates in PH as OK...
I've got the Lat Global changed, the LONG not yet....
when I substitute the & for a + the whole fomula evelauates as Synthax error....
Edited by krommetje - November 14 2014 at 08:41
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: November 14 2014 at 12:38 | IP Logged
|
|
|
Peter,
You'll need to escape the "+" sign with %2b. I would also use the ph-cgi eval function (which will return the result of the formula) vs the evalformula function which will return the internal webserver evalformula page. The url I just tested and comfirmed working was:
http://192.168.0.10:8000/ph-cgi/eval?formula=ph_setglobal_a( "MOTIONCNT","0") %2b ph_setglobal_a("DOORCNT",2)
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 15 2014 at 02:45 | IP Logged
|
|
|
Dave,
that did it! HOWEVER: no space is allowed between the 2 formulas, notation has to be like this:
...eval?formula=ph_setglobal_a( "MOTIONCNT","0")%2bph_setglobal_a("DOORCNT",2)
now I can continue with a trigger and some more ideas I have.
Peter
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 15 2014 at 05:09 | IP Logged
|
|
|
Dave....
tell me:
My home Lat / Long is N51.4567405 E5.6372489 and I stored these both in a global: HOMELAT and HOMELONG.
when my andoid sends its gps measurements and I am at home....When I run this formula:
Code:
ph_latlongdist(ph_getglobal_n("HOMELONG"), ph_getglobal_n("HOMELAT"), ph_getglobal_n("PLAT"), ph_getglobal_n("PLONG1"))
|
|
|
I get a distance of 4172,414678127143
The helpfile says the result is returned in KM....
What is wrong here?
Edited by krommetje - November 15 2014 at 05:10
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 15 2014 at 08:41 | IP Logged
|
|
|
see this log I made going from home to the grocerystore (about 2 miles or 3-4 kilometer):
[code]
Date and Time--------Latitude--Longitude--Calculated distance
2014-11-15 12:36:52 51.4589887 5.6342066G 4172,414678127143
2014-11-15 12:38:01 51.4567578 5.6373025G 5393,602000218917
2014-11-15 12:39:08 51.4567547 5.637272G 1982,395196258448
2014-11-15 12:40:13 51.45654829 5.63761807G 15364,64940214777
2014-11-15 12:56:38 51.4672545 5.6354296G 11635,39412155462
2014-11-15 12:57:41 51.4642158 5.6270593G 11974,40785579967
2014-11-15 12:58:42 51.4642158 5.6270593G 11974,40785579967
2014-11-15 12:59:43 51.4672422 5.6356227G 14729,24492109461
2014-11-15 13:00:46 51.4672939 5.6354344G 7791,074222543259
2014-11-15 13:01:46 51.4672851 5.6354328G 17590,30734164736
2014-11-15 13:02:48 51.467268 5.6354344G 15448,56762841154
2014-11-15 13:03:51 51.4672653 5.6349918G 281,0511281208597
2014-11-15 13:04:54 51.4672653 5.6349918G 281,0511281208597
2014-11-15 13:05:54 51.4672653 5.6349918G 281,0511281208597
2014-11-15 13:06:57 51.4672653 5.6349918G 281,0511281208597
2014-11-15 13:07:59 51.4672653 5.6349918G 281,0511281208597
2014-11-15 13:08:58 51.4672653 5.6349918G 281,0511281208597
2014-11-15 13:10:01 51.4672653 5.6349918G 281,0511281208597
2014-11-15 13:11:01 51.4672653 5.6349918G 281,0511281208597
2014-11-15 13:12:00 51.4672653 5.6349918G 281,0511281208597
2014-11-15 13:13:03 51.4672653 5.6349918G 281,0511281208597
2014-11-15 13:14:02 51.468811 5.6425697G 13163,40795701733
2014-11-15 13:15:03 51.4668921 5.6349016G 14273,70004337114
2014-11-15 13:16:03 51.4654549 5.6345208G 11333,01337879344
2014-11-15 13:17:07 51.4629227 5.6331901G 15143,39375639444
2014-11-15 13:18:08 51.4623631 5.6329602G 6536,043295520513
2014-11-15 13:19:09 51.4602688 5.6320511G 13457,85428609073
2014-11-15 13:20:11 51.4563162 5.6318432G 5294,655893650398
2014-11-15 13:21:12 51.4301861 5.6203696G 1113,452463624386
2014-11-15 13:22:15 51.4589887 5.6342066G 4172,414678127143
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: November 15 2014 at 11:16 | IP Logged
|
|
|
Peter,
On my system, I ran the following formula:
ph_latlongdist(51.4567405,5.6372489,51.4589887,5.6342066)
and get a return of 0.3269925583113723. The first two vals are your stored lat/long and the next two vals are the first lat/long from your list.
Couple of things I can think of. You say your home values are stored in globals as N51.4567405 E5.6372489. Im assuming that the N and E are not part of the stored value as that will be a problem. In your list of values, I see the longitude has a G at the end. I assume that also isnt there. The other thing I see is that your lat/long values have a decimal point when based upon your locale, I believe the decimal should be a comma (like in the calculated distance result).
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 16 2014 at 07:03 | IP Logged
|
|
|
alright, the app on my droid sends it data with a . and not with a , if I calculate the distance with all GV's I still get a wrong distance, however if I calculate the distance with ph_latlongdist(51.4567405,5.6372489, ph_getglobal_n("PLAT1"), ph_getglobal_n("PLONG1")) then the distance is correct....The globals plat1 and plong1 contain Lat and Long with a comma .... Substituting the comma for a decimal point gets a wrong distance again......
this leaves me with the authentication problem. URL authentication like http://login:password@myurl.com... does not work with PH... Should I set the Authentication in the explorer to Basic?
Edited by krommetje - November 16 2014 at 08:00
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: November 16 2014 at 11:38 | IP Logged
|
|
|
Peter,
Another thing I think you can do is use the ph_number
function. Something like:
ph_latlongdist(ph_number("51,4567405"),ph_number("5,63724
89"),ph_number(ph_getglobal_s("PLAT1")),
ph_number(ph_getglobal_s("PLONG1")))
However, if you've got it working for you already, then I
would probably just stick with that.
Concerning authentication, if you're using SSL or cookie
authentication with PowerHome, then the userid and
password in the URL will not work and you would have to
switch to basic authentication. However, what has worked
for me on my phone was to use the built in browser to go
to PowerHome with cookie authentication, go through the
login process and retrieve the cookie. Most applications
that use the built in browser for communication now work.
The ones that dont, some of them have an option to supply
a cookie and I'll supply the cookie that the browser
retrieved. Basic authentication should solve the issue
for you however.
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: November 19 2014 at 04:24 | IP Logged
|
|
|
Dave,
no matter what I do, the distance still calculates wrong, see this screenclip:
the Lat/Long is sent OK but I still keep stumblin'on this decimal/comma item... your formula does not work either...
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: November 19 2014 at 11:52 | IP Logged
|
|
|
Peter,
In the PH multi-editor, what do you get when you run the following functions:
Code:
ph_latlongdist(ph_number("51.4567405"),ph_number("5.6372489" ),ph_number("51.4589887"),ph_number("5.6342066")) |
|
|
and
Code:
ph_latlongdist(ph_number("51,4567405"),ph_number("5,6372489" ),ph_number("51,4589887"),ph_number("5,6342066")) |
|
|
Dave.
|
Back to Top |
|
|