I was wondering if there is a way to pass parameters to an arduino sketch at the upload step.
Edit: The reason this would be helpful is because I have a bunch of esp8266 units that need to have details about their specific location but changing variables around per upload feels tedious.
If this is not possible the other solution that I am probably going to try is to have a sketch to just flash these details to eeprom and then read it from there whenever it is needed. Also storing them in eeprom feels a bit better than as literals in these sketches.
2 Answers 2
Every ESP8266 has a unique MAC address. You could that information to distinguish between the different units.
Something like if( mac='00:0a:95:9d:68:16' ){ ... }
-
Yes but I need each unit to know where it is located, I do not want to have an external lookup for its location.Chris Ryan– Chris Ryan2016年05月18日 18:43:18 +00:00Commented May 18, 2016 at 18:43
-
You could store all the locations in an array in your code. Then use the MAC address to look up the right location from the list. The only downside is that you need to know the locations and mac-addresses ahead of time.Gerben– Gerben2016年05月18日 18:49:13 +00:00Commented May 18, 2016 at 18:49
Another option, if you can afford the pins, is to install DIP switches or ground-jumpers on a few pins and set / wire a different n-bit code onto each board. Set those pins to INPUT_PULLUP, read them at setup, and wallah! each board is unique. You can put the lookup table (binary number -> parameter string, f/ex) in Flash so it doesn't take up scarce RAM.
-
To add to the above, you could use two pins with dip switches and add resisters to make a ladder. then just read the R value?CapeCoder– CapeCoder2017年01月24日 14:21:30 +00:00Commented Jan 24, 2017 at 14:21
-
In that case you'd only need one (analog) pin.JRobert– JRobert2017年01月30日 15:04:40 +00:00Commented Jan 30, 2017 at 15:04
dd