Setting parameters before system load
-
Hi
I want to set some of my parameters prior to the mySensors code loading. I want to set the NodeId on my sensors and things like the WiFi credentials on the gateway. The gateway can be ESP8266 or ESP32.
I noticed that was a preHwInit() function available. Will this allow me to set things like that before the code loads and if so where will I store or effect those parameters? -
NodeID is set by defining MY_NODE_ID. The assignment can be a variable if you want to set it dynamically yourself.
In the same manner you can probably set MY_WIFI_SSID and MY_WIFI_PASSWORD. I am not aware if anyone has tried setting them dynamically before, so you'll probably have to experiment a bit.
https://www.mysensors.org/download/sensor_api_20#node-boot-sequence describes when things are canned in the boot sequence.
-
Thanks for the reply. If use defined variables then I am sure it should be possible to do.
As far as the dynamic setting is concerned, I want to connect the sensor serial port to a terminal and then set the variables that I need through text messages. There is an Arduino library called sCmd that has a very basic protocol that allows this kind of thing. There will be a button to put it into setup loop before hardware init and then I need to write the variables to the Eeprom. They will be retrieved at the next boot. Hence my need to know where the system puts it's config variables so that I don't go mess that up. -
Thanks for the reply. If use defined variables then I am sure it should be possible to do.
As far as the dynamic setting is concerned, I want to connect the sensor serial port to a terminal and then set the variables that I need through text messages. There is an Arduino library called sCmd that has a very basic protocol that allows this kind of thing. There will be a button to put it into setup loop before hardware init and then I need to write the variables to the Eeprom. They will be retrieved at the next boot. Hence my need to know where the system puts it's config variables so that I don't go mess that up. -
That’s a really clever way to handle provisioning! To make sure you don't stomp on the MySensors internal data, check out the MyEEPROM.h file in the library source. MySensors usually starts its storage from the very beginning of the EEPROM (index 0), but you can usually find a safe 'offset' higher up (like above 256 or 512) to store your custom sCmd strings. Just make sure your preHwInit() reads from that same offset before the MySensors engine takes over!
-
This is very cool. In order to provision my devices, I had two programs. I loaded the first that was used to set MY_NODE_ID in location 0 of the MyEEPROM (this is where MySensors puts it). Then I would load the MySensors program.
The sCmd library is much better, though it would take up program space.