Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino UNO/mega + w5100 can't connect #195

Open
ghost opened this issue Aug 25, 2016 · 1 comment
Open

Arduino UNO/mega + w5100 can't connect #195

ghost opened this issue Aug 25, 2016 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 25, 2016

I'm very very new at this topic to start with. I have for the past two days tried to get this thing working on my Arduino UNO/mega and two different w5100 shields.
One of the shield seems to not work at all since i don't get an IP from it, when i run the code

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

byte mac[]    = {  0x00, 0xAA, 0xBB, 0xCC, 0xCE, 0xEC };
EthernetClient client;
void setup()
{
  Serial.begin(9600);
  if(Ethernet.begin(mac) == 0){
  Serial.println("fail");
  for(;;);
  }
  Serial.print("my ip :"  );
  for(byte thisByte = 0; thisByte < 4; thisByte ++) 
  {
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print(".");
    }
  }`

The other shield got an IP from the code above and it seems to work. I have been able to ping the IP and with an example found online able to get data from telnet to the ip and successfully connecting to the "webClient" in arduino basic library.

I have tried both of the basic examples located in the pubsubclient "auth(code example below) and basic". Where noone seems to work for me. The basic example are giving me the "-2 can't connect" error, and the auth are just failing.

The gateway dns and subnet are taken from my laptop with the cmd : /sbin/ifconfig. I'm not 100% that is the correct way to do it, maybe it could be my problem?

My computer are running a mosquitto 1.4.9 "server" on the correct port, I am able to connect to this server from my node js application and sub/publish data. I'm running out of options on what the problem could be, and would appreciate any help!

/Eddie

`#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>

// Update these with values suitable for your network.
byte mac[]    = {  0x00, 0xAA, 0xBB, 0xCC, 0xCE, 0xEC };
IPAddress arduinoIP(192, 168, 0, 22);
IPAddress server(192, 168, 0, 15); 
IPAddress gatewayIP(192,168,0,1);
IPAddress subnetIP(255,255,255,0);
IPAddress dnsIP(192,168,0,1);

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("message has arrived on topic: [");
  Serial.print(topic);
  Serial.print("]");
}

EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);
//EthernetServer Eserver(80);

void setup()
{
  Serial.begin(9600);
  Ethernet.begin(mac, arduinoIP, dnsIP, gatewayIP, subnetIP);
  Serial.println("after ethernet.begin");
  Serial.print("my adr:");
  Serial.print(Ethernet.localIP());
  Serial.println();
  // PubSubClient.h

  if (client.connect("*"))
  {
    Serial.println("success");
    client.publish("test","hello world");
    //client.subscribe("test/topic");

    Serial.println("publishing/connected");
  }
  else
  {
    Serial.println("could not connect");
  }
}

void loop()
{
 client.loop();
}`

small edit: i saw that my gateway was wrong. It's now fixed, but still wont work.
Trying to see that my dns is correct aswell.
Edit 2: can't find it, but i found this at the arduino website: dns: the IP address of the DNS server (array of 4 bytes). optional: defaults to the device IP address with the last octet set to 1
which means that i should have <192.168.0.1> ? (if i could connect to the test mosquitto, does that mean that i got the correct dns, and gateway?)
Either way, did not make any difference.

Edit 3: picture of the setup, nothing special i guess.
image

Edit 4: tried a ton of different ways to code the IP of the server, including:
IPAddress server(192,168,0,15);
byte server[] = {192,168,0,15};
const char*[] = {192,168,0,15};
char server[] = "192.168.0.15";
char server[] ="mqtt:/192.168.0.15"; <-- this is the exact address that i use when connecting with my node app.

edit 5: tried to connect to 85,119,83,194 (test.mosquitto.com) which works.
can't connect to my public IP though.. the ports are correct , i think... And they are open in the router. Could the problem be that my computer which are running the mosquitto server are on the wifi while the arduino is on a wired connection?

edit 6: still not able to connect, dump of my (mosquitto cfg) below:

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

listener 1883
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d

@ghost
Copy link
Author

ghost commented Aug 25, 2016

Edit 7: And it's solved! Took waay more time then it should've.
It was the firewall on my laptop, which is running linux mint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants