• AVR Freaks

Helpful ReplyHot!HTTP_NET works with DHCP and doesn't with STATIC IP (Solved)

Author
Luca Pascarella
Junior Member
  • Total Posts : 100
  • Reward points : 0
  • Joined: 2007/05/28 00:53:17
  • Location: The Netherlands
  • Status: offline
2020/02/18 04:41:27 (permalink)
0

HTTP_NET works with DHCP and doesn't with STATIC IP (Solved)

In a project with Harmony net 3.5.0 and a PIC32MZ EF I can correctly instantiate an HTTP_NET server when DHCP is enabled and working but it stops to work when DHCP is disabled and a static IP is, instead, assigned.
 
I have debug commands enabled at this time and obtain the following:
 
http info returns:
HTTP connections - active: 0, open: 4
HTTP conn: 0 status: 0x 0, sm: 0x 0, chunks: 0, chunk empty: 0, file empty: 0
HTTP conn: 1 status: 0x 0, sm: 0x 0, chunks: 0, chunk empty: 0, file empty: 0
HTTP conn: 2 status: 0x 0, sm: 0x 0, chunks: 0, chunk empty: 0, file empty: 0
HTTP conn: 3 status: 0x 0, sm: 0x 0, chunks: 0, chunk empty: 0, file empty: 0

 
http stat returns:
HTTP connections: 4, active: 0, open: 4
 
 
 
HTTP pool empty: 0, max depth: 0, parse retries: 0

 
netinfo returns:
---------- Interface <eth0/PIC32INT> ----------
 
 
 
Host Name: MCHPBOARD_E - NBNS disabled
IPv4 Address: 192.168.4.50
Mask: 255.255.255.0
Gateway: 192.168.4.1
DNS: 192.168.4.1
MAC Address: 93:db:12:90:80:1f
default IP address is ON
dhcp is disabled
Link is UP
Status: Ready

 
macinfo returns:
Interface: PIC32INT Driver Statistics
 
Receive Statistics
nRxOkPackets: 35
nRxPendBuffers: 0
nRxSchedBuffers: 4
nRxErrorPackets: 0
nRxFragmentErrors: 0
nRxBuffNotAvailable: 0
 
Transmit Statistics
nTxOkPackets: 3
nTxPendBuffers: 0
nTxErrorPackets: 0
nTxQueueFull: 0
 
Interface: PIC32INT Hardware Register Status
FRMTXOK : 0x3
FRMRXOK : 0x23
RXBUFCNT: 0x0
RXOVFLOW: 0x0
FCSERROR: 0x0
ALGNERR : 0x0
SCOLFRM : 0x0
MCOLFRM : 0x0

 
tcpinfo returns:

 
TCP sockets: 10
sktIx: 0, addType: 1, remotePort: 0, localPort: 80, rxSize: 2048, txSize: 2049, state: 0, rxPend: 0, txPend: 0
sktIx: 1, addType: 1, remotePort: 0, localPort: 80, rxSize: 2048, txSize: 2049, state: 0, rxPend: 0, txPend: 0
sktIx: 2, addType: 1, remotePort: 0, localPort: 80, rxSize: 2048, txSize: 2049, state: 0, rxPend: 0, txPend: 0
sktIx: 3, addType: 1, remotePort: 0, localPort: 80, rxSize: 2048, txSize: 2049, state: 0, rxPend: 0, txPend: 0

 
Any clue what am I missing or should I check?
post edited by Luca Pascarella - 2020/02/26 01:13:20
#1
Luca Pascarella
Junior Member
  • Total Posts : 100
  • Reward points : 0
  • Joined: 2007/05/28 00:53:17
  • Location: The Netherlands
  • Status: offline
Re: HTTP_NET works with DHCP and doesn't with STATIC IP 2020/02/19 00:52:40 (permalink)
0
Any idea so far? I am most probably missing something, but I cannot figure out what is wrong because the initialization ends successfully.
 
However, I discovered that not only incoming connections (HTTP server) are blocked but also outgoing connections. For example, the NTP cannot update the date, and TCPIP_SNTP_TimeGet always returns SNTP_RES_TSTAM_ERROR.
 
On the other hand, TCPIP_STACK_Status returns SYS_STATUS_READY, and my code continues the initialization as when the DHCP is enabled.
 
What should I start to check? I have zero ideas.
#2
Luca Pascarella
Junior Member
  • Total Posts : 100
  • Reward points : 0
  • Joined: 2007/05/28 00:53:17
  • Location: The Netherlands
  • Status: offline
Re: HTTP_NET works with DHCP and doesn't with STATIC IP 2020/02/19 05:42:20 (permalink)
0
I realized that if the device starts with the DHCP on and through commands I manually switch off DHCP the default IP works.
 
I used the following command to switch off the DHCP:
dhcp PIC32INT off

 
Now, the board has the default IP and the webserver works well, moreover, I can change the IP address with any in the subnet and it always works well.
 
setip PIC32INT 192.168.4.80 255.255.255.0

 
However, if the board boots with DHCP off the default IP does not work.
#3
ric
Super Member
  • Total Posts : 26973
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: HTTP_NET works with DHCP and doesn't with STATIC IP 2020/02/19 12:35:00 (permalink)
0
When you use static IP, you're also hard coding the gateway and DNS addresses. Are they correct?
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#4
Luca Pascarella
Junior Member
  • Total Posts : 100
  • Reward points : 0
  • Joined: 2007/05/28 00:53:17
  • Location: The Netherlands
  • Status: offline
Re: HTTP_NET works with DHCP and doesn't with STATIC IP 2020/02/19 23:30:15 (permalink)
0
Thank for the advice. I re-checked my initialization array TCPIP_NETWORK_CONFIG networkConfig by printing the content, and even this seems correct.
 
IP: 192.168.4.50
Mask: 255.255.255.0
Gtw: 192.168.4.1
DNS1: 192.168.4.1
DNS2: 0.0.0.0
Power: full
Flags: 0x8

 
I'm pretty sure I'm missing something, but still I cannot see what...
#5
Luca Pascarella
Junior Member
  • Total Posts : 100
  • Reward points : 0
  • Joined: 2007/05/28 00:53:17
  • Location: The Netherlands
  • Status: offline
Re: HTTP_NET works with DHCP and doesn't with STATIC IP 2020/02/20 04:11:34 (permalink)
5 (1)
Finally, I localized the problem.
 
When macAddr of TCPIP_NETWORK_CONFIG_FLAGS points to a null-terminated string that contains a custom MAC address e.g. "80:1F:12:AA:BB:CC" the TCPIP stack does not work. Apparently the TCPIP stack is initialized without issues but then it does nothing. When instead macAddr is set to NULL the TCPIP stack uses the internal MAC address and it works correctly.
 
For a coincidence when I set the static IP I also pass as a string the internal MAC address. Passing NULL the static IP works.
 
According to tcpip.h char* macAddr; can point to a string that contain a custom MAC address.
typedef struct
{
/* Pointer to the interface name; could be NULL. */
/* Note: Usually it's been one of the TCPIP_STACK_IF_NAME_xxx symbols: */
/* "ENCJ60", "ENCJ600", "97J60", "PIC32INT", "MRF24WN", "WINC", "WILC1000". */
/* However, the TCP/IP stack will assign an alias names for each interface */
/* (eth0, wlan0, etc. see TCPIP_STACK_IF_NAME_ALIAS_xxx), so this name is maintained */
/* for backward compatibility purposes only and will be eventually dropped. */
/* The native name of the interface in the form TCPIP_STACK_IF_NAME_xxx is */
/* present in the MAC driver for that interface (see the "tcpip/tcpip_mac_object.h" */
/* definition of TCPIP_MAC_OBJECT_TYPE). */
char* interface;
/* Valid Host name for this interface to use. Ex: "MCHPBOARD" */
char* hostName;
/* MAC address to use for this interface. */
/* Use "00:04:a3:00:00:00" or 0 for the factory preprogrammed address*/
char* macAddr;
/* Static IP address to use. Ex: "169.254.1.1"*/
char* ipAddr;
/* Netmask to use. Ex: "255.255.0.0"*/
char* ipMask;
/* Static Gateway to use. Ex: "169.254.1.1"*/
char* gateway;
/* Primary DNS to use. Ex: "169.254.1.1"*/
char* priDNS;
/* Secondary DNS to use. Use "0.0.0.0" for none */
char* secondDNS;
/* Power Mode to use. Use TCPIP_STACK_IF_POWER_NONE, TCPIP_STACK_IF_POWER_FULL, */
/* TCPIP_STACK_IF_POWER_LOW, or TCPIP_STACK_IF_POWER_DOWN*/
char* powerMode;
/* flags for interface start-up */
TCPIP_NETWORK_CONFIG_FLAGS startFlags;

 
Is this assumption wrong? Can I pass a string with an alternative MAC address at the initialization function?
#6
rainad
Moderator
  • Total Posts : 1329
  • Reward points : 0
  • Joined: 2009/05/01 13:39:25
  • Location: 0
  • Status: offline
Re: HTTP_NET works with DHCP and doesn't with STATIC IP 2020/02/25 07:50:04 (permalink) ☄ Helpfulby Luca Pascarella 2020/02/26 01:13:03
0
Yes, you can use your own MAC address in the initialization function.
But it's been reported that the Ethernet library function that sets the EMAC registers with the MAC address is wrong, shuffling the MAC address bytes.
I.e. when you specify the "80:1F:12:AA:BB:CC" the actual result in the registers will be: "BB:CC:12:AA:80:1F" (and this is an incorrect multicast address).
If you have a console connected to your app, command 'netinfo' will show the wrong MAC address.
This is a bug which will be solved in the next release.
For now probably the easiest is that you reorder the MAC address yourself, to result in the correct address.
 
P.S. I attach the file that holds the fix for this issue. It will be part of the next release. 
Simply replace the ..\app\firmware\src\config\pic32mz_ef_sk\driver\ethmac\src\dynamic\drv_eth_pic32_lib.c file in your app with this one and it will solve the issue.
 
post edited by rainad - 2020/02/25 11:21:33
#7
Luca Pascarella
Junior Member
  • Total Posts : 100
  • Reward points : 0
  • Joined: 2007/05/28 00:53:17
  • Location: The Netherlands
  • Status: offline
Re: HTTP_NET works with DHCP and doesn't with STATIC IP 2020/02/26 01:12:44 (permalink)
0
Great rainad. I confirm the MAC bytes shuffle.
 
Overwriting the MAC with a correct one it works correctly.
#8
boatbodger
Junior Member
  • Total Posts : 108
  • Reward points : 0
  • Joined: 2011/03/27 15:39:07
  • Location: 0
  • Status: offline
Re: HTTP_NET works with DHCP and doesn't with STATIC IP 2020/03/01 02:34:11 (permalink)
0
That's really helpful - I had spotted this problem independently, and simply mangled my MAC bytes to get round it - I am glad I no longer have to do that ;).  Thank you for sharing.
#9
Jump to:
© 2020 APG vNext Commercial Version 4.5