From a2b8d9b579a87d4e626c25a2bd2b134450cf2c7e Mon Sep 17 00:00:00 2001 From: Denis Tregubov Date: Wed, 30 Oct 2019 21:20:31 +0300 Subject: [PATCH 1/3] Deepsleep issue fixed --- src/ThingerClient.h | 4 +++- src/ThingerSmartConfig.h | 11 ++++++++++- src/thinger/thinger.h | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ThingerClient.h b/src/ThingerClient.h index 6c2e081..58daee6 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 @@ -402,6 +403,7 @@ class ThingerClient : public thinger::thinger { void handle(){ if(handle_connection()){ synchronized(size_t available = client_.available();) + //THINGER_DEBUG_VALUE("THINGER", "Available bytes: ", available); #ifdef _DEBUG_ if(available>0){ THINGER_DEBUG_VALUE("THINGER", "Available bytes: ", available); @@ -567,4 +569,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..2879784 100644 --- a/src/thinger/thinger.h +++ b/src/thinger/thinger.h @@ -589,4 +589,4 @@ namespace thinger{ }; } -#endif \ No newline at end of file +#endif From 9fbf9c67d2bc9650e8c7f058832db55126942eee Mon Sep 17 00:00:00 2001 From: Denis Tregubov Date: Wed, 30 Oct 2019 21:24:50 +0300 Subject: [PATCH 2/3] extra comments removed --- src/ThingerClient.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ThingerClient.h b/src/ThingerClient.h index 58daee6..aaa5bea 100644 --- a/src/ThingerClient.h +++ b/src/ThingerClient.h @@ -403,7 +403,6 @@ class ThingerClient : public thinger::thinger { void handle(){ if(handle_connection()){ synchronized(size_t available = client_.available();) - //THINGER_DEBUG_VALUE("THINGER", "Available bytes: ", available); #ifdef _DEBUG_ if(available>0){ THINGER_DEBUG_VALUE("THINGER", "Available bytes: ", available); From 0ee8096354d3642541e254c27082b234c3eaa30f Mon Sep 17 00:00:00 2001 From: Denis Tregubov Date: Wed, 30 Oct 2019 22:41:01 +0300 Subject: [PATCH 3/3] write_bucket confirm_write=true --- src/thinger/thinger.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/thinger/thinger.h b/src/thinger/thinger.h index 2879784..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); }