I am totally new into Arduino things. I buy couple of arduinos and those ethernet shields which would connect to internet and send some data to our API.
First problem is i can't get to work my ethernet shield, all the time i don't get any ip address. All wires are connected right, check it 10 times already also i use a lot of different libaries but no success at all.
Can someone help me little bit with it? Also try on other arduino nano, no success so there is no hardware corruption i guess..
I have one of those NANO shields and just plugged it in.
The only change I made was to put the IP address onto my own subnet 192.168.0.115 and it works just fine.
Are you aware of networking protocols, IP ranges, Subnets, etc.
If not brushing up a little may be in order as the sketch you pointed at is perfect apart from the subnet IP.
// Watch video here: https://www.youtube.com/watch?v=M4mVDnlnzSA
// UIP is a proper library for Arduino Nano Ethernet shield
// NOTE: UIPEthernet library is not needed if you are using Arduino UNO/Duemilanove/Mega/etc.
// UIPEthernet library is used for Arduino Nano Ethernet Shield
#include <UIPEthernet.h> // Used for Ethernet
// **** ETHERNET SETTING ****
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x78, 0xEE };
// Change the IP below to your subnet if you have any issues
// IPAddress ip(192, 168, 0, 115);
IPAddress ip(192, 168, 1, 115);
EthernetServer server(80);
void setup() {
Serial.begin(9600);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("IP Address: ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client)
{
Serial.println("-> New Connection");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank)
{
client.println("<html><title>Hello World!</title><body><h3>Hello World!</h3></body>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r')
{
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(10);
// close the connection:
client.stop();
Serial.println(" Disconnected\n");
}
}
Check the DHCP list in your router or if you are on windows open a command prompt and type "ipconfig /all"
Check the "Default gateway IP to get the range (normally 192,168,0.1) or if its a little older then it may actually be as you said and show 192.165.1.115.
Some of the nastier routers may also have ranges cut down too to under 100. but thats not too often.
Left you enough clues to get going and that it shows that IP (presumably in serial monitor) means the sketch ran fine so thats probably not the issue and chances are neither is your Ethernet module.
Really looks like it may be down to a lack of understanding about network basics.
But just to be sure some final thoughts.
Change the IP in your sketch (as already mentioned) to 192.168.0.115 (confirm that's in your subnet)
Turn off your computers security for a little while.
If you run Chrome as you browser open an INCOGNITO window with NO add ons.
(other browsers usually have similar options)
This is now mu current code, i'm trying to send some data to some domain, when i check access log on domain of course nothing inside log from my Arduino IP, but i still receive in serial monitor:
#include <UIPEthernet.h>
#include <SPI.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 2, 255);
char serverName[] = "checking.tozdajdela.net"; // test web page server
EthernetClient client;
String data;
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
Serial.print("ip-");
Serial.println( Ethernet.localIP());
Serial.print("Subnet mask-");
Serial.println( Ethernet.subnetMask());
Serial.print("Gateway-");
Serial.println( Ethernet.gatewayIP());
Serial.print("DNS-");
Serial.println( Ethernet.dnsServerIP());
}
void loop() {
sendGET(); // call sendGET function below when byte is an e
}
void sendGET() //client function to send/receive GET request data.
{
if (client.connect(serverName, 80)) { //starts client connection, checks for connection
Serial.println("connected");
client.println("GET / HTTP/1.0"); //download text
client.println("Host: checking.tozdajdela.net");
client.println(); //end of get request
}
else {
Serial.println("connection failed"); //error message if no client connect
Serial.println();
}
while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available()) { //connected or data available
char c = client.read(); //gets byte from ethernet buffer
Serial.print(c); //prints byte to serial monitor
}
Serial.println();
Serial.println("disconnecting.");
Serial.println("==================");
Serial.println();
client.stop(); //stop client
}
Also if i put out ethernet cable so, arduino doesn't have network this program keep saying that is connected/disconnected and it gives me same IP as before, that's really weird.
LMAO about the last bit of your post and i'm sorry about that.
See the fourth line where it tells the dhcp what IP it wants to use.
Clearly its going to get that IP every time it wants it regardless of what you do with the cable unless you clear out all the tables.
Only reason it would not get that IP is if another device demanded it whilst yours was disconnected.
As for the sketch no spending a lot of time on it but a quick glance has me thinking there is something missing ?
I may play with it a little later
IS the "tozdajdela.net" supposed to put anything out ?
I get this if I open that page.
Your IP has been logged !
You are using: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
No matter which page i put i will always get same results, first it is connected and than it disconnected.
Also get same output if arduino isn't connected to ethernet cable at all..
I don't know what to do anymore i'm trying this module almost 2 days with no success, ok first succcess was i'm now getting some kind of local IP, but as i said this ip keeps getting no matter if i am connected or not. Anyway this ip doesn't use any other device.