How to change server to connect in code

Hi!

I’m trying to create a standalone sensor node network and I want to connect it to a raspberry pi (as main server). How can I make the sketch (in arduino and raspberry pi) to connect to a custom server?

I assume for Arduino (and arduino like boards) something must be added to:

    Blynk.begin(auth);

And for raspberry pi will need to add the server and port in here:

Blynk.begin(auth, serv, port);

But not sure about this. the serv and port I assume it’ll use a string to connect, right?

Thanks

------- EDIT -------

I’ve been looking a bit more and it’s possible to change the server in raspberry pi with

sudo ./blynk --server=serveriphere --token=tokenhere

That will depend on the method you used to setup a Blynk Client on the RPi.

With eht eC++ WiringPI method, then yes you use the commands as you listed above.

However with NodeJS, I the syntax is a bit different, and possibly always needs to be embedded in the JS sketch itself (much like Arduino). e.g. This is what I have at the beginning of my JS sketch:

var Blynk = require('blynk-library');  // Links variable 'Blynk' to the Blynk Library
var AUTH = 'cda957435ce44407bed2e9283c95018f';  // My top secret auth code... useless to anyone on the cloud ;P
var blynk = new Blynk.Blynk(AUTH, options = { connector : new Blynk.TcpClient( options = { addr: "10.10.3.13", port: 8442 } ) });  // This takes all the info and directs the connection to my Local Server.

For Arduino, you can look at any of the Example sketches as they show the optional info for connecting to Local Servers e.g:

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

A small trap for new players is the IPAddress(xxx,xxx,xxx,xxx) part… you DON"T put all of that in the command, just the actual IP numbers, usually in quotes with periods (but may work with commas?), as per my example here:

char auth[] = "d1e516ca1xxxxxxxxxc786907a90";  // Blynk App Authorization Code.
char ssid[] = "xxxxxxx";  // Your local AP SSID.
char pass[] = "xxxxxxx";  // Your local AP password.
char server[] = "10.10.3.13";  // The local IP address of your Local Server device.

Blynk.begin(auth, wifi, ssid, pass, server, 8442);  // Connect to Blynk - Local Server.
2 Likes

Thanks!

I’m using a custom domain with noip to connect make it easier and cheaper (getting a fixed public ip is 25€ per month with my isp). In arduino, should I do:

char server [] ="my_custom_domain_here";

or it just accepts ip numbers like format?

Greetings

Generaly the MCU hardware stays “home” and thus able to connect to the Local (internal) side of your Router’s Network, so you use the actual IP of your Local Server in your script.

The only thing that would use your NoIP address on is your App, becasue it would the part that tends to leave the house with you, and thus be out of Local (internal) WiFi range… And your NoIP address simply points to your Public (external) address of your router. PS, You still need to setup port forwarding for that to work.

1 Like

I think I “found” Blynk some years ago when I was searching for something to do with “MCU access without port forwarding”.

We use a WISP and port forwarding is not available unless the WISP goes to the trouble of setting it up, which they don’t really want to do.

@luis_diaz we have custom domain’s and yes your server is fine with the name or “123.456.789.012”.
You do not need to do any port forwarding to access your home MCU on the road with Blynk.

Thanks,

everything is starting to make sense to me :smiley:

I didn’t get the impression this OP was using a WISP, rather just an ISP (Cable, Telecom, fiber, etc) with a WiFi/Router (getting a dynamic Public IP) installed in his home… and using NoIP instead of paying for a static Public IP. Basicly I have the same setup (although my dynamic Public IP never really changes, but that’s just my ISP I guess).

I know you understand this, but for @luis_diaz sake… If this is the case (the above mentioned ISP and router), then he may still need to setup port forwarding in his router, so it will pass any “outside” Blynk connection requests (from the App) through to his Local Servers IP.

@Gunner I was just pointing out my “route” to Blynk which has some relevance to this post, namely port forwarding (PF).

Actually when I saw reference to custom domain I thought the OP was referring to a real domain but it looks like it will be a noip subdomain. I still believe PF is not required.

1 Like

Easyish way to find out :stuck_out_tongue_winking_eye: @luis_diaz Who is your internet supplier, did they provide you the wireless router/modem, and what is it’s make and model?

Are you “connected” to them via cable TV, Telephone (ADSL), or is it beamed wirelessly to a device they provided (possibly the same router/modem)?

I have edited the first 2 posts to include the correct syntax for local server access. AFAIK the parameters require a space between them.

Actually @luis_diaz PF or some similar features that are available for the Pi will almost certainly be required.

When I saw “custom domain” I thought your server was on the internet, which it’s not really.

HI!

My server is on a raspberry pi on my local network.

My internet supplier is Movistar (a spanish company), and yes, they provide a ONT and a router. I don’t know the manufacturer and model right now (I’m at work). I don’t know why it will matter.[quote=“Costas, post:10, topic:16381”]
Actually @luis_diaz PF
[/quote]

Don’t know what PF means … Would you explain it?

Nope, I’m running the blynk server on a raspberry pi at home.

@luis_diaz hope this helps.

1 Like

Fiber internet, nice :wink: OK, so your router basically takes the dynamic Public IP (think street address to a office building), provided from Movistar (via the ONT), and “routes” traffic to and from a range of Private IP’s (think office numbers within that building) i.e. all of your wired and WiFi devices; phone, computer, MCU’s, etc.

Part of the router’s job is to protect that internal Private network from outside intrusion (think building security guard)… thus while your App will be provided with that Public IP, via the NoIP service (even if it changes, being Dynamic and all), your router will still block any attempts to communicate to your server without what is called port forwarding; A feature you setup in the router. Basically, it says anything knocking on the door with a package labeled 8442 will get forwarded to the correct Private IP address (think office, in this case the RPi), in which your Local Server resides.

And yes, there may be ways around needing port forwarding, but that is beyond my experiential knowledge.

Thanks mates!

I’m learning a lot about networks in this journey :slight_smile: