How to get the IP address of Blynk Server

What I’m asking may be very basic and easy if I knew how to figure out the right header files and read them. Please pardon this.

What is the variable or call that one can access to figure out the resolved IP address of Blynk server connected to from the device?

Doesn’t it tell you that if you turn on BLYNK_DEBUG ?

Pete.

The serial output only shows server name but not IP. I want to show the IP address in the terminal.

Out of curiosity… why do you need a way of having your sketch “discover” the very same IP that must already be coded into it, in order to connect to the server in the first place?

I’d assumed that @mohan_sundaram is using Blynk cloud servers, in which case he wouldn’t know the IP address of the server his MCU has connected to.

Why he’d need this info is still a mystery, unless he was having geo DNS issues and wants to know if a ping from his mobile device resolved the same IP as the server his MCU has connected to.

Maybe he’ll enlighten us…

Pete.

Well if that is the case, then a little Googling later and I found this program will show the resolved address of blynk-cloud.com for my region.

http://www.esp8266.com/viewtopic.php?f=29&t=8026&start=4

I am still working on pulling the relevant stuff out of it to make it work in a Blynk sketch.

This library and sample code will return the IP of a host:


It’s not exactly the same as finding which IP address the MCU actually connected to at boot-up, but for most purposes it’s probably the same thing.

Pete.

It is if you use the same variable for both the Blynk connection and the whatever it is that does the ping stuff :slight_smile:

However, I am already running into library conflict or something… so while I did get a number… it was not the same number I got from the non blynkified script from that link I provided.

I hadn’t thought of that - nice idea!

Pete.

Heh… turns out whatever IP I was getting from my attempts wasn’t the correct resolved IP for blynk-cloud.com anyhow… instead I was getting something from the Principality of ANDORRA :unamused:

OK, so the OPs question… and for whatever strange reason it is needed… is still unanswered :stuck_out_tongue:

Precisely the reason. When I set up my device, the HTTP RESTful API was failing from the browser with an error msg “Invalid token”. It worked on one day and I captured the resolved IP and started using it in Webhooks in IFTTT. This kind of hit and miss is not something good.

The device resolves and connects to the right server and never fails with the invalid token error. So, if one can get the correct resolved IP from the device, we can then use it in the Webhooks in IFTTT. I’m assuming this is hidden somewhere as a variable in the library either as a variable or a call. Like how we get the SSID from the WiFi.SSID call.

I’m going to have devices in different places and am thinking of building a product. So, this does become very important.

Edit: The examples cited for ping all take ip addresses and are not resolving addresses to ping. Nevertheless, as @Gunner pointed out, ping may not return the same ip as the one the device connects to even if the same hostname is used.

If you build a product with Blynk the normal procedure is for you to be to be allocated a dedicated Blynk server, so fo example not blynk-cloud.com but dedicated-server-for-mo.com

Your product connects all the MCU’s to this dedicated server and you use it in IFTTT and API calls etc without an IP address.

During you testing phase you can simply use a known Blynk server IP address for all your devices including IFTTT and API calls etc.

For future reference, it is possible to resolve the hostname blynk-cloud.com to an IP address using this code:

 IPAddress Blynk_Server_IP;
 WiFi.hostByName("blynk-cloud.com", Blynk_Server_IP);
 Serial.print("blynk.cloud.com IP address is ");
 Serial.println(Blynk_Server_IP);

You can use this at any point once you have a Wi-Fi connection and you can use it when you done a normal Blynk.begin(), so it could be called using a button widget and the result pushed to a display widget if needed. As has been pointed out before, this isn’t necessarily the same IP address that has been used to establish the connection from the device to the Blynk cloud server. Having said that, it seems highly likely that it will be the same server.

I did briefly play around @Gunner’s suggestion by with using

WiFi.begin(ssid,pass);

to set-up the Wi-Fi connection then calling the code above and using:

Blynk.config(auth, Blynk_Server_IP, 8442);

This does work, but I ran into a couple of snags:

a) Sometimes this bit of code returns an IP of “0.0.0.0” as the Blynk_Server_IP and when this happens you obviously don’t get a Blynk connection when you use this as a parameter in the Blynk.config() call. There’s probably a way around this using a while loop to keep calling

WiFi.hostByName("blynk-cloud.com", Blynk_Server_IP);

until you get a valid IP, but I couldn’t be bothered to explore that option.

b) When you do get a Blynk connection you don’t get the normal Blynk logo on the serial monitor. You can tell that there is a valid connection because the device is shown as being online in the app, so it’s not really a big deal, especially if you’re not monitoring the serial output or redirecting it to a terminal widget.

It doesn’t seem that this will help @mohan_sundaram, but somebody might find it useful at some point in future.

Pete.

2 Likes

Please do note that one DNS A-record can have multiple IP adresses asociated with it. This is for redundancy purposes and so on.

If you REALLY want to know where you are connecting, there is only one sound method and that is getting TCP session info to see where you are actually connecting too.

I think that will be the bugs in the ESP8266 Arduino core. I have flashed similar code to my WeMos at least a dozen times today and it always picks up the correct IP. If you are not using the master code change to the v1.4 Prebuilt lwIP in the IDE.

Don’t forget this line after the Blynk.config()

Blynk.connect();

I think Blynk’s GeoDNS is effectively the redundancy as this is what the OP is trying to work with.

Well, yes, but still. Reverse resolving an A-record is no guarentee for getting the correct IP. Only TCP sessions will show that.

I’m using the 2.4.0-rc2 core, getting blank IP’s roughly every 10th to 20th time I hit the reset button on the Wemos.

I didn’t have Blynk.connect() in there, but adding it doesn’t make any difference to what’s displayed on the serial monitor.

Pete.

Does rc2 have lwIP selector in tools? I think it does from memory.

I started without it and it took forever to connect as I have blynk.run() within an if(Blynk.connected()) statement in the loop(). It was taking about 15 seconds, not down to a fraction of a second.