BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

How can i “write code around it” and use the GPS streaming? I really want the GPS trigger on IOS


#1

How can i “write code around it” and use the GPS streaming? I really want the GPS trigger on IOS, or at least a solution for the meantime. Can anyone help me? I’m kind of a noob but i learn quick. I’ve read about Geofences but dont know how to write the code for one or how to use them. Thanks in advance!


IOS GPS trigger?
#2

The basic theory would be that you hard-code the latitude and longitude coordinates of your home into the Blynk sketch, then capture the results that come from the GPS Stream widget on your phone and compare the two. If either the latitude or longitude are different from your home coordinates by a pre-defined amount then you can deduce that your phone isn’t at home.
The latitude and/or longitude values from your phone could be greater or smaller than those of your home address, and can include negative values, so the mathematical comparison needs to account for this.

However, if you’re wanting this to work in the background so that your hardware detects if your phone has arrived at home and gets your slippers, pipe and smoking jacket ready for you then the Blynk app would need to be accessing and sending your location information constantly. This needs to keep accessing the location information of your phone will kill your battery fairly quickly.
I did s little test yesterday using my iPhone 6 (which recently had a new battery fitted). After about 3 hours of just having the phone in my pocket my battery was down to 35%, when I’d normally expect it to still be at around 95%.

This isn’t a Blynk thing per se, any app that constantly accessed your location datawill have the same effect.
You could set the location services permissions to only send data when the app is in use, but then you’d need to open the Blynk app for the hardware to know where you are - which defeats the object of the exercise for most scenarios.

There are other possible solutions, such as checking if your phone is connected to your home Wi-Fi network, but this isn’t 100 reliable as iOS devices go into sleep mode and don’t respond to pings after a while. There are some systems that can check your network routing table to see if the phone is present, but you’d probably need a Raspberry Pi for that.
Besides, you might want to know when the phone is getting near to home, not close enough to connect to the Wi-Fi network.

Pete.


#3

Thanks a lot Pete! I have a lot of reading to do. I’m currently trying to go about this problem using IFTTT location and a webhook to trigger a relay controlled with blynk. Theres a few other threads that talk about this topic more in detail so ill post my related questions there. Thanks again! (but feel free to leave a comment here if I’m totally on the wrong track :joy:)

(link for others who find this thread:
How to integrate Blynk and IFTTT (Google Assistant))


#4

It might be best to keep your questions/comments in this topic.
It’s sometimes annoying when someone adds a “me too” comment to an old topic, or hijacks a topic.

I’d never heard of IFTTT location until you mentioned it. Looking at the details it seems like a better solution, especially the battery life on iOS.
The look and feel of IFTTT seems to have changed dramatically at some point. Some of the previous guide topics may not apply now, so search the forum for IFTTT and look at the newer posts.

Two tips might help…

  1. use GET rather than PUT
  2. if you’re using Blynk Cloud then hard-code the IP address of the Blynk server that contains your project into the IFTTT ‘recipe’ to avoid Geo DNS issues.

Pete.


#5

Ok. Well if I’m gonna post my questions here; how do i get this to work :rofl:? I’m testing it with an LED instead of a relay & trying to use the http address in chrome browser to switch it on/off before testing it with ifttt. Ive read through all the newest posts concerning IFTTT Some people say use

http://139.59.206.133/043bc8b7142840c1a2405614a4f88d87/update/D1
or
http://139.59.206.133/043bc8b7142840c1a2405614a4f88d87/pin/D1
or
http://139.59.206.133/043bc8b7142840c1a2405614a4f88d87/pin/D1?value=1
or with:8080 after the IP
both with PUT & [“1”], or with GET.

I’d think https://blynkapi.docs.apiary.io/#reference/0/write-pin-value-via-put/write-pin-value-via-put?console=1 would ideally be the source of the info but i cant get it to work there either with “Write pin value via GET” or via PUT.

http://139.59.206.133/043bc8b7142840c1a2405614a4f88d87/V1?value=1 works (for example) with virtual pins, i can change (input) displays on the blynk app, but i cant get it to work with Digital pins (output) & actually turn the LED on/off.


#6

Are you using a NodeMCVU or Wemos D1 Mini?
If so, do you have the LED connected to the pin that’s labelled D5 on the board?

The command you’re using will change the value of GPIO5, which is labelled as D1 on these boards.

Pete.


#7

It woooooooooooooooooooorked!!!

Im using a Wemos D1 Mini. Why does D5 in the http command actually mean GPIO5 (which in turn is D1, super confusing :unamused:).
Anyway, i changed my D# in the http to signal the GPIO# & it worked.

So http://139.59.206.133/043bc8b7142840c1a2405614a4f88d87/update/D5?value=1 changed GPIO5 pin on. That also switches the Blynk button in the app. So i get some feedback that the LED (or relay) turned on.

Thanks so much Pete!!


#8

The question should really be “why have the NodeMCU/Wemos people chosen to number the pins this way?”
If you were using an Arduino then D5 in the API would turn on digital pin 5 - so everything makes sense except what Wemos have done.

There a bit more on which pins are the best ones to use here, which is worth reading:

You should generate a new auth code in the app and use that instead of the one you’re using, because now that you’ve shared your current one on a public forum anyone can activate your relay whenever they like!.

Has that answered your questions, or is there more on the geofencing issue?

Once you have it set-up and working fully, I’d like to see a write-up and some feedback about how well IFTTT Location works, as this seems like quite a good solution to use for this type of scenario.

Pete.


#9

So on an Arduino board, D5 = GPIO5? :thinking: That makes way more sense :rofl:.

Ill definitely read up on those Wemos pins! (new auth code is done but, that one i gave wasnt my exact one anyway).

That totally solves my Geofencing issue! Now that i can control the LED/relay through the Blynk server with an http command, i will test the IFTTT location function more. Ive got a few zone sizes to test the sensitifity & lag time (since theres a much longer lag time going through IFTTT than straight through Blynk). Then ill throw em together & post the results here :+1:


#10

Excellent!

I’ll mark this topic as “Solved”, but you can still post to it, and change it back to “Need Help…” if you want.

Pete.


#11

With the HTTP/API the D stands for Digital as opposed to V for Virtual, and in theory A for analog (although I have found analog need to use its digital pin reference at times - AKA Arduino A0 would need a D14 etc… :rabbit: trail :stuck_out_tongue: ).

API pin D1, NodeMCU silkscreened D1, Arduino GPIO/TX D1, Wemos D1 & Wemos D1 Mini … While these all look the same they are not always directly referencing the same thing… brand/use confusion for sure :crazy_face:


#12

So i tested out a few radii in the location function of IFTTT. Turns out when you set up the radius, you can zoom in quite a bit further on a computer than you can in the smartphone app (iphone for me). So i tested the standard radius & then used the computer to zoom in a bunch and create recipies to test every radius in between. Basically its not gonna get more exact than that standard radius of about 700ft (at that point almost all of my smaller geozones alerted too). But at that standard ~700tf distance it worked pretty well, got the notification that i entered the GeoFence zone & i checked my Blynk app & my LED was on :+1:. I can use this to hook up a relay for my lights or for a garage door opener or whatever. Would be cool to be more exact with the radii, maybe if it used wifi or bluetooth to finetune location somehow (it uses google maps, so I’m guessing just standard GPS coords.), but for now I’m glad it works!


#13

Wow, 700’ is a bit of a wide radius.
Where I live, if I had a garage and the door opened when I was 700’ from home, the local lowlife would have emptied it by the time I’d arrived home!

Maybe add a delay between the IFTTT webhook command being received and the door opening process starting? You’d need to use a virtual pin rather than a digital pin for that, but that’s not a problem and personally I never use digital pins with Blynk.

Pete.