Open coelner opened 6 years ago
Hello, since the Arduino IDE doesn't provide a clean interface for uploading precompiled binaries I am not sure I see the benefit of going through the trouble. Maybe the platform can generate sketches with the API key baked in as an alternative.
At the same time, it adding a field for the authorisation token to the wifimanager will allow us to preprogramme sensors - less technical users then just have to enter their wifi details + auth code at home, and they are set, no need to touch the IDE for them.
Cheerio * W.
On Wed, Feb 14, 2018 at 12:34 PM, Thanasis Georgiou < notifications@github.com> wrote:
Hello, since the Arduino IDE doesn't provide a clean interface for uploading precompiled binaries I am not sure I see the benefit of going through the trouble. Maybe the platform can generate sketches with the API key baked in as an alternative.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hackair-project/hackAir-Arduino/issues/8#issuecomment-365576556, or mute the thread https://github.com/notifications/unsubscribe-auth/Ad8nOFO063Fv_e4ksMPXj_D-x-2hPsfRks5tUsS2gaJpZM4SEOFJ .
-- Wiebke Herding (+31 61 55 073 66) ON:SUBJECT | Momentum for Sustainability
wiebke@onsubject.eu http://www.onsubject.eu
this is the git diff for this feature. I don't know the real length of the token, this need to changed accordingly.
diff --git a/examples/Wemos-Advanced/Wemos-Advanced.ino b/examples/Wemos-Advanced/Wemos-Advanced.ino
index 819fc81..dfb72d3 100644
--- a/examples/Wemos-Advanced/Wemos-Advanced.ino
+++ b/examples/Wemos-Advanced/Wemos-Advanced.ino
@@ -24,7 +24,8 @@
// Replace the string below with your Authorization Token from the hackAIR
// platform
-#define AUTHORIZATION "AUTHORIZATION TOKEN"
+//#define AUTHORIZATION "AUTHORIZATION TOKEN"
+char hackair_auth_token[50] = "";
// Sensor initialization
hackAIR sensor(SENSOR_SDS011);
@@ -59,8 +60,13 @@ void setup() {
// Initialize temperature and humidity sensor
dht.begin();
+ // add token per webUI
+ WiFiManagerParameter hackair_authorization_token("hackair_auth_token", "hackAIR AUTH Token", hackair_auth_token, 49);
// Initialize the WiFi connection
WiFiManager wifiManager;
+ wifiManager.addParameter(&hackair_authorization_token);
+
+
if (!wifiManager.autoConnect("ESP-wemos")) {
Serial.println("failed to connect, please push reset button and try again");
delay(3000);
@@ -71,6 +77,8 @@ void setup() {
Serial.println("network connected:)");
Serial.println("Your local ip is:");
Serial.println(WiFi.localIP());
+ //copy token to our space
+ strcpy(hackair_auth_token, hackair_authorization_token.getValue());
}
void loop() {
@@ -129,7 +137,8 @@ void loop() {
client.print("Host: api.hackair.eu\r\n");
client.print("Connection: close\r\n");
client.print("Authorization: ");
- client.println(AUTHORIZATION);
+ //client.println(AUTHORIZATION);
+ client.println(hackair_auth_token);
client.print("Accept: application/vnd.hackair.v1+json\r\n");
client.print("Cache-Control: no-cache\r\n");
client.print("Content-Type: application/json\r\n");
Hello, I was just working on this but I realized that the custom settings are not being saved by the WiFi manager so they don't persist through reboots. This is problematic because the WiFi network is stored and if there is a power loss the device will enter a state of confusion, knowing where to connect but not the API key.
I see a couple of paths going on:
WiFiManager.clear()
at the start of the sketch to clear the saved WiFi network and redo the whole setup process on every boot. This is tedious since temporarily unplugging the device will reset all the settings.WiFiManager.clear()
will erase the saved networks but not the API key.Tell me your opinion on this so we can plan our next move.
I vote for option #2.
option 2 is the predefined behaviour (https://github.com/tzapu/WiFiManager#custom-parameters)
.
WiFiManager.clear()
only uses the features of the esp8266 core, which internally save the last connected network. Maybe this could be helpful: https://arduino-esp8266.readthedocs.io/en/latest/libraries.html#esp-specific-apis
it is possible to add custom entries to the wifimanager (https://github.com/tzapu/WiFiManager#custom-parameters) if we add an option to add the token while the setup process, we could provide precompiled images.