How to reach a WLAN address from outside ?

semar

Active Member
Licensed User
Longtime User
Hi all,
I'm struggling on a network challenge.

Basically I want to estabilish an UDP connection between two devices - an android app and a LifX light bulb. The latter opens an UDP channel on a specific port (56700).

It works flawlessly when the devices are on the same network (WLAN).

Now the question. How to reach the device (bulb) from within another network ? Both networks have an internet connection. In other terms, how to get the "internet" address of the light bulb ?

The light bulb has an address like, for example, 192.168.179.21. It's reachable from within the same network. The router that sits "ahead" has - I guess - a static IP address, which is given by the internet provider.

Now, there should be a sort of NAT traversing/translation in order to get a valid IP address and reach the light bulb from "outside". But how to get it ?

Sorry if I'm asking something obvious here.

Thanks for your attention,
Sergio
 

josejad

Expert
Licensed User
Longtime User
You should use some Dynamic DNS client, like duckdns or dyndns. You register and get a DNS name (something like "mybulb01.ddns.net"), then you use a client in your local network that update your ISP IP.
You have to open the ports in your internet router and redirect it to your bulb internal ip.
Something like this:
https://www.b4x.com/android/forum/t...t-access-your-device-over-the-internet.26611/

good luck¡
 

semar

Active Member
Licensed User
Longtime User
First of all, many thanks for your insides.

Actually I successfully use the provided HTML-Api for the bulbs, and it works fine.

My question regarding the connection from outside: I guess the official App uses winsockets, because the bulb reacts in real time, while using the HTML there is still a lag.

Anyway, the idea of a device that stays at home and controls the bulbs is a good idea, and I firstly wanted follow that path.

However, that adds a device that should always be on. That, plus the Wi-Fi that should also works the whole time, does not really meet my energy-saving criteria.

That said, I'm looking for a B4J solution that should run on a remote server. But before to trigger the well known "please start a new thread for that question", I'll do it now ;-)

[EDIT]..and here is it:
https://www.b4x.com/android/forum/t...ost-where-to-run-a-b4j-program-anyone.103419/
[/EDIT]

Best regards,
Sergio
 
Last edited:

sorex

Expert
Licensed User
Longtime User
what about using a Raspberry Pi or Raspberry Pi Zero(W)?


They are cheap in purchase (€10 for a Pi Zero with wifi) and costs probably a few euros to keep it running an entire year and you can make it your web & database server.
 

semar

Active Member
Licensed User
Longtime User
@sorex,
the Raspberry is indeed a really good alternative ! However, it is also an additional device that consumes energy. That's why I evaluate now the possibility of a cloud virtual server where to run a B4J app onto.
 

sorex

Expert
Licensed User
Longtime User
even if it's only €10/month you are at €120/year vs one time €10-25 + €5/year electricity for the raspberry.

the dynamic or fixed dns to some low power local device will always be cheaper I guess.
unless you use a webserver as middleware and use some €0 free hosting service.
 

semar

Active Member
Licensed User
Longtime User
even if it's only €10/month you are at €120/year vs one time €10-25 + €5/year electricity for the raspberry.
the dynamic or fixed dns to some low power local device will always be cheaper I guess.
unless you use a webserver as middleware and use some €0 free hosting service.

Yes sorex I get your point, and I must say, you're definately right.. Argh ! Again, changing plan.. But I'm really thinking to a Raspberry - or an old smartphone - solution.
Fact is, if I choose to buy a virtual server on the cloud for, say, 12 months, I should pay for it even for the periods where it will not be used. A raspberry however - or even better an old smartphone - is - like you say - will bought just once. :cool:
 

sorex

Expert
Licensed User
Longtime User
Indeed. And as you install a linux based OS (Raspbian) onto the Pi you can prepare and test your VPS solution at home.

Then you can still decide later if it's worth to put it (the JAR) somewhere else.

You can still use the Pi for other reasons so it's never a waste.
 

OliverA

Expert
Licensed User
Longtime User
You have to open the ports in your internet router and redirect it to your bulb internal ip.
Even though I liked your post due to DuckDNS/dynamic DNS recommendation, I would not connect any 3rd party IOT devices to the net if possible. Especially, if the device does not support encryption out of the box. At minimum, I would put the Pi (mentioned by @sorex) between the bulb and the internet and only have the pi communicate with the internet. Even then, I would have a very narrow scope of actions on the Pi that are accessible over the internet and then all communications should be encrypted (HTTPS for example). Don't try to roll your own encryption, since encryption is hard and badly implemented encryption is easily circumvented. Please note that anything you expose to the internet, someone will try to hack.
 

semar

Active Member
Licensed User
Longtime User
Even though I liked your post due to DuckDNS/dynamic DNS recommendation, I would not connect any 3rd party IOT devices to the net if possible. Especially, if the device does not support encryption out of the box. At minimum, I would put the Pi (mentioned by @sorex) between the bulb and the internet and only have the pi communicate with the internet. Even then, I would have a very narrow scope of actions on the Pi that are accessible over the internet and then all communications should be encrypted (HTTPS for example). Don't try to roll your own encryption, since encryption is hard and badly implemented encryption is easily circumvented. Please note that anything you expose to the internet, someone will try to hack.
Thank you OliverA for your insides.
 
Top