I've done more work on this since your follow-up. I see the logic in the pointer, however,
const char *SSID = SECRET_SSID;
would be a modification to the auto-generated 'thingProperties.h' file from the Cloud editor. If I was using the IDE the approach would be different, using commands like,
WiFi.begin(SSID, PASS);
// do some things to change SSID over Modbus to update a new SSID
WiFi.disconnect();
WiFi.begin(SSID, PASS);
But in moving off the IDE so as to utilize the OTA and cloud services, the traditional .ino files need to be stored as a Thing with all edits and compiling being done through the Cloud. Which then presents the problem of modifying auto-generated .h files as noted above...
The file 'thingProperties.h' has
#include <Arduino_ConnectionHandler.h>
which makes reference to 'WiFi.h' when looking at the source code on Github.
I'm easily moving character I/O between the OPTA and the external HMI with Modbus. But ultimately, I need to change the SSID and PASS variables through the HMI display (I want to be able to install a product in the field and configure site WiFi without having to bring a laptop).
I've tried this:
char wifiAddressConfig[32];
void setup() {
// ...
}
void loop() {
// ...
ModbusRTUClient.requestFrom(2, HOLDING_REGISTERS, 100, 16);
while( ModbusRTUClient.available() ) {
// Wifi SSID is 32 characters = max of 2x16 Holding Registers
uint16_t wifiAddressRead = ModbusRTUClient.read();
uint8_t wifiAddressReadW1 = wifiAddressRead;
uint8_t wifiAddressReadW2 = wifiAddressRead >> 8;
wifiAddressConfig[2*i] = (char) wifiAddressReadW1;
wifiAddressConfig[2*i+1] = (char) wifiAddressReadW2;
i=i+1;
}
Serial.println("changed wifi address");
Serial.println(wifiAddressConfig);
// disconnect from existing network and connect to new network
WiFi.disconnect();
// ...
}
Interestingly, this does break the current Wifi connection and returns error code '6' to the Serial console. However, the connection reestablishes itself under the original SSID compiled from the Cloud.
If I add to the code above,
SSID = wifiAddressConfig;
WiFi.disconnect();
I get a compile error,
error: assignment of read-only variable 'SSID'
Or try adding to loop() something crazy like,
ArduinoCloud.begin(WiFiConnectionHandler(wifiAddressConfig, PASS));
hoping that maybe this will update the cloud connection without thinking through consequences of all the header files involved here... I get a very detailed compiler error,
error: cannot bind non-const lvalue reference of type 'ConnectionHandler&' to an rvalue of type 'ConnectionHandler'
I found a post on Github for a request to shut down the ArduinoCloud service through something like
ArduinoCloud.end()
but no work has been done to my knowledge or searching.
Clearly SSID must be saved to memory. There should be a way to overwrite it?
Thank you for any help,
Chris