Go Down

Topic: #ifdef / #switchdef / array for upload to multiple targets (same HW) (Read 320 times) previous topic - next topic

s-light

hello community,

i will have to program ~20 ArduinoEthernet boards - all with the identical sketch -
but every board has a uniq mac and a ipaddress -
so i searching for an idea to 'define' the 'Hardware/Bord-Specific' parameters for all boards -
and than choose in an easy way which one to use for the current upload target (connected board)..

i have two different ideas till now -
1 - use a array to store all possible configs
Code: [Select]
tDeviceParameters dpDeviceList[] = {
{ // -- not used.
 0, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x00 }, // mac
IPAddress(192, 168, 222, 100), // ip
},
{ // development board
 1, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x4E }, // mac
IPAddress(192, 168, 222, 101), // ip
},
{ // test board
 2, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x43 }, // mac
IPAddress(192, 168, 222, 102), // ip
},
{ // second test board
 3, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x45 }, // mac
IPAddress(192, 168, 222, 103), // ip
},
};

tDeviceParameters dpThisDeviceX = dpDeviceList[1]; // number is identical with ID == identical with IPAddress ending.

problem: all infos are using space... but only one is used...

2 - use a list of #ifdef s
Code: [Select]
#define DEVICE_1

#ifdef DEVICE_1
tDeviceParameters dpThisDevice = {
// development board
 1, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x4E }, // mac
IPAddress(192, 168, 222, 101), // ip
};
#endif

#ifdef DEVICE_2
tDeviceParameters dpThisDevice = {
// second test board
 2, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x43 }, // mac
IPAddress(192, 168, 222, 102), // ip
};
#endif

#ifdef DEVICE_3
tDeviceParameters dpThisDevice = {
// second test board
 3, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x45 }, // mac
IPAddress(192, 168, 222, 103), // ip
};
#endif
//...

this is not so nice from the formating  ?!  8)

have someone out there another idea / concept to do something like this?
i have added my test sketch - its the basic UDPSendReceiveString Example with small modifications.
or is the compiler so clever to know that only one of the entrys in an array is used in the software?

sunny greetings
stefan

majenko

Option 3: give them all the same sketch, and store the MAC / IP in EEPROM.

MarkT

Yes, I'd suggest writing a config sketch that just takes the MAC / IP from serial and stores
it in the EEPROM, reads it back and prints to serial for confirmation, upload that
and run it for each board to configure.

Then upload the sketch that does what you want using EEPROM.   You can always
make the EEPROM uploading an option of the main sketch if you need to, of course.

You may want to use DHCP and avoid uploading the IP.

Also if you are using an ethernet or WiFi card it should have a MAC ROM already...
[ I won't respond to messages, use the forum please ]

s-light

thanks for the suggestion with the EEPROM.
i haven't worked with this up to now ;-)
so its a good idea to look into it.

the fixed ip is by design. in the system where this boards will be used are no dhcp. all server and clients have fixed ips.

Also if you are using an ethernet or WiFi card it should have a MAC ROM already...

iam using the ArduinoEthernet boards - so its the same like an UNO + Ethernet-Shield
so the W5100 has a programmed mac?
than i think there would be a option to read that out with the Ethernet library..

sunny greetings
stefan

Go Up