From b5018563c145509f44ab30eea83e6cbfd91bbf20 Mon Sep 17 00:00:00 2001 From: Arthur Ma Date: Sat, 29 Apr 2017 22:56:59 +0800 Subject: [PATCH] Remove static Audio instance (#155) * Issue #153 Currently there have 2 user threads, one for Arduino 1 for telemetry data collection. Both of them would send data to remote services via the WiFi module. If there 2 threads are trying to send data at the same time then it will block the whole system, after add lock for any network operation problem solved. So root cause should be: the underline wifi driver is not thread safety, as we don't have the source code of the wifi driver I will check with MXChip for further investigation. * folder struct change * Remove the telemetry thread to save resource * minor changes * Remove static Audio instance as this is not a mandatory component for all apps * fix typo --- .../cores/arduino/drivers/I2S_Audio/AudioClass.cpp | 2 -- .../cores/arduino/drivers/I2S_Audio/AudioClass.h | 2 -- AZ3166/AZ3166-1.0.0/cores/arduino/system/main.cpp | 8 ++++---- .../AzureIotHubExample/AzureIotHubExample.ino | 12 ++++++++++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/AZ3166/AZ3166-1.0.0/cores/arduino/drivers/I2S_Audio/AudioClass.cpp b/AZ3166/AZ3166-1.0.0/cores/arduino/drivers/I2S_Audio/AudioClass.cpp index 5fd4e0874..3041fd37a 100644 --- a/AZ3166/AZ3166-1.0.0/cores/arduino/drivers/I2S_Audio/AudioClass.cpp +++ b/AZ3166/AZ3166-1.0.0/cores/arduino/drivers/I2S_Audio/AudioClass.cpp @@ -251,8 +251,6 @@ int AudioClass::getCurrentSize() return m_record_cursor - m_wavFile; } -AudioClass Audio; - /*------------------------------------------------------------------------------ Callbacks implementation: the callbacks API are defined __weak in the stm32412g_discovery_audio.c file diff --git a/AZ3166/AZ3166-1.0.0/cores/arduino/drivers/I2S_Audio/AudioClass.h b/AZ3166/AZ3166-1.0.0/cores/arduino/drivers/I2S_Audio/AudioClass.h index 586f4b7ce..1611b8df2 100644 --- a/AZ3166/AZ3166-1.0.0/cores/arduino/drivers/I2S_Audio/AudioClass.h +++ b/AZ3166/AZ3166-1.0.0/cores/arduino/drivers/I2S_Audio/AudioClass.h @@ -67,6 +67,4 @@ class AudioClass { void genericWAVHeader(WaveHeader* header, int pcmDataSize, uint32_t sampleRate, int sampleBitDepth, uint8_t channels); }; -extern AudioClass Audio; - #endif diff --git a/AZ3166/AZ3166-1.0.0/cores/arduino/system/main.cpp b/AZ3166/AZ3166-1.0.0/cores/arduino/system/main.cpp index 2dc318d26..73710d98c 100644 --- a/AZ3166/AZ3166-1.0.0/cores/arduino/system/main.cpp +++ b/AZ3166/AZ3166-1.0.0/cores/arduino/system/main.cpp @@ -18,7 +18,7 @@ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - + #include "Arduino.h" #include "mico_system.h" #include "console_cli.h" @@ -66,7 +66,7 @@ static bool IsAPMode() return false; } -static int GetMacWichoutColon(char* buff) +static int GetMACWithoutColon(char* buff) { const char* mac = WiFiInterface()->get_mac_address(); int j = 0; @@ -93,7 +93,7 @@ static void EnterConfigurationiMode() } char id[24] = "id:"; - id[3 + GetMacWichoutColon(id + 3)] = 0; + id[3 + GetMACWithoutColon(id + 3)] = 0; Screen.print(1, id); // Enter configuration mode @@ -113,7 +113,7 @@ static void EnterAPMode() } char ap_name[24] = "AZ-"; - ap_name[3 + GetMacWichoutColon(ap_name + 3)] = 0; + ap_name[3 + GetMACWithoutColon(ap_name + 3)] = 0; if (!InitSystemWiFiAP()) { diff --git a/AZ3166/AZ3166-1.0.0/libraries/AzureIotHub/examples/AzureIotHubExample/AzureIotHubExample.ino b/AZ3166/AZ3166-1.0.0/libraries/AzureIotHub/examples/AzureIotHubExample/AzureIotHubExample.ino index 28449898f..8cfc4cfa1 100644 --- a/AZ3166/AZ3166-1.0.0/libraries/AzureIotHub/examples/AzureIotHubExample/AzureIotHubExample.ino +++ b/AZ3166/AZ3166-1.0.0/libraries/AzureIotHub/examples/AzureIotHubExample/AzureIotHubExample.ino @@ -7,7 +7,7 @@ #define RGB_LED_BRIGHTNESS 16 #define LOOP_DELAY 50 -#define HEARTBEAT_INTERVAL (30000 / LOOP_DELAY) +#define HEARTBEAT_INTERVAL (60000 / LOOP_DELAY) // 0 - idle // 1 - shaking @@ -128,9 +128,17 @@ static void DoHeartBeat(void) Serial.println(">>Heartbeat<<"); eventSent = false; iothub_client_sample_send_event((const unsigned char *)"{\"topic\":\"iot\", \"DeviceID\":\"Heartbeat\", \"event\":\"heartbeat\"}"); - while (!eventSent) + for (int i =0; i < 20; i++) { iothub_client_sample_mqtt_loop(); + if (eventSent) + { + break; + } + } + if (!eventSent) + { + Serial.println("Failed to get response from IoT hub: timeout."); } heartbeat = 0; digitalWrite(LED_BUILTIN, HIGH);