Following problem was to solve:
Distributing an ESP32 or ESP8266 Thinger solution without requiring the user to compile a version with his own credentials.
I don’t want use the usual way of a temporary website to enter the credentials.
That is a very clumsy solution requiring a lot of code and program space (all the HTML code must be in program space)
Even for the user it is absolutely not straight forward…
SmartConfig is a nice solution, but only provides SSID and Password, you need th Thinger.io credentials as well.
For Thinger, you need at least: SSID, WiFiPassword, Device Name, Thinger Account, Device Credentials (the rest of the options and parameters can then be gathered from the Thinger properties)
My solution is quite simple, elegant and requires practically no additional ESP code, no library and nothing to install at user’s side. (excepted Python, which he needs anyway to upload the binary).
It is a Python script that patches the credentials into your compiled binary.
It works that way:
In your ESP code, you define placeholders for your credentials and make them long enough to potentially fit any user’s content.
Here:
#define DEVICE_NAME "DEVCNAME "
#define WIFI_SSID "WIFISSID "
#define WIFI_PASS "WIFIPASS "
#define THINGER_USERNAME "CLOUDNAM "
#define DEVICE_CREDENTIALS "DEVCCRED "
The placeholders MUST match exactly those defined in the provided PythonPatcher.py Python script.
You then compile your code and distribute the raw binary together with PythonPatcher.py
The user places the two files on his desktop and runs the PythonPatcher.py.
The script will ask for the file to patch, and the credentials and patch the binary accordingly, saving the patched file on the destop too:
%Run PythonPatcher.py
Enter binfile to patch:PythonTest.bin
Enter SSID:GW-****
Enter Password:*******
Enter Device Name:Steroids
Enter Cloud User Name:Thing4
Enter Device Credentials:*******
File PythonTest_patched.bin saved
You then upload the patched file to the ESP and you are online at Thinger !
Soo easy…
Caveats:
This solution is not suitable to distribute an ESP device including code, the user must patch and upload himself.
You must take care to use the credentials only at one place of your code (if you need it a several places, copy it to a String-variable).
In my example, the placeholders are 16 chars long, the placeholder for WiFI password is 24 chars long
You might use longer strings in your code and match them in the PythonPacher.
The Python script is on Github: