Callbacks functions don't work

Hello guys,
I'm encountering some problems with my code.
I'm usin' two callbacks function in my sketch but when I pass them as parameters in other functions, it does'nt work because I don't get anything from the Serial port in the two callback functions
Please I need some help

That's my code

#include <NanodeUIP.h>

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


//CALLBACK FUNCTION
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);
}

//CALLBACK FUNCTION
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("l'adresse IP est:");
    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.print("The mac address is: ");
  Serial.println(mac_address);
  uip.wait_for_link();
  Serial.println("Link is up");
  uip.init_resolv(resolv_found);//FUNCTION USIN' THE CALLBACK FUNCTION
  uip.start_dhcp(dhcp_status);//FUNCTION USIN' THE CALLBACK FUNCTION
  Serial.print("The ip address is: ");
  uip.get_ip_addr_str(ip_address);
  Serial.println(ip_address);
  Serial.println("setup() done");
}

void loop() 
{
  uip.poll();
  
}

That's what I get from the serial port

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

It looks as if you expect the callbacks to be invoked by the NanodeUIP library. Can you provide links to the library and its documentation?

Thx for replying PeterH,
That's the link

Callback functions work. Full stop.

Maybe the condition under which it is called did not occur.

Callback functions work. Full stop.

Maybe the condition under which it is called did not occur.

You're right Nick, I've tested it in another sketch and its works, sorry for this stupid post.
Currently I haven't found the issue but as you have said, I have looked into the source code of the library and I assume the condition under which it is called occurs.
sde1000 the creator of the library is already kept in touch on this problem; but I want to know your proposals.
Cheers
Ryan

You have the library source. I suggest editing it to display something just before calling the callback. That will confirm the condition exists. If it doesn't get displayed work back to find why you think the condition exists, when it doesn't.

Hi,

You have the library source. I suggest editing it to display something just before calling the callback. That will confirm the condition exists.

I've put a "Serial.print" and I have a display so I think that the condition exists.

I am usin' Wireshark, a sniffer to detect if there is any datas which are sent.
With the example "TestDHCP" which allow me to get an IP address by DHCP with the library Ethercard, Wireshark sniffs somethin' but when I upload the sketch "uiptest" to get an IP address usin' the nanodeUIP library, It sniffs anything
What do you think?
Thx in advance for your replies :slight_smile:

What do the debugging displays show?

Are you sure that the callbacks are called in a context where you can use Serial.print()?

Hi you all, :slight_smile:
That's my display

[UIP test]
The mac address is: 74:69:69:2D:30:31
Link is up
function init_resolv in <<NanodeUIP.cpp>>
Function resolv_init() in <<resolv.cpp>>
setup() done

That's my setup function

void setup()
{
  Serial.begin(57600);
  Serial.println("[UIP test]");
  uip.init(mymac);
  uip.get_mac_str(mac_address);
  Serial.print("The mac address is: ");
  Serial.println(mac_address);
  uip.wait_for_link();
  Serial.println("Link is up");
  uip.init_resolv(resolv_found);
  //uip.start_dhcp(dhcp_status);
  //Serial.print("The ip address is: ");
  //uip.get_ip_addr_str(ip_address);
  //Serial.println(ip_address);
  Serial.println("setup() done");
}

That's the callback function "resolv_found" which is taken in parameter in the function uip.init_resolv(resolv_found)

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);
}

these previous codes are in the arduino sketch; now let's take a look in the library where I have put some "Serial.print"
That's the method "init_resolv" which is called in the sketch

void NanodeUIP::init_resolv(resolv_result_fn *callback) {
  Serial.println("function init_resolv in <<NanodeUIP.cpp>>");
  resolv_status_callback=callback;
  resolv_init();
}

there is a display here so it entered the function
That's the function "resolv_init" which is called next

resolv_init(void)
{
  static uint8_t i;
  Serial.println("Function resolv_init() in <<resolv.cpp>>");
  for(i = 0; i < RESOLV_ENTRIES; ++i) {
    names[i].state = STATE_DONE;
  }

}

There's a display so it entered the function also
But I assume the callback function "resolv_found" in the sketch isn't called because it displays anything; knowing that in the method "init_resolv", the callback is assigned to "resolv_status_callback"

void NanodeUIP::init_resolv(resolv_result_fn *callback) {
  Serial.println("function init_resolv in <<NanodeUIP.cpp>>");
  resolv_status_callback=callback;
  resolv_init();
}

Which is declared as it:

resolv_result_fn *resolv_status_callback;

resolv_result_fn which is defined like this:

typedef void resolv_result_fn(char *name, uip_ipaddr_t *addr);

What do you think?
Thx in advance for your answers :slight_smile:

Where is resolv_status_callback called?

Thx for replying Nick,
When I make a search of "resolv_status_callback" in all the files of the folder "NanodeUIP" which contains files used by the "NanodeUIP.h" library, I only have this:
the first instance

void resolv_found(char *name, uip_ipaddr_t *ipaddr)
{
  if (uip.resolv_status_callback!=NULL) {
	Serial.println("uip.resolv_status_callback!=NULL");
    uip.resolv_status_callback(name, ipaddr);
  }
  else
  {
	Serial.println("uip.resolv_status_callback==NULL");
  }
}

I've already put some "Serial.print" and there is not any display
And the second instance:

void NanodeUIP::init_resolv(resolv_result_fn *callback) {
  Serial.println("function init_resolv in <<NanodeUIP.cpp>>");
  resolv_status_callback=callback;
  resolv_init();
}

And finally the last one:
Where it is declared

resolv_result_fn *resolv_status_callback;

Hi all,
I have read through the NanodeUIP 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 replies
Cheers
Ryan

I've attached which is viewed with WireShark

hello Guys
I have found the condition which is never verified and make the board not getting any IP address and that for 2 hours.
This is it

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

I always have on the Serial Monitor

any offer

I've had it to check if I get a DHCP_OFFER and I don't
What do you think?
Cheers
Ryan

Finally I've succeeded in sending a DHCP_DISCOVER frame with the library NanodeUIP and I'm comparing it with the one from EtherCard which works fine
I'm doin' it with WireShark, I will keep you in touch
That's the display from WireShark