diff --git a/src/ThingerClient.h b/src/ThingerClient.h index 6c2e081..aaa5bea 100644 --- a/src/ThingerClient.h +++ b/src/ThingerClient.h @@ -135,6 +135,7 @@ class ThingerClient : public thinger::thinger { * Without a small delays between readings, the MKRGSM1400 seems to miss information, i.e, reading a byte * after a byte. Maybe it is related to UART communication. */ + delay(50); #ifdef ARDUINO_SAMD_MKRGSM1400 delay(2); #endif @@ -567,4 +568,4 @@ inline bool inputResource(pson& in, String& value){ inputValue_2(__VA_ARGS__),\ inputValue_1(__VA_ARGS__)\ ) -#endif \ No newline at end of file +#endif diff --git a/src/ThingerSmartConfig.h b/src/ThingerSmartConfig.h index 88abbd6..0d907fd 100644 --- a/src/ThingerSmartConfig.h +++ b/src/ThingerSmartConfig.h @@ -61,6 +61,12 @@ class ThingerSmartConfig : public ThingerClient { // try to connect to the last known Wifi Network if(WiFi.SSID()!=NULL){ THINGER_DEBUG_VALUE("NETWORK", "Trying to connect to the last known network: ", WiFi.SSID()); + + // Modes that fix Fatal exception 28(LoadProhibitedCause) (https://github.com/thinger-io/Arduino-Library/issues/28) + WiFi.persistent(false); + WiFi.mode(WIFI_OFF); + WiFi.mode(WIFI_STA); + unsigned long wifi_timeout = millis(); WiFi.begin(WiFi.SSID().c_str(), WiFi.psk().c_str()); while(WiFi.status() != WL_CONNECTED && (millis() - wifi_timeout < WIFI_CONNECTION_TIMEOUT_MS)) { @@ -77,6 +83,9 @@ class ThingerSmartConfig : public ThingerClient { if(WiFi.status() != WL_CONNECTED){ unsigned long wifi_timeout = millis(); THINGER_DEBUG("NETWORK", "Waiting Smart Config..."); + WiFi.persistent(false); + WiFi.mode(WIFI_OFF); + WiFi.mode(WIFI_STA); WiFi.stopSmartConfig(); WiFi.beginSmartConfig(); while(!WiFi.smartConfigDone()) { @@ -136,4 +145,4 @@ class ThingerSmartConfig : public ThingerClient { #endif }; -#endif \ No newline at end of file +#endif diff --git a/src/thinger/thinger.h b/src/thinger/thinger.h index 04be395..19fc67b 100644 --- a/src/thinger/thinger.h +++ b/src/thinger/thinger.h @@ -258,7 +258,7 @@ namespace thinger{ * @param data data to write defined in a pson structure * @return */ - bool write_bucket(const char* bucket_id, pson& data, bool confirm_write=false){ + bool write_bucket(const char* bucket_id, pson& data, bool confirm_write=true){ thinger_message message; message.set_signal_flag(thinger_message::BUCKET_DATA); message.set_identifier(bucket_id); @@ -272,7 +272,7 @@ namespace thinger{ * @param resource_name resource defined in the code, i.e., thing["location"] * @return */ - bool write_bucket(const char* bucket_id, thinger_resource& resource, bool confirm_write=false){ + bool write_bucket(const char* bucket_id, thinger_resource& resource, bool confirm_write=true){ thinger_message message; message.set_signal_flag(thinger_message::BUCKET_DATA); message.set_identifier(bucket_id); @@ -286,7 +286,7 @@ namespace thinger{ * @param resource_name resource identifier defined in the code, i.e, "location" * @return */ - bool write_bucket(const char* bucket_id, const char* resource_name, bool confirm_write=false){ + bool write_bucket(const char* bucket_id, const char* resource_name, bool confirm_write=true){ return write_bucket(bucket_id, resources_[resource_name], confirm_write); } @@ -589,4 +589,4 @@ namespace thinger{ }; } -#endif \ No newline at end of file +#endif