I have try “spark/device/ip” but when I was able to get it to work, my other subscriptions stop working. I wasn’t sure if I was having some string/pointer issue or I was just using it wrong. That is why I was looking for alternatives.
In the example below, the other two subscriptions are working fine, but “spark/device/ip” is not. @dave could you help me figure out what am I doing wrong? Thanks.
Same over here. Neither in your code or my code the other subscriptions stop working. They always work.
The problem now is that “spark/device/ip” doesn’t work. Even when I strip down the code to have only the IP subscription. Is this what you are seeing as well?
I’m sorry I haven’t had time to dig back into this recently, so many things happening at once! I think I’ll have more time early next week to revisit these, sorry about the delay.
I had this working once, but recall I started having issues with subscription/publish so I pulled the code. Don’t know if it will help. I might have had issues because I called the publish for the IP in setup? I striped down the code for this posting.
I think this is code has a race condition. When you do the subscribe, a Spark protocol request is queued up to notify the cloud that you want to listen to events of the given name etc. Then when you do the publish the cloud gets a request that should trigger the subscribe, but you didn’t give any time for the subscribe request to be completed and processed before the publish came in.
By putting some delay between these call I was able to make it work fine:
I was able to isolate a repro of the issue. In a nutshell, what I have found is that when one subscribes to a webhook, “spark/device/ip” stops working. It only happens with webhooks, “spark/device/ip” works fine with other subscriptions.
@dave let me know if I’m mission something obvious here.
There are many things wrong with this code that make it difficult to tell where the bug might be. Let’s just focus on the non-working, second case:
You have three subscriptions all calling the same function and that function copies the event data into a local string array. Is it required to trigger the problem that they all call the same function?
In the event handler you subscribe with, you first copy the char array data into an Arduino String object and then copy it out again in to externalIP. This seems like it just wastes memory.
Also in the event handler you pay no attention to if the string data you received is longer than the 15 location externalIP array, so this can really clobber memory.
You are initializing lastTime by calling Time.now() and this likely to be before the clock is running. I guess this OK since it probably returns 0 anyway, but an explicit 0 value might be better.
So does it still fail if your webhook subscribe function is different? Does it still fail if you bounds check the incoming event data before smashing it into externalIP?
I know I can use something like Telize to look up timezone. It is also a paid service since sometime in 2015 according to their site. Is there any other timeZone lookup library based on public ip address that anyone can recommend?
Cool idea! I think what you could do now would be to say, get your external IP from the cloud, and then hit a service with your IP using say, the geoIP database to get a location estimate?
I’m currently using the new Google Maps Geolocation feature which so far seems to work extremely well, geolocating on the basis of seen wireless networks.
This gives me a coordinate location that I can use for a webhook to hit up the Google Maps Timezone API.