Ethernet Shield Fixed IP

Guys, I’m not sure how to set fixed IP on Ethernet Shield.

In the field: IPAddress server_ip (10, 0, 0, 10); Which IP should I put?

define BLYNK_PRINT Serial

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

IPAddress server_ip (10, 0, 0, 10);

// Mac address should be different for each device in your LAN
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress arduino_ip ( 10,   0,   0,  20);
IPAddress dns_ip     (  8,   8,   8,   8);
IPAddress gateway_ip ( 10,   0,   0,   1);
IPAddress subnet_mask(255, 255, 255,   0);

#define W5100_CS  10
#define SDCARD_CS 4

void setup()
{
  // Debug console
  Serial.begin(9600);

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

  Blynk.begin(auth, server_ip, 8080, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
  // Or like this:
  //Blynk.begin(auth, "blynk-cloud.com", 80, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
}

If you’re using the Blynk cloud servers then you should use the Blynk.begin line that’s commented out in your code example:

Blynk.begin(auth, "blynk-cloud.com", 80, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);

that way you don’t need the IPAddress server_ip variable at all.

Pete.

correct, I’m using the blynk server in the cloud.
I rewrote the code, but it still did not connect. Look:

#define BLYNK_PRINT Serial

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxx";

//IPAddress server_ip (192, 168, 15, 19);

// Mac address should be different for each device in your LAN
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress arduino_ip ( 192,   168,   15,  80);
IPAddress dns_ip     (  8,   8,   8,   8);
IPAddress gateway_ip ( 192,   168,   15,   1);
IPAddress subnet_mask(255, 255, 255,   0);

#define W5100_CS  10
#define SDCARD_CS 4
int pirPin = 7;

I’ve edited your post to add backticks so that it displays correctly, like this:
Blynk%20-%20FTFC

However, you’re missing the last part of your code.

Pete.

the bottom of the code is right, I wanted to know how the connection part is, I can not.
I do not want to install the blynk server, I want to use the cloud server, but my need is for the IP to be fixed.

It’s what I said before, in the second post in this topic.

Pete.

now I got it. Thank you

It is better to also explain how you fixed it, so that others can read… :rofl::rofl::rofl: Ermm… sorry… I had a moment there… anyhow, others might read it and learn as well :stuck_out_tongue:

Oh, Of course.

I made the modifications said for Pete.

I commented the line:
//IPAddress server_ip (192, 168, 15, 19);

I put my network data:

    // Mac address should be different for each device in your LAN
    byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
    IPAddress arduino_ip ( 192,   168,   15,  80);
    IPAddress dns_ip     (  8,   8,   8,   8);
    IPAddress gateway_ip ( 192,   168,   15,   1);
    IPAddress subnet_mask(255, 255, 255,   0);

Lastly I commented the line:

//Blynk.begin(auth, server_ip, 8080, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);

I used this line to enable static ip

Blynk.begin(auth, "blynk-cloud.com", 80, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);

Full Code:

   #define BLYNK_PRINT Serial


#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

//IPAddress server_ip (10, 0, 0, 10);

// Mac address should be different for each device in your LAN
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress arduino_ip ( 192,   168,   15,  40);
IPAddress dns_ip     (  8,   8,   8,   8);
IPAddress gateway_ip ( 192,   168,   15,   1);
IPAddress subnet_mask(255, 255, 255,   0);

#define W5100_CS  10
#define SDCARD_CS 4

void setup()
{
  // Debug console
  Serial.begin(9600);

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

  //Blynk.begin(auth, server_ip, 8080, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
  // Or like this:
  Blynk.begin(auth, "blynk-cloud.com", 80, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
}
2 Likes