sde1000 / NanodeUIP

Port of uIP library to Nanode
http://wiki.hackspace.org.uk/wiki/Project:Nanode/UIP
38 stars 22 forks source link

DHCP with the NanodeUIP library #14

Closed MarcoPhenix closed 11 years ago

MarcoPhenix commented 11 years ago

Hi guys, I am developpin' on an arduino UNO board rev 3 and I have plugged into it a ENC28J60-H ethernet shield. I'm using the NanodeUIP,NanodeUNIO librairies for my application and I don't know how to get an IP address usin' DHCP. I've also tried the uiptest example but it doesn't work at all. Maybe I'm just an ignorant newbie in the Arduino World but I definitively don't know how to make it works. Please I need some help. Cheers

sde1000 commented 11 years ago

What does it send to the console when you run the example?

Does the UNO board or ethernet shield have a MAC address chip? That's what the NanodeUNIO library is expecting to talk to. If it doesn't, does it have any other way of getting a MAC address?

MarcoPhenix commented 11 years ago

Thanks for replying sde1000. it send nothing to the console. I assigned a MAC address to the UNO board by myself

sde1000 commented 11 years ago

I suspect you are trying to use this library on hardware it wasn't designed for. You should be able to get it to work, but you'll need to make some changes:

  1. Remove NanodeUNIO - you don't have the appropriate chip on the board.
  2. Where NanodeUIP fetches the MAC address using NanodeUNIO, get it to fetch your MAC address instead.
  3. You may also have to check which pin is used to select the ENC28J60 and change the driver appropriately.
MarcoPhenix commented 11 years ago

Thx again sde1000 I'll try the advices tomorrow and I will keep you in touch Cheers

MarcoPhenix commented 11 years ago

Hi sde1000, I've followed youir advices and I don't get any ip address yet that's my code, have a look please, the callbacks functions dhcp_status and resolv_found are not call at all What do you think?


include

static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

static void resolv_found(char name, uip_ipaddr_t addr) { Serial.println("fonction resolv_found"); char buf[30]=": addr="; Serial.print(name); uip.format_ipaddr(buf+7,addr); Serial.println(buf); }

void dhcp_status(int s,const uip_ipaddr_t *dnsaddr) { Serial.println("fonction dhcp_status"); char buf[20]="IP:"; if (s==DHCP_STATUS_OK) { resolv_conf(dnsaddr); uip.get_ip_addr_str(buf+3); Serial.println(buf); uip.query_name("www.greenend.org.uk"); } }

char mac_address[20]; char ip_address[20];

void setup() { Serial.begin(38400); Serial.println("[UIP test]"); uip.init(mymac); uip.get_mac_str(mac_address); Serial.println(mac_address); uip.wait_for_link(); Serial.println("Link is up"); uip.init_resolv(resolv_found); uip.start_dhcp(dhcp_status); Serial.println(ip_address); Serial.println("setup() done"); }

void loop() { uip.poll();

}


sde1000 commented 11 years ago

How far does it get? Do you get any output on the serial port at all? If the ENC28J60 driver is working at all I would at least expect it to output "Link is up".

MarcoPhenix commented 11 years ago

Thx again for replying sde1000 That's what I get from the serial port:


[UIP test] 74:69:69:2D:30:31 Link is up 0.0.0.0 setup() done


sde1000 commented 11 years ago

Hmm. Are you able to get a packet trace from the network it's connected to? Is it sending any DHCP discover packets at all?

MarcoPhenix commented 11 years ago

HI sde1000 When I change the library, usin' instead of "nanodeuip.h", "ethercard.h", I can get an IP address by DHCP but I want to make it usin' only "nanodeuip.h" because in my application, I want to get an IP address by DHCP and then, publish on a MQTT server. What do you think?

MarcoPhenix commented 11 years ago

Hi sde1000 As you can see on the code, I have put some "Serial.print()" functions into the functions "dhcp_status" and "resolv_found" to see if they are called and you can noticed also viewing the Serial monitor display that they aren't. What do you think? Maybe the condition in the library which is supposed to call them isn't verified

sde1000 commented 11 years ago

Are you sure you have adapted the library properly to your hardware? For example, have you checked that the chip select pin for the ENC28J60 is the same on your UNO+ethernet shield and the Nanode? I mentioned this in an earlier comment and you haven't confirmed that you've checked it.

(As I said before, you're trying to use this library on a platform it wasn't written for, so you are going to have to make some changes to it. I can't guide you through all of these since I don't have a UNO+ethernet shield to test on!)

MarcoPhenix commented 11 years ago

Hi sde1000 I'm sure I've adapted the library properly to my hardware because I use the pin 8 for the CS.And I assume it's the same for both, nanode and my UNO+ethernet shield sde1000 you think that the DHCP functions are only written for the nanode? Because I don't have any problem with MQTT

MarcoPhenix commented 11 years ago

Hi sde1000 I'm currently usin' a sniffer, WireShark, to see if the arduino board send the datagrams and It doesn't. But when I use DHCP with the library "Ethercard", il does. What do you think? Thx in advance for your reply

sde1000 commented 11 years ago

You mention you "don't have any problem with MQTT". Which library are you using for that?

MarcoPhenix commented 11 years ago

I'm using the libraries "NanodeUIP", "NanodeMQTT" and "NanodeUNIO"

MarcoPhenix commented 11 years ago

Hi sde1000 I've also asked on the Arduino forum(http://forum.arduino.cc/index.php?topic=178974.new;topicseen#new) for some advices. I will be very pleased if you join the discussion knowing that I've posted more details and monitor displays Cheers Ryan

MarcoPhenix commented 11 years ago

Hi Sde1000, I have read through your library and I finally found that the board send only DHCP Discover messages but doesn't get any DHCP OFFER at all, which is strange because with another library I always get an IP address What do you think? Thx in advance for your reply Cheers Ryan

MarcoPhenix commented 11 years ago

That's what I view on WireShark with wireshark I found the condition where the state should been changed It's here

/***/ if(uip_newdata() && parse_msg() == DHCPOFFER) { s.state = STATE_OFFER_RECEIVED; //Serial.println("offer"); break; } else { Serial.println("any offer"); }

/**/ What do you think about it? Cheers Ryan

sde1000 commented 11 years ago

Hmm. So it's emitting discover packets but your DHCP server isn't responding to them. What are you using as a DHCP server? Can you have a look at its logs?

MarcoPhenix commented 11 years ago

I use as a DHCP server my Internet Router.I don't know how to have a look at its logs

MarcoPhenix commented 11 years ago

I've just noticed that the functions parse_msg() and uip_newdata() return always the value 0

MarcoPhenix commented 11 years ago

Hello sde1000, I've just compared the DHCP_DISCOVER sent by your library and the one which is sent by EtherCard's one and there are different, I will keep you in touch with my research Cheers Ryan

MarcoPhenix commented 11 years ago

Hello sde1000 I have made the DHCP_DISCOVER similar as the one from EtherCard and I haven't get any IP address yet.Please can you tell me how can I put the Internet Protocol flags at 0(Don't fragment)? Thx in advance for your reply Ryan

MarcoPhenix commented 11 years ago

Hi sde1000 The two DHCP_DISCOVER frames from NanodeUIP and EtherCard libraries are the same but EtherCard's one make and request and the NanodeUIP's don't. What do you think is the issue??

MarcoPhenix commented 11 years ago

Hi sde1000 As I said in the previous comments, I've made the two "DHCP_DISCOVER" frames similar.the first from NanodeUIP library and the second from EherCard library image And you can see on the picture, the UNO board with the nanodeUIP library send "discover" and then receive and "offer" but doesn't make a "request" at all Whereas at the bottom of the picture, the board with the Ethercard library make a "discover" then receive a "offer" next, it replies with a "request" and the server close the transaction with a "ack" which is correct. So I think that the NanodeUIP library don't parse the "offer" correctly. Please, can you tell what do you think? Thx in advance for your reply Cheers Ryan.

sde1000 commented 11 years ago

You could well be right, but I don't think I can help you further. I don't have your hardware so I can't test anything. I don't even have any working Nanodes at the moment (I recycled the parts into other projects).

MarcoPhenix commented 11 years ago

thx for replying honnestly, i don't think it depends on the hardware I'm using because I mean Nanode it's an Arduino Board plus an enc28j60 controller I think it's in the part of the code where it parse the reply of the server. there is the issue according to me. Ryan