Dear all.
I have get 4 PCS web platform v1.1. all are well with factory setting and own compile. now i want to assign static ip for that. when i have disable #define STACK_USE_DHCP_CLIENT and AppConfig.Flags.bIsDHCPEnabled = TRUE; to AppConfig.Flags.bIsDHCPEnabled = FALSE; its not working. i am also confuse about eeprom, its not format with new ip . how can i get out from this problem?
thanks
Masud
Hi Masud - It looks like you're on the right track. With DCHP client you will need set the correct addresses for all the network resources here:
//MAC, IP settings, etc
#define MY_DEFAULT_HOST_NAME "DP-WP"
#define MY_DEFAULT_MAC_BYTE1 0x00
#define MY_DEFAULT_MAC_BYTE2 0x04
#define MY_DEFAULT_MAC_BYTE3 0xA3
#define MY_DEFAULT_MAC_BYTE4 0x00
#define MY_DEFAULT_MAC_BYTE5 0x10
#define MY_DEFAULT_MAC_BYTE6 0x05
//be sure to use XXXul to avoid warnings
#define MY_DEFAULT_IP_ADDR_BYTE1 192ul
#define MY_DEFAULT_IP_ADDR_BYTE2 168ul
#define MY_DEFAULT_IP_ADDR_BYTE3 1ul
#define MY_DEFAULT_IP_ADDR_BYTE4 100ul
#define MY_DEFAULT_MASK_BYTE1 255ul
#define MY_DEFAULT_MASK_BYTE2 255ul
#define MY_DEFAULT_MASK_BYTE3 0ul
#define MY_DEFAULT_MASK_BYTE4 0ul
#define MY_DEFAULT_GATE_BYTE1 192ul
#define MY_DEFAULT_GATE_BYTE2 168ul
#define MY_DEFAULT_GATE_BYTE3 1ul
#define MY_DEFAULT_GATE_BYTE4 1ul
#define MY_DEFAULT_PRIMARY_DNS_BYTE1 192ul
#define MY_DEFAULT_PRIMARY_DNS_BYTE2 168ul
#define MY_DEFAULT_PRIMARY_DNS_BYTE3 1ul
#define MY_DEFAULT_PRIMARY_DNS_BYTE4 1ul
#define MY_DEFAULT_SECONDARY_DNS_BYTE1 0ul
#define MY_DEFAULT_SECONDARY_DNS_BYTE2 0ul
#define MY_DEFAULT_SECONDARY_DNS_BYTE3 0ul
#define MY_DEFAULT_SECONDARY_DNS_BYTE4 0ul
Thanks for fast reply.
yes i have also change that way but not work. Can u help with your code where i can format eeprom. or how can i change ip from web page . please see attach.
I'm sorry, I've never tried to use it with a static IP, and I'm not sure how it works. Maybe someone else has some ideas.
I never had any luck getting the web config page to work, but as DHCP worked, I didn't spend a lot of time on it.
[quote author="Trev"]
I never had any luck getting the web config page to work, but as DHCP worked, I didn't spend a lot of time on it.
[/quote]
Thanks for your information. where should i change code for fixed ip . i am so confused. please help
thanks
[quote author="masud58"]
where should i change code for fixed ip . [/quote]
It's not something I have done, so your guess is as good as mine. I'd suggest you start by consulting the TCP/IP stack help file and the source code.
Hi masud58
I think I might be able help a bit here.
First of all you need to understand a few networking concepts:
1. What you have with a web platform is an ethernet connection. This only need it needs is a MAC address to work. It doesn't understand IP addresses. It sends and recieves packets of data at whats known in networking talk as layer 2. The controller knows its own MAC address and can send and recieve packets on the ethernet with this address at layer 2. It can also send and recieve layer 2 packets on the layer 2 (ethernet) broadcast address.
2. IP address are soft (i.e changable) and in network language IP is a layer 3 service. To make IP addressing work a service called ARP (Address Resolution protocol) is used to figure out the correspondance between IP address and MAC address it uses layer 2 services (ethernet) to broadcast a request to figure out who has what IP address. This works simply as follows. If a host wants to send an IP packet it first consults the ARP cache (a table that translates IP addresses to MAC addresses). If the IP address is found it send the packet directly to the MAC address of the the host concerned. However if its not in the ARP cache then it sends an ARP request to the IP broadcast address which the layer 2 service sends to the MAC broadcast address. Any host running a TCPIP must implemnt an ARP service, so when an ARP request is sent all hosts on the ethernet (layer 2) consult there configured IP addresses. and only the host that has the matching IP address responds with an ARP reply that it has that IP address. On recieving the ARP response the orginating host stores the response in the ARP cache and then addresses the packet to the host with the corresonding MAC address.
Phew ok now to your problem. You say setting the IP address doesn't help i.e. its still not working, What is most likely wrong is that ARP is not working. For it work correctly you need to specifiy the the correct IP broadcast address. Usually this is worked out using the netmask. So you need to collect some information
1. IP address of the network you wish to connect to: (E.g 192.168.2.x)
2. The IP network netmask this must be correct or ARP won't work.
3. Sometime you can specify the broadcast IP address directly (Note not required in this case)
The first two item are configured in the place where IAN shown you above.
If the above is correct set then you then may have a routing problem which will occur if you are trying to send packets outside your local sub net (LAN/ethernet). Here you need to specify the default router address it must be inside your local sub net. if this is correct you will need to post details of your network setup. So I can take a look it would be advisable to also try to attach a network trace using Wireshark on a host attached to the same network as the Web Platform.
Remember network configuration is quite complex and the above is only just enough to let you understand the what involved and what can go wrong. I'm not a networking expert by am means but I setup and got working quite a few networks. Also I'd be very carefull with removing DHCP from the web platform. The screen you show above is a web screen and presumes that you can talk to the web platform before you can change it. Its not a PC were you can quickly change the IP address if its wrong and you have a bunch of tools to help you set it up.
Hope this helps
Cheers
Ron
Mausd
Just another thought to my reply above you should try with DHCP enabled first as the configuration Ian has pointed you to sets the default configuration if DHCP response is not recieved. It won't hurt to leave this enabled as long as no DHCP server is present. So don't disable the DHCP service leave it in and configure the default IP addresses details as Ian has pointed you to. Also I not sure if its clear but you
will not be able to use the web based configuration page unless you can make a web connection to the web platform. The only way you can make static IP addressing work is to correctly configure it in the first place in your code. If you disable the DHCP client option you may end up not having any IP address at all. So try enabling DHCP and setting the default IP address and make sure the netmask is correct as well. So you need this to be enabled.
#define STACK_USE_DHCP_CLIENT
Note that the setup below allows for 65535 hosts to be connected. Are you sure you need this many
#define MY_DEFAULT_IP_ADDR_BYTE1 192ul
#define MY_DEFAULT_IP_ADDR_BYTE2 168u
l#define MY_DEFAULT_IP_ADDR_BYTE3 1ul
#define MY_DEFAULT_IP_ADDR_BYTE4 100ul
#define MY_DEFAULT_MASK_BYTE1 255ul
#define MY_DEFAULT_MASK_BYTE2 255ul
#define MY_DEFAULT_MASK_BYTE3 0ul
#define MY_DEFAULT_MASK_BYTE4 0ul
A more standard setup would be to change the netmask to be 255.255.255.0 to allow for 256 hosts
change the line
#define MY_DEFAULT_MASK_BYTE3 0ul to #define MY_DEFAULT_MASK_BYTE3 255ul
Once you get this working using the DHCP default address then you will need to find out how the IP address is set.
You can use the find in files feature using "MY_DEFAULT_IP_ADDR_BYTE1" as the target in your IDE (MPLAB). I'll have a look tonight after I've rolled back my own stack and compiler versions and if I can quickly figure out where the IP address is set.
If you need more help you will need to explain the network that you are trying to connect to as its a bit difficult to understand what you are trying to achieve from what you have told us so far.
Cheers
Ron
wow . I cant express my fillings behave of you. many many thanks.
yes its true that its not for hobby. i will follow your guide. let me time to check all procedure. also i am not expert about that. i can show you all thing with debuging. please wait.
Thanks
masud
Hi Masud
I checked out how the IP address is set as promised.
Heres what I found
StackTsk.h Line 89 defines the structure that hold the IP address and netmask etc
// Application-dependent structure used to contain address information
typedef struct __attribute__((__packed__))
{
IP_ADDR MyIPAddr; // IP address
IP_ADDR MyMask; // Subnet mask
IP_ADDR MyGateway; // Default Gateway
IP_ADDR PrimaryDNSServer; // Primary DNS Server
IP_ADDR SecondaryDNSServer; // Secondary DNS Server
IP_ADDR DefaultIPAddr; // Default IP address
IP_ADDR DefaultMask; // Default subnet mask
BYTE NetBIOSName[16]; // NetBIOS name
struct
{
unsigned char : 6;
unsigned char bIsDHCPEnabled : 1;
unsigned char bInConfigMode : 1;
} Flags; // Flag structure
MAC_ADDR MyMACAddr; // Application MAC address
#if defined(ZG_CS_TRIS)
BYTE MySSID[32]; // Wireless SSID (if using ZG2100M)
#endif
#if defined(STACK_USE_SNMP_SERVER)
// SNMPv2C Read community names
// SNMP_COMMUNITY_MAX_LEN (8) + 1 null termination byte
BYTE readCommunity[SNMP_MAX_COMMUNITY_SUPPORT][SNMP_COMMUNITY_MAX_LEN+1];
// SNMPv2C Write community names
// SNMP_COMMUNITY_MAX_LEN (8) + 1 null termination byte
BYTE writeCommunity[SNMP_MAX_COMMUNITY_SUPPORT][SNMP_COMMUNITY_MAX_LEN+1];
#endif
} APP_CONFIG;
then in MainDemo.c line 33 a variable of the type is created
APP_CONFIG AppConfig;
it is initalized in MainDemo.c line 64 from the defines in TCPIPConfig.h
AppConfig.MyIPAddr.Val = MY_DEFAULT_IP_ADDR_BYTE1 | MY_DEFAULT_IP_ADDR_BYTE2<<8ul | MY_DEFAULT_IP_ADDR_BYTE3<<16ul | MY_DEFAULT_IP_ADDR_BYTE4<<24ul;
AppConfig.DefaultIPAddr.Val = AppConfig.MyIPAddr.Val;
AppConfig.MyMask.Val = MY_DEFAULT_MASK_BYTE1 | MY_DEFAULT_MASK_BYTE2<<8ul | MY_DEFAULT_MASK_BYTE3<<16ul | MY_DEFAULT_MASK_BYTE4<<24ul;
AppConfig.DefaultMask.Val = AppConfig.MyMask.Val;
Looking at your last post it appears that you have more than one web platform on the same LAN. if this is the case then you will need to adjust the MAC address in TCPIPConfig.h because the MAC address is supposed to be unique. Note the top two bytes are assigned to each interface/chip manufacturer's so don't alter that Just changethe last byte (MY_DEFAULT_MAC_BYTE6 ) by 1 for each extra web platform you connect.
Your ethernet won't run properly if you have two or more controllers with the same MAC address.
#define MY_DEFAULT_MAC_BYTE1 0x00
#define MY_DEFAULT_MAC_BYTE2 0x04
#define MY_DEFAULT_MAC_BYTE3 0xA3
#define MY_DEFAULT_MAC_BYTE4 0x00
#define MY_DEFAULT_MAC_BYTE5 0x10
#define MY_DEFAULT_MAC_BYTE6 0x05 <== change to 0x06 for second and 0x07 for the third etc
You should be able to disable DHCP client as you intended. As code in the main routine will set the IP address, however you will need to change the MAC address as noted above if you have more than one Web Platform on the same LAN.
Hope this helps.
Ron
Thanks for your taking challenge. my connection is as above.
pc Lan card to hub port 1. which ip is 192.168.2.3
web platform to hub port2. which ip is 192.168.2.2
IP Phone to hub port 3. which ip is 192.168.2.1 its like a server with dhcp enable. bcause i dont know. Grandstream Handy tone 486.
nothing are connected on that network. if i unplugged IP phone all network stop. i have attached capture file from winshark.
thanks
masud
if i change mac add for another thats work. and its get ip 192.168.2.4 another thanks for point out.
may be i have solved this problem . my red eyes says to get rest. i will come with details next day.
thanks
masud
Hi Masud
Yes get some rest that will help you think clearly. From what you describe you need to change the MAC address for each web platform board you have. I'll take a look at the trace you attached shortly. But from what you say it sounds like the IPhone is as you say a DHCP server and possibly the default router and DNS server. So if you disconnect the IPhone i would expect networking to stop at around the end of the DHCP lease time. The address you have the IP you have assigned to the IPhone is traditionally assigned for what is know as the default router. This means that if one of the web platforms wants or needs to respond back to a host thats not in your local area network it will send packets (data) to the default router IP address. Its import to know if you are trying to access the web platforms from other LANS. Checking the Wireshark trace will give me more clues. But I don't have Wireshark installed on this computer. Let me do that now.
Ron
Mausd
Ok I've looked at the Wireshark trace you attached and yes you have the host with IP address acting as a DHCP server. Reading back through your post I can see what you are trying to do. What you need to do to get all 4 Web Platforms working its this, you need to change the MAC and IP address you use together. I'll try to make this simple as english is not your native language.
MAC Address IP Address Net Mask Define Statement
00.04.A3.00.10.05 192.168.2.2 255.255.255.0 #define MY_DEFAULT_MAC_BYTE6 0x05
00.04.A3.00.10.06 192.168.2.4 255.255.255.0 #define MY_DEFAULT_MAC_BYTE6 0x06
00.04.A3.00.10.07 192.168.2.6 255.255.255.0 #define MY_DEFAULT_MAC_BYTE6 0x07
00.04.A3.00.10.08 192.168.2.7 255.255.255.0 #define MY_DEFAULT_MAC_BYTE6 0x08
You must change that MAC addresses to make it so there are no duplicate MAC address This
is very importabt.
If you want to use static IP addresses and I can understand why you do don't connect or use the IPhone as a DHCP server
this will not help you if you want to use IP addresses in the working system. You may also need to set the default router. From the trace I can see that its being set to the to 192.168.2.1 probably need to set this in your code as well.
Please congratulate yourself for getting this far you are having to deal with a complex technical subject in a foreign language. As we say here in New Zealand well done "Mate". I know some of this because while I was born and raised in New Zealand english is not my first language either. Just remember lots of english speaking people will not be able to understand the network language we have been use either even though its english.
Keep up the good work and I hope you get a bonus or something for all your hard work.
Ron
Hi Masud
I just analysised the trace you sent again as I was puzzled by your comment
if i unplugged IP phone all network stop.
Now I understand why. In the completion of the DHCP protocol the lease time (the time that the client is allowed to use the IP address given). Is one minute or 60 seconds this is very short. According to the DHCP protocol the client will try to get an new lease typical around half the lease time or in your case 30 seconds. So If you disconnect the DHCP server (IPhone) networking will stop within 30 seconds of you doing this. Which is what you see in your case.
Stop using the DHCP server and sort out the static IP addressing
Keep up the battle I think you have almost won.
Cheer
Ron
Mausd
Just quick comfirmation post. I disabled the use of DHCP and set the IP address and Netmask in the TCPIPConfig.h file and built and deployed it to the web plaform I was able to ping it and connect to using IE 6 web browser. This shows that all need to do to get your 4 web platforms to work is to make sure each web plaform has a different MAC address. This shows that you can use static IP addresses basically as Ian told you.
Cheers
Ron
yes its work. many many thanks. i am comming with all my error. after 14 hour deep sleep. i an now fresh.
Its my fault. I dint check my Lan card ip setup. when i change wp ip to similar (not same)with my Lan card. its work without IPphone. its a basic error. so sorry for that. but i learned more. but i cant write step by step. because Ronz point out . about my english. i am not an tcp/ip expert. i am working on power environment. now its time to go for freedom of web platform. Thanks Ian , Ronz, Trev , another request to Ian, Please Change Dangerous. because its hurt me when i was go for custom clear. anyway many many thanks.
Mausd
Excellent news, well done, go and celebrate as your culture permits.
Ron
Thanks for the update and photo, I'm glad you got it going.
RonZ - Thanks for the great troubleshooting. You gave great info, and I really enjoyed following your posts.
Thanks
our culture didnt permits enjoy alone. you are all invited. now i am going for webpage template. which is compatible with wp all io pin. on/off switch with status call back. i want to control array of relay and one adc . any idea ?
Masud
Ok understood re the celebration in New Zealand we say go and have a beer you deserve it. But that our culture not yours. I hope now you can concentrate on getting the monitoring and control working. The power of collaboration via the internet ably demonstrated. Good luck in completing the project.
Ian
No problem happy to help. I've got a Web Platform and Logic Analyzer direct from seed studios, also go a bus pirate made local here in Wellington New Zealand I've found it a useful tool. I must admit to feeling a bit guilty not supporting you after I bought the bus pirate but I wanted the Web Platform and Logic Analyzer any way so I felt better after at least supporting DP and being able to help
Ron
also go a bus pirate made local here
Do you have a link, or a picture? I love to see the design in the wild, I never dreamed it would go so far!
Ian
Ok I'll organize a photo in the next day or two and post it in a new thread. It came with a perspex case for NZ$45. Im off to bed as its 11:30pm here in New Zealand (GMT +13 hours) otherwise I do it now its not difficult. I've also made a crude case for the Web Platform I'll include it as well. The Bus Pirate a copy of version v2go and a New Zealand company mindkits also sells Bus Pirates for NZ$50. They are the ones from Sparkfun http://www.mindkits.co.nz/store/prototyping/Bus-Pirate (http://www.mindkits.co.nz/store/prototyping/Bus-Pirate) is the link.
Ron
[quote author="masud58"]
now i am going for webpage template. which is compatible with wp all io pin. on/off switch with status call back. i want to control array of relay and one adc . any idea ?
[/quote]
How many relays? I used the default Microchip demo web page LEDs to control 4 relays connected to the I/O1 header. I believe all I changed was:
In MainDemo.c
//setup LEDs
LED0_TRIS = 0;
LED1_TRIS = 0;
LED2_TRIS = 0;
LED3_TRIS = 0; // TR addition
LED4_TRIS = 0; // TR addition
LED0_IO = 1;
LED1_IO = 1;
LED2_IO = 1;
LED3_IO = 1; // TR addition
LED4_IO = 1; // TR addition
In HardwareProfile.h
#define LED0_TRIS TRISAbits.TRISA8 // LD1
#define LED0_IO LATAbits.LATA8
#define LED1_TRIS TRISAbits.TRISA9 // LD2 (IO1)
#define LED1_IO LATAbits.LATA9
#define LED2_TRIS TRISCbits.TRISC3 // IO2
#define LED2_IO LATCbits.LATC3
#define LED3_TRIS TRISCbits.TRISC4 // IO3
#define LED3_IO LATCbits.LATC4
#define LED4_TRIS TRISCbits.TRISC5 // IO4
#define LED4_IO LATCbits.LATC5
#define LED5_TRIS TRISCbits.TRISC5 //map these bits to the same pin
#define LED5_IO LATCbits.LATC5 //as we don't have more leds
#define LED6_TRIS TRISCbits.TRISC5
#define LED6_IO LATCbits.LATC5
#define LED7_TRIS TRISCbits.TRISC5
#define LED7_IO LATCbits.LATC5
I/O1 Header
IO1 = Control line for to relay 1 (inline 220K resistor to avoid transients during (re)boot as shared with LD2)
IO2 = ditto relay 2
IO3 = ditto relay 3
IO4 = ditto relay 4
IO9 = Gnd to relay board
IO10 = 3V3 to relay board
IO5-8 are still unused.
Hello all.
I have customize code above for my requirement.
7 IO for relay(led). 1 IO for heartbeat. i have also edit demo web page with password protection.
in HardwareProfile
// dsPIC33F processor
#define GetSystemClock() 80000000 //Hz
#define GetInstructionClock() (GetSystemClock()/2)
#define GetPeripheralClock() GetInstructionClock()
#define LED0_TRIS TRISAbits.TRISA8
#define LED0_IO LATAbits.LATA8
#define LED1_TRIS TRISAbits.TRISA9
#define LED1_IO LATAbits.LATA9
#define LED2_TRIS TRISCbits.TRISC3
#define LED2_IO LATCbits.LATC3
#define LED3_TRIS TRISCbits.TRISC4
#define LED3_IO LATCbits.LATC4
#define LED4_TRIS TRISCbits.TRISC5
#define LED4_IO LATCbits.LATC5
#define LED5_TRIS TRISBbits.TRISB6
#define LED5_IO LATBbits.LATB6
#define LED6_TRIS TRISBbits.TRISB5
#define LED6_IO LATBbits.LATB5
#define LED7_TRIS TRISBbits.TRISB8
#define LED7_IO LATBbits.LATB8
//#define BUTTON0_TRIS TRISBbits.TRISB6
//#define BUTTON0_IO PORTBbits.RB6
//#define BUTTON1_TRIS TRISBbits.TRISB5
//#define BUTTON1_IO PORTBbits.RB5
//#define BUTTON2_TRIS TRISBbits.TRISB8
//#define BUTTON2_IO PORTBbits.RB8
//#define BUTTON3_TRIS TRISBbits.TRISB7
//#define BUTTON3_IO PORTBbits.RB7
#define LED_GET() (0)
#define LED_PUT(a)
in CustomHTTPApp
/****************************************************************************
Section:
GET Form Handlers
***************************************************************************/
/*****************************************************************************
Function:
HTTP_IO_RESULT HTTPExecuteGet(void)
Internal:
See documentation in the TCP/IP Stack API or HTTP2.h for details.
***************************************************************************/
HTTP_IO_RESULT HTTPExecuteGet(void)
{
BYTE *ptr;
BYTE filename[20];
// Load the file name
// Make sure BYTE filename[] above is large enough for your longest name
MPFSGetFilename(curHTTP.file, filename, 20);
// If its the forms.htm page
if(!memcmppgm2ram(filename, "forms.htm", 9))
{
// Seek out each of the four LED strings, and if it exists set the LED states
ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led7");
if(ptr)
LED7_IO = (*ptr == '1');
ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led6");
if(ptr)
LED6_IO = (*ptr == '1');
ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led5");
if(ptr)
LED5_IO = (*ptr == '1');
ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led4");
if(ptr)
LED4_IO = (*ptr == '1');
ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led3");
if(ptr)
LED3_IO = (*ptr == '1');
ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led2");
if(ptr)
LED2_IO = (*ptr == '1');
ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led1");
if(ptr)
LED1_IO = (*ptr == '1');
}
// If it's the LED updater file
[attachment=1]
[attachment=0]
Nice work, thanks for sharing your code changes.