# Rabbit Board 4000

**URL:** <https://forums.digi.com/t/rabbit-board-4000/15165>\
**Category:** Rabbit Software\
**Tags:** dynamicc, rabbit-4000\
**Created:** [July 23, 2015, 5:44pm UTC](https://forums.digi.com/t/rabbit-board-4000/15165 "2015-07-23T17:44:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![wse-ltd.com](https://avatars.discourse-cdn.com/v4/letter/w/f07891/32.png) [@wse-ltd.com](https://forums.digi.com/u/wse-ltd.com)\
**Post date:** [July 23, 2015, 5:44pm UTC](https://forums.digi.com/t/rabbit-board-4000/15165/1 "2015-07-23T17:44:58Z")

</div>

hello, I have a rabbit board 4000 BL4S160 2m serial program flash. Basically after I power cycle the network router which connects to the board (simulating an extended power outage), the values stored in memory are lost. I have replaced the battery to no avail. I have inherited this code and controller so I am kind of new to does?

Any ideas on where to start?

---

<div class="post-metadata">

**Author:** ![petermcs](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@petermcs](https://forums.digi.com/u/petermcs)\
**Post date:** [July 24, 2015, 12:13am UTC](https://forums.digi.com/t/rabbit-board-4000/15165/2 "2015-07-24T00:13:05Z")

</div>

I have seen something similar in my products where the Rabbit device is set to use Link Local addressing in the absence of a DHCP server.

What happens is that when the router goes down, the rabbit board changes network and then when the router is restored it changes network again. There is a bug in the TCP/IP stack which as far as I can remember, relates to how the stack stores its list of routers which can end up in a loop writing to memory beyond the end of the list. I modified the code to always clear the list of routers in this case and it solved the problem for me - I did report the issue to Digi but I don’t think they tried to get to the bottom of it.

I’m working on adding support for a GPRS module to my product and will have to revisit this whole area as the simple fix I put in place does not work if you have more than one network connection as every time the GPRS connection is dropped, all the routers are flushed.

Regards,  
Peter

---

<div class="post-metadata">

**Author:** ![wse-ltd.com](https://avatars.discourse-cdn.com/v4/letter/w/f07891/32.png) [@wse-ltd.com](https://forums.digi.com/u/wse-ltd.com)\
**Post date:** [July 26, 2015, 5:46pm UTC](https://forums.digi.com/t/rabbit-board-4000/15165/3 "2015-07-26T17:46:59Z")

</div>

OK thanks Peter. Here is my code snippet for the network handler:

```auto

//IP network handler thread
      	while(1)
         {
         	if(ifpending(IF_DEFAULT) != IF_UP)//if nextwork interface isn't up...
            {	// Start network and wait for interface to come up.
	            do
	            {
	               sock_init();//initialist TCP socket for HTTP Post commands.
                  ifdown(IF_ETH0);
                  while (ifpending(IF_ETH0) == IF_COMING_DOWN)
                  {
                  	tcp_tick(NULL);
                     yield;
                  }
                  ifconfig(IF_ETH0,
	                           IFS_DOWN,
	                           IFS_IPADDR, aton(IPAddressString),
	                           IFS_NETMASK, aton(SubnetString),
	                           IFS_ROUTER_SET, aton(DefaultGatewayString),
	                           IFS_NAMESERVER_SET, aton(DNSServerString),
	                           IFS_UP,
	                           IFS_END);

                  yield;

	               while (ifpending(IF_DEFAULT) == IF_COMING_UP)
                  {
	                  tcp_tick(NULL);
                     yield;
                  }

	            }while(ifpending(IF_DEFAULT) != IF_UP);
	            //Network must be up so initialise http server, and reserve port 80 for multiple web connections
	            http_init();
	            tcp_reserveport(80);
               printf("set up network 
");
               printf("
 done");

            }
            //run the http server daemon and process TCP services
            http_handler();
            tcp_tick(NULL);
         	yield;
         }

```

Could you provide a code snippet to clear the list of routers please? -Paramjit

---

<div class="post-metadata">

**Author:** ![wse-ltd.com](https://avatars.discourse-cdn.com/v4/letter/w/f07891/32.png) [@wse-ltd.com](https://forums.digi.com/u/wse-ltd.com)\
**Post date:** [July 26, 2015, 5:47pm UTC](https://forums.digi.com/t/rabbit-board-4000/15165/4 "2015-07-26T17:47:54Z")

</div>

OK thanks Peter. Here is my code snippet for the network handler:

//IP network handler thread  
while(1)  
{  
if(ifpending(IF\_DEFAULT) != IF\_UP)//if nextwork interface isn’t up…  
{ // Start network and wait for interface to come up.  
do  
{  
sock\_init();//initialist TCP socket for HTTP Post commands.  
ifdown(IF\_ETH0);  
while (ifpending(IF\_ETH0) == IF\_COMING\_DOWN)  
{  
tcp\_tick(NULL);  
yield;  
}  
ifconfig(IF\_ETH0,  
IFS\_DOWN,  
IFS\_IPADDR, aton(IPAddressString),  
IFS\_NETMASK, aton(SubnetString),  
IFS\_ROUTER\_SET, aton(DefaultGatewayString),  
IFS\_NAMESERVER\_SET, aton(DNSServerString),  
IFS\_UP,  
IFS\_END);

```
              yield;

               while (ifpending(IF_DEFAULT) == IF_COMING_UP)
              {
                  tcp_tick(NULL);
                 yield;
              }

            }while(ifpending(IF_DEFAULT) != IF_UP);
            //Network must be up so initialise http server, and reserve port 80 for multiple web connections
            http_init();
            tcp_reserveport(80);
           printf("set up network 

```

“);  
printf(”  
done");

```
        }
        //run the http server daemon and process TCP services
        http_handler();
        tcp_tick(NULL);
     	yield;
     }

```

Could you provide a code snippet to clear the list of routers please? -Paramjit WSE Ltd

---

<div class="post-metadata">

**Author:** ![petermcs](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@petermcs](https://forums.digi.com/u/petermcs)\
**Post date:** [July 27, 2015, 1:41am UTC](https://forums.digi.com/t/rabbit-board-4000/15165/5 "2015-07-27T01:41:33Z")

</div>

I fixed the problem in my case by changing the router\_del\_all() function in ARP.lib to the following:

// PMCS  
\_arp\_nodebug void router\_del\_all(void)  
{  
auto unsigned i;  
auto RTEntry \* rte;  
auto ATHandle ath;  
auto ATEntry \* ate;

```
// This function may be called pre-sock_init(). If so, then there will
// be no ARP cache entries, so flush will not be called.

```

LOCK\_GLOBAL\_IF\_INIT(TCPGlobalLock);  
#ifndef ARP\_MINIMAL  
#ifdef ARP\_VERBOSE  
printf("ARP: deleting all routers  
");  
#endif  
for (i = 0, rte = \_arp\_gate\_data; i \< ARP\_ROUTER\_TABLE\_SIZE; ++i, ++rte)  
if (rte-\>ath) {  
ath = ATH2INDEX(rte-\>ath);  
if (ath \< ARP\_TABLE\_SIZE)  
{  
ate = \_arp\_data + ATH2INDEX(ath);  
ate-\>flags &= ~ATE\_ROUTER\_ENT; // No router any more  
ate-\>ath = 0;  
\_arp\_unlink\_to(ate);  
}

```
		rte-&gt;ath = 0;
	}

```

#else  
memset(\_arp\_gate\_data, 0, sizeof(\_arp\_gate\_data));  
#endif  
UNLOCK\_GLOBAL\_IF\_INIT(TCPGlobalLock);  
}

This solved the crashing problem but will only work for boards with a single network interface. I’m going to have to figure out something better soon as I want to have a GPRS interface in addition to the Ethernet one.

---

<div class="post-metadata">

**Author:** ![wse-ltd.com](https://avatars.discourse-cdn.com/v4/letter/w/f07891/32.png) [@wse-ltd.com](https://forums.digi.com/u/wse-ltd.com)\
**Post date:** [July 28, 2015, 8:39am UTC](https://forums.digi.com/t/rabbit-board-4000/15165/6 "2015-07-28T08:39:14Z")

</div>

I am trying this today and will let you know how it goes. Thanks.

---

<div class="post-metadata">

**Author:** ![wse-ltd.com](https://avatars.discourse-cdn.com/v4/letter/w/f07891/32.png) [@wse-ltd.com](https://forums.digi.com/u/wse-ltd.com)\
**Post date:** [August 3, 2015, 11:02am UTC](https://forums.digi.com/t/rabbit-board-4000/15165/7 "2015-08-03T11:02:45Z")

</div>

looks like the main problem was the battery on the board needed replacing. It is now able to retain memory values after long power outage. thanks for the help.
