Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include current regions in "location" payload #523

Closed
krambriw opened this issue Mar 21, 2018 · 22 comments
Closed

Include current regions in "location" payload #523

krambriw opened this issue Mar 21, 2018 · 22 comments
Assignees

Comments

@krambriw
Copy link

Hi,
Working with the above command, would it possible to add desc to the response to the above command? (maybe this is not only for ios)
Like
location: object
lat: 59.42870689075506
lon: 18.005181523421005
name: "wk"
desc: "waypoint name" // the current waypoint the device is in or "none" if not inside any

@ckrey ckrey self-assigned this Mar 21, 2018
@ckrey
Copy link
Member

ckrey commented Mar 21, 2018

A device may be in multiple overlapping regions/waypoints at the same time.

A possible extension would be to add an array of regions the device is currently in. Obviously this would be limited to all locations the owner of the device has marked as "shared".

{"_type":"location",...,"regions":["waypoint name1","waypoint name2"]}

What is the use case for such an extension? For shared waypoints, the backend already receives the definitions of waypoints and enter/leave events.

@krambriw
Copy link
Author

Hi Christoph,
My idea was to have a background routine in my HA system that just regularly cross-check to complement the enter/leave events. Reason is, I have seen that the order of received events can be mixed up wrongly. This actually happened now. I was in a waypoint and left towards the next waypoint (Home). The system received all events but I received the "enter" Home before the "leave" event for the previous waypoint arrived. Also the time stamps in the message was not helping in sorting the events correctly, they indicated that I "entered" Home before I left the previous waypoint.

Kind regards, Walter

@ckrey
Copy link
Member

ckrey commented Mar 21, 2018

you know that the iOS app is not always on. This means it will not process a reportLocation request instantaneously.

Show us an example of the incoming messages.

@krambriw
Copy link
Author

krambriw commented Mar 21, 2018

Yes, for sure. Below is the example, I did not expand the usual location messages and I removed most of those in between the events. I'm using Node-RED and "significant location changes". It could be that the sorting in Node-RED only has resolution in seconds...but I guess other systems might be affected as well. Log file is attached. I have 3 waypoints defined; "Home", "ICA Häggvik" and "Rackethallen". (The event order is actually also wrong for those)

Maybe a sequential message counter in the event would be enough to allow for correct sorting in the post processing? If it makes sense or is simpler

Kind regards, Walter

Owntracks log.txt

@ckrey
Copy link
Member

ckrey commented Mar 21, 2018

Thanks Walter for sharing this,

the enter/leave monitoring is done by iOS, not by the app (which is suspended anyhow).

For some reason the enter home detection happens 6 seconds before the leave Rackethallen is detected and reported. Even a message counter would not change the sequence.

Nothing we can do because the app is not always on and does not evaluate position changes itself.

@krambriw
Copy link
Author

I see, understoood
It is around 3 km between home and rackethallen and I was driving by car...not too fast ;)
Just another one, would it be possible to add the desc to normal location messages? They seem to be rather frequent also when in "significant location changes" mode? If I had those, I could at least synchronize "as good as possible"

@krambriw
Copy link
Author

Hello Christoph,
Coming back to this topic. Well, now I have some experience with how the iPhone is updating location changes etc
But what about activating the GPS? Is this something that can be done when Owntracks is running in the background?

I mean the following scenario:

a) I send a "reportLocation" command (with a GPS flag set)

  1. Owntracks running in any mode receives the command via MQTT
  2. turns on the GPS
  3. reads the location lon/lat
  4. turns off the GPS
  5. checks if inside any defined regions
  6. returns the response with location and "currently in regions" back to the MQTT broker

Is this possible? If so you would have a possibility to actively "poll" for actual location and "wake up" the iPhone

Kind regards, Walter

@ckrey
Copy link
Member

ckrey commented Apr 9, 2018

We could add the names of all shared Regions which the device is currently in to all "_type":"location" messages as in

  {
    "batt": 88,
    "lon": 5,
    "acc": 10,
    "vel": 0,
    "vac": 4,
    "lat": 50.1,
    "inregions": [
      "Another Region",
      "Home"
    ],
    "t": "c",
    "conn": "w",
    "tst": 1523284733,
    "alt": 42,
    "_type": "location",
    "tid": "CE"
  }

@ckrey ckrey changed the title Include desc in response to {"_type":"cmd","action":"reportLocation"} Include current regions in "location" payload Apr 9, 2018
@krambriw
Copy link
Author

krambriw commented Apr 9, 2018

I think that such enhancement would be very useful. I have noticed that the "location" event is received by my Node-RED application rather "frequent", like once every 10 minute or so if I remember correctly ( I will do some more logging) also when Owntracks is set to "significant location changes". This could eventually make it possible to "predict" arrival/departure to/from a region before the enter/leave event is received. Also if, for some reason, the enter/leave event is missed, you could synch up in the application when next location event arrives
Kind regards, Walter

@ckrey ckrey added the fixed label May 4, 2018
@ckrey
Copy link
Member

ckrey commented May 4, 2018

done, will be available in Version 9.8.6+

ckrey added a commit that referenced this issue May 4, 2018
ckrey added a commit that referenced this issue May 6, 2018
    [NEW] use MQTT V5 library
    [NEW] Include desc in _type=beacon messages #521
    [NEW] translation (PL) update

    [FIX] Drop AppleWatch support because Apple stops Watchkit 1 support
    [FIX] Drop Support for iOS < 11.0, older iOS versions use old version
    [FIX] Drop Addressbook links via Relation "owntracks" / "updateaddressbook"
    [FIX] Replace deprecated UIAlertView
    [FIX] Replace deprecated UILocalNotification
    [FIX] Replace deprecated AddressBook interface
    [FIX] show matching files when selecting certificates only
    [FIX] Crash in TodayViewController on iOS 9.3.5 iPhone4S #528
    [FIX] Crash when accessing Address Book #529
    [FIX] Crash when requesting reportLocation #527
    [FIX] Crash in ConnectionType #526
    [FIX] update lastUsedLocation immediately
@krambriw
Copy link
Author

Hi Christoph, great!!!
When do you think it will be @ appstore (for upgrading purpose)?
Kind regards, Walter

@jpmens
Copy link
Member

jpmens commented May 15, 2018

It will be submitted to the App Store for approval once we’ve tested it and have submitted it. This will happen exactly when we think it is ready and neither earlier nor later. (I’m not being sarcastic: this is the response you should expect from an Open Source project. :-) )

@krambriw
Copy link
Author

Well, I have managed sw development professionally in multinational companies the last 25 years so sw quality, I know what matters and of course I appreciate due professional care in every step
I just thought you had a rough idea where you are in that phase (like 40% done). With such popular and widely used app, I would presume you have some kind of plans and testing schemes/specs and you should actually know the status

@ckrey
Copy link
Member

ckrey commented May 16, 2018

@krambriw a good read on who we are and what we do is here https://blog.opencagedata.com/post/interview-jp-mens-owntracks

@ckrey
Copy link
Member

ckrey commented May 17, 2018

@krambriw if you share an email address with us, we will include you in our beta-tester group

@krambriw
Copy link
Author

krambriw commented May 19, 2018

Hello, a first report: beta version 9.8.12 is working fine with the new feature "inregions". I think this is a very valuable feature when integrating/interfacing with other systems since the data can be used to synchronize the state if the leave/enter messages are missed for some reason.

I have attached part of my log file showing location & transition messages. In my house I have a "mid range" iBeacon (powered by USB) with an estimated coverage radius of approx 100 m. I have also defined a normal "Home" region for the same, also with 100 m radius just to compare how well entering/leaving is detected. So far it looks like they are detected at the same moment. Could it be that the iBeacon connection somehow "is helping" the app to get a network connection, some higher priority in iOS supporting BLE connections??

2018-05-19 11:12
{"batt":100,"lon":18.005110195262557,"acc":65,"p":102.05797576904297,"vac":10,"lat":59.428773424623124,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"u","_cp":1,"conn":"w","tst":1526721166,"alt":28,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 11:12
{"tst":"1526617158","_type":"lwt"}
2018-05-19 12:26
{"batt":100,"lon":18.004935764523758,"acc":65,"p":102.04998779296875,"vac":10,"lat":59.42871426518089,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"u","_cp":1,"conn":"w","tst":1526725554,"alt":27,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 12:39
{"batt":100,"lon":18.00463856272432,"acc":65,"p":102.0481185913086,"vac":10,"lat":59.428545915125966,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"p","_cp":1,"conn":"w","tst":1526726368,"alt":26,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 13:19
{"tst":"1526617158","_type":"lwt"}
2018-05-19 13:21
{"t":"b","tst":1526728756,"acc":65,"_type":"transition","event":"leave","lon":18.003315845535074,"lat":59.428483162584044,"wtst":1522853049,"tid":"wk","desc":"EBEFD083-70A2-47C8-9837-E7B5634DF524"}
2018-05-19 13:21
{"batt":100,"lon":18.003315845535074,"acc":65,"p":102.05799865722656,"vac":10,"lat":59.428483162584044,"inregions":["Home"],"t":"b","_cp":1,"conn":"m","tst":1526728756,"alt":25,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 13:21
{"t":"c","tst":1526728765,"acc":65,"_type":"transition","event":"leave","lon":18.00192110626567,"lat":59.428318919405,"wtst":1526638546,"tid":"wk","desc":"Home"}
2018-05-19 13:21
{"batt":100,"lon":18.00192110626567,"acc":65,"p":102.0635757446289,"vac":10,"lat":59.428318919405,"inregions":[],"t":"c","_cp":1,"conn":"m","tst":1526728765,"alt":24,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 13:21
{"batt":100,"lon":18.00498212854104,"acc":65,"p":102.07757568359375,"vac":23,"lat":59.420103160822215,"inregions":[],"_cp":1,"conn":"m","tst":1526728871,"alt":24,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 13:26
{"batt":100,"lon":18.04621349531665,"acc":165,"p":102.00126647949219,"vac":143,"lat":59.42187900417511,"inregions":[],"_cp":1,"conn":"m","tst":1526729204,"alt":22,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 13:26
{"batt":100,"lon":18.04621349531665,"acc":165,"p":102.00126647949219,"vac":143,"lat":59.42187900417511,"inregions":[],"_cp":1,"conn":"m","tst":1526729203,"alt":22,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 13:55
{"batt":100,"lon":18.04570692538321,"acc":65,"p":101.98621368408203,"vac":10,"lat":59.421452147500474,"inregions":[],"_cp":1,"conn":"m","tst":1526730413,"alt":26,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 13:56
{"batt":100,"lon":18.040374008185005,"acc":165,"p":101.96086883544922,"vac":46,"lat":59.418483441561285,"inregions":[],"_cp":1,"conn":"m","tst":1526730957,"alt":24,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 14:07
{"batt":100,"lon":17.998751873684878,"acc":65,"p":102.0804672241211,"vac":37,"lat":59.42591147978409,"inregions":[],"_cp":1,"conn":"m","tst":1526731216,"alt":26,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 14:07
{"t":"c","tst":1526731266,"acc":65,"_type":"transition","event":"enter","lon":18.004142394328227,"lat":59.42835015128096,"wtst":1526638546,"tid":"wk","desc":"Home"}
2018-05-19 14:07
{"batt":100,"lon":18.004142394328227,"acc":65,"p":102.0804672241211,"vac":10,"lat":59.42835015128096,"inregions":["Home"],"t":"c","_cp":1,"conn":"m","tst":1526731266,"alt":26,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 14:07
{"t":"b","tst":1526731268,"acc":65,"_type":"transition","event":"enter","lon":18.00414720064485,"lat":59.42835307117884,"wtst":1522853049,"tid":"wk","desc":"EBEFD083-70A2-47C8-9837-E7B5634DF524"}
2018-05-19 14:07
{"batt":100,"lon":18.00414720064485,"acc":65,"p":102.0491943359375,"vac":10,"lat":59.42835307117884,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"b","_cp":1,"conn":"m","tst":1526731268,"alt":26,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 14:07
{"batt":100,"lon":18.00484056664544,"acc":65,"p":102.00895690917969,"vac":10,"lat":59.42870804220424,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"_cp":1,"conn":"w","tst":1526731650,"alt":27,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 14:43
{"batt":100,"lon":18.00512232541045,"acc":65,"p":102.00580596923828,"vac":10,"lat":59.428772045728174,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"p","_cp":1,"conn":"w","tst":1526733216,"alt":27,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 14:43
{"batt":100,"lon":18.00512002914765,"acc":65,"p":102.00297546386719,"vac":10,"lat":59.42876989183893,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"p","_cp":1,"conn":"w","tst":1526733788,"alt":27,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 15:48
{"batt":99,"lon":18.004844706252403,"acc":65,"p":101.97032165527344,"vac":10,"lat":59.42868441154024,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"p","_cp":1,"conn":"w","tst":1526737708,"alt":27,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 16:17
{"batt":99,"lon":18.004844706252403,"acc":65,"p":101.97032165527344,"vac":10,"lat":59.42868441154024,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"p","_cp":1,"conn":"w","tst":1526737708,"alt":27,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 16:17
{"batt":98,"lon":18.004818896982968,"acc":65,"p":101.9740982055664,"vac":10,"lat":59.42869215883138,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"p","_cp":1,"conn":"w","tst":1526739421,"alt":27,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 17:19
{"batt":98,"lon":18.0049384780233,"acc":65,"p":101.97350311279297,"vac":10,"lat":59.42866365925021,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"p","_cp":1,"conn":"w","tst":1526742453,"alt":27,"_type":"location","tid":"wk","name":"wk"}
2018-05-19 17:19 {"batt":96,"lon":18.004730830213852,"acc":65,"p":101.955322265625,"vac":10,"lat":59.4286167126659,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"p","_cp":1,"conn":"w","tst":1526742968,"alt":27,"_type":"location","tid":"wk","name":"wk"}

@krambriw
Copy link
Author

Hello, a 2nd report: beta version 9.8.12, running in "significant changes" mode

I have now increased the normal "Home" region radius to 500 m just to see if entering/leaving events would be detected earlier/later than compared with the iBeacon events. It looks like this made no difference, all events (including those in queue) are transmitted in the same moment, i.e. when the iBeacon signal is recognized or considered lost by the iPhone BLE.

It "feels" as if a bluetooth connection/disconnection somehow is able to "wake up" the iPhone just enough and then, when this happens, also allow Owntracks to use the network. As I said, just my feeling, maybe you have some better insights

To get a more "immediate" detection when leaving/entering regions I assume you need either to use iBeacons or maybe run the app in "move mode"

The new feature "inregions" is anyway very useful in order to synchronize with my other systems

@krambriw
Copy link
Author

Hello, a 3rd report: beta version 9.8.12, running in "significant changes" mode

Noticed one thing - my iPhone has been in the same position but somehow one entry in the array "inregions" shows that it can drop out of a region anyway - and after a while it comes back.
The region that falls out is a normal "virtual" region, in my case named "Home". The iBeacon region seems to never fall out

2018-05-26 17:23:57 [ "Home", "EBEFD083-70A2-47C8-9837-E7B563…" ]
2018-05-26 17:23:57 [ "Home", "EBEFD083-70A2-47C8-9837-E7B563…" ]
2018-05-26 17:23:58 [ "EBEFD083-70A2-47C8-9837-E7B563…" ]
2018-05-26 17:33:02 [ "EBEFD083-70A2-47C8-9837-E7B563…" ]
2018-05-26 18:28:07 [ "Home", "EBEFD083-70A2-47C8-9837-E7B563…" ]
2018-05-26 18:28:07 [ "Home", "EBEFD083-70A2-47C8-9837-E7B563…" ]

@ckrey
Copy link
Member

ckrey commented May 30, 2018

Thanks for testing.
re 2nd Report: The Phone is woken up by iOS when it leaves the iBeacon region or when it leaves the circular region.
In the latter case, this depends on the GPS coverage and the availability of other position sources (Celltower, WLAN) including accuracy. Both is managed by iOS.
E.G. In my environment the circular region (50m) leave event is triggered approximately in a distance of 150m from my home

re 3rd:
would you share the "acc" (accuracy) values for your example lines

@krambriw
Copy link
Author

Thank you very much for providing this nice app!
Inputs and additional info provided below
My kind regards,
Walter

2nd: ok, thanks for the explanation, understood

3rd: here the corresponding lines with more details (I just add date & time to the complete payload when logging). My iPhone is mostly connected to the mobile network 4G, rarely using wifi.

2018-05-26 17:23 {"batt":100,"lon":18.004967092156743,"acc":65,"p":102.43795013427734,"vac":10,"lat":59.42884144721297,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"p","_cp":1,"conn":"m","tst":1527347361,"alt":50,"_type":"location","tid":"wk","name":"wk"}
2018-05-26 17:23 {"batt":100,"lon":18.003464436617637,"acc":2000,"p":102.42120361328125,"vac":10,"lat":59.42102187399951,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"p","_cp":1,"conn":"m","tst":1527347910,"alt":50,"_type":"location","tid":"wk","name":"wk"}
2018-05-26 17:23 {"batt":100,"lon":18.003303569785253,"acc":2000,"p":102.41483306884766,"vac":10,"lat":59.420184749362,"inregions":["EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"p","_cp":1,"conn":"m","tst":1527348236,"alt":50,"_type":"location","tid":"wk","name":"wk"}
2018-05-26 17:33 {"batt":100,"lon":18.005101068132223,"acc":48,"p":102.41502380371094,"vel":0,"vac":3,"lat":59.428695140500245,"inregions":["EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"p","_cp":1,"conn":"m","tst":1527348781,"alt":27,"_type":"location","tid":"wk","name":"wk"}
2018-05-26 18:28 {"batt":100,"lon":18.001731407266703,"acc":2000,"p":102.41597747802734,"vac":36,"lat":59.42565393206989,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"p","_cp":1,"conn":"m","tst":1527350601,"alt":28,"_type":"location","tid":"wk","name":"wk"}
2018-05-26 18:28 {"batt":100,"lon":18.00149798356864,"acc":2000,"p":102.38890838623047,"vac":32,"lat":59.42649027754776,"inregions":["Home","EBEFD083-70A2-47C8-9837-E7B5634DF524"],"t":"p","_cp":1,"conn":"m","tst":1527352086,"alt":28,"_type":"location","tid":"wk","name":"wk"}

@ckrey
Copy link
Member

ckrey commented May 30, 2018

you can see that the accuracy drops to +-2000 meters at 17:23 and the location lat/lon changes quite a bit at that time. Then the phone assumes you are not at "Home"

When acc comes back to +-65 meters, you are back "Home".

Accuracy values of a few 1000 meters are typical when the phone has no GPS fix and needs to rely on Cell Tower positioning. If you switch on WLAN, accuracy will probably be better if your WLAN access point is known...

@krambriw
Copy link
Author

I see, right, that sorts this thing out, understood. I will use WLAN for some days and do some testing with that as well just to verify & see the difference

@ckrey ckrey closed this as completed Jun 5, 2018
alyssaharvey3 pushed a commit to alyssaharvey3/ios-dev that referenced this issue Oct 18, 2022
zarakarlsson628 added a commit to zarakarlsson628/ios-dev that referenced this issue Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants