Go Down

Topic: DHCP Troubles (Read 399 times) previous topic - next topic

kashyap

Hi All,

I am new to the arduino forum. I have couple of questions with ethenet shield (w5100). I am using Xbee (for zigbee) on the top of ethernet shield. I am able to send ethernet (UDP/IP)data through xbee wirelessly.

Here is my problem. This is working like a charm when I am using STATIC IP address. But when I configure my arduino as DHCP it is not working anymore.
The library for DHCP is here...http://gkaindl.com/software/arduino-ethernet/dhcp

Is there anybody here who has use DHCP with ethernet shield with Xbee?
I am using arduino Duemilanove(who has one serial) and Xbee PRO series 2 and ethernet shield Wiznet W5100.

Thanks in advance

kashyap

#1
Oct 26, 2011, 10:58 pm Last Edit: Oct 27, 2011, 04:55 am by Coding Badly Reason: 1
Hi All,

I am new to the arduino forum. I have couple of questions with ethenet shield (w5100). I am using Xbee (for zigbee) on the top of ethernet shield. I am able to send ethernet (UDP/IP)data through xbee wirelessly.

Here is my problem. This is working like a charm when I am using STATIC IP address. But when I configure my arduino as DHCP it is not working anymore.
The library for DHCP is here...http://gkaindl.com/software/arduino-ethernet/dhcp

If I use methods from xbee.h and ethernetDHCP.h simultaneously it hangs arduino.

Is there anybody here who has use DHCP with ethernet shield with Xbee?
I am using arduino Duemilanove(who has one serial) and Xbee PRO series 2 and ethernet shield Wiznet W5100.

Here is a some part of my code which is working fine. But When I use xbee methods like

XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x407a94e0);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxRequest zbTx1 = ZBTxRequest(addr64, payload1, sizeof(payload1)); (This 3 line of code is at the beginning of void setup{ })

it just hangs.

Code: [Select]
#include <XBee.h>

#if defined(ARDUINO) && ARDUINO > 18
#include <SPI.h>
#endif
#include <Ethernet.h>
#include <EthernetDHCP.h>
#include <udp.h>
#include <client.h>
#include <server.h>

unsigned int localPort = 0xBAC0;  
uint8_t remoteIp[4];     // holds received packet's originating IP
uint16_t remotePort; // holds received packet's originating port
int ptr=0;
// buffers for receiving and sending data
#define UDP_TX_PACKET_MAX_SIZE  1024
uint8_t packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //to receive UDP packet and send Zigbee packet
uint8_t packetBufferzbrx_udptx[UDP_TX_PACKET_MAX_SIZE]; // To receive Zigbee packet and send UDP packet

uint8_t payload[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}   ;
uint8_t payload1[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}   ;

//XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x407a94e0);
//ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
//ZBTxRequest zbTx1 = ZBTxRequest(addr64, payload1, sizeof(payload1));

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

const char* ip_to_str(const uint8_t*);

XBee xbee = XBee();
boolean is_xbee_begin = false;

void setup()
{
 Serial.begin(9600);

 Serial.println("Attempting to obtain a DHCP lease...");
 
 
 EthernetDHCP.begin(mac);

 // Since we're here, it means that we now have a DHCP lease, so we print
 // out some information.
 const byte* ipAddr = EthernetDHCP.ipAddress();
 const byte* gatewayAddr = EthernetDHCP.gatewayIpAddress();
 const byte* dnsAddr = EthernetDHCP.dnsIpAddress();
 
 Serial.println("A DHCP lease has been obtained.");

 Serial.print("My IP address is ");
 Serial.println(ip_to_str(ipAddr));
 
 Serial.print("Gateway IP address is ");
 Serial.println(ip_to_str(gatewayAddr));
 
 Serial.print("DNS IP address is ");
 Serial.println(ip_to_str(dnsAddr));
 
 Udp.begin(0xBAC0);
 //xbee.begin(115200);
}

void loop()
{
 // You should periodically call this method in your loop(): It will allow
 // the DHCP library to maintain your DHCP lease, which means that it will
 // periodically renew the lease and rebind if the lease cannot be renewed.
 // Thus, unless you call this somewhere in your loop, your DHCP lease might
 // expire, which you probably do not want :-)
 EthernetDHCP.maintain();
 if(is_xbee_begin == false)
 {
   is_xbee_begin = true;
   xbee.begin(9600);
 }
 
 int packetSize = Udp.available();
       if(packetSize)
       {
                 
                   packetSize = packetSize - 8;      // subtract the 8 byte UDP header
                   Serial.print("Received packet of size ");
                   Serial.println(packetSize);
               
                   // read the packet into packetBufffer and get the senders IP addr and port number
                   Udp.readPacket(packetBuffer,UDP_TX_PACKET_MAX_SIZE,remoteIp,&remotePort);
                   for(int i=0; i<=packetSize;i++)
                   {
                     Serial.print(byte(packetBuffer[i]));
                   }
                   Serial.println();
                   packetBuffer[packetSize] = 0;
       }
 
 delay(500);
}

// Just a utility function to nicely format an IP address.
const char* ip_to_str(const uint8_t* ipAddr)
{
 static char buf[16];
 sprintf(buf, "%d.%d.%d.%d\0", ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3]);
 return buf;
}



Thanks in advance


Moderator edit: Moved to new topic.  [code] [/code] tags added around source code.

Go Up