How do Internet-Of-Things apps detect if the device is local or not?

Internet of Things IoT Frameworks 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating
_x000D_ _x000D_ Among other devices, I have a Belkin WeMo switch and a 3M WiFi Thermostat. Both come with Android apps. When I open the app when at home (phone on the same WiFi subnet as the devices) the app says the devices are "local", or that the app is connected "directly" to the device. Any change I make is then directly reflected on the device. If I connect from anywhere outside my house, it some how "knows" that the device is not local. If I understand correctly, it then updates its own server somewhere, and eventually the device at home gets the update. How does an app do that? I want to replicate that functionality. Basically, I have a Raspberry Pi that, let's say does something over GPIO and I can trigger that action by visiting a web page. On my home network, the web page is accessible at http://192.168.10.25/do_something ...Outside my home network, the web page is accessible at http://my_custom_name.some_free_dynamic_dns.com:8080/do_something. I have set up my router to port forward 8080 on WAN to 192.168.10.25:80 on LAN. This works. How do I avoid having 2 pages? I want to write an app which effectively shows me the 192.168.10.25/do_something URL. When I am at home, it should "automatically" detect that the phone is on the same network as the URL, and just open 192.168.10.25/do_something directly ... and when I am outside, it should "automatically" detect that too and launch http://my_custom_name.some_Free_dynamaic_dns.com:8080/do_something. The key part here is that when at home, even if my ISP is down and host names aren't resolving, it shouldn't matter because everything is local. How do I go about doing this?

Posted on 16 Aug 2022, this text provides information on IoT Frameworks related to Internet of Things. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ Have your app try connecting to the Web server at 192.168.10.25 (or whatever local address you pick) first. If there is no answer within a reasonable amount of time (5 seconds should be enough), then connect to the external webserver. For security, you might want to make sure that the webserver at 192.168.10.25 is actually your webserver. You can do this by using challenge and response and public key encryption. I can give more details if you wish. You can try to avoid waiting for the (non-existent) local webserver by looking at your phone's IP address. If it isn't 192.168.x.y, you can assume that you are not local and go directly to the external web site. If you embed 192.168.10.25 directly in your app, then no host lookup is necessary.

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Important Internet of Things Links