From dea9cb49271631d4def70d21db42a85d1d58f269 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 23 Jul 2015 15:37:39 +0200 Subject: o Fixing a bug where the reponse code wasn't properly set. --- trygvisio_soil_moisture.ino | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'trygvisio_soil_moisture.ino') diff --git a/trygvisio_soil_moisture.ino b/trygvisio_soil_moisture.ino index 8185754..729f5da 100644 --- a/trygvisio_soil_moisture.ino +++ b/trygvisio_soil_moisture.ino @@ -225,8 +225,8 @@ static void aci_loop() { case ACI_EVT_DATA_RECEIVED: pipe_number = aci_evt->params.data_received.rx_data.pipe_number; - Serial.print(F("ACI_EVT_DATA_RECEIVED: pipe_number=")); - Serial.println(pipe_number, DEC); +// Serial.print(F("ACI_EVT_DATA_RECEIVED: pipe_number=")); +// Serial.println(pipe_number, DEC); if (pipe_number == pipe_rx) { on_soil_moisture_ctrl(aci_evt->params.data_received.rx_data.aci_data, aci_evt->len); @@ -352,12 +352,14 @@ void loop() { sm_loop(); -#ifdef SM_DEBUG +#ifdef USE_LOW_POWER_MODE == 1 +#ifdef SM_DEBUG == 1 Serial.println(F("Sleeping...")); Serial.flush(); #endif // SM_DEBUG go_to_sleep(); +#endif // USE_LOW_POWER_MODE } static void show_pipes() { @@ -425,14 +427,29 @@ void notify_soil_moisture(const struct sm_res& res, uint8_t body_len) { // This should probably be an explicit part of the API, but for now it makes it easier to implement a synchronous interface. lib_aci_set_local_data(&aci_state, pipe_set, (uint8_t *)&res, len); - if (available && aci_state.data_credit_available > 0) { - boolean sent = lib_aci_send_data(pipe_tx, data, len); - if (sent) { - aci_state.data_credit_available--; + // There is no need to lod messages that won't be sent. + if (!available) { + return; + } #if SM_DEBUG == 1 - write_res(res); +Serial.println("write_res"); + write_res(res); +#endif + + if (aci_state.data_credit_available = 0) { +#if SM_DEBUG == 1 + Serial.println("Not enough credits to send notification."); +#endif + return; + } + + boolean sent = lib_aci_send_data(pipe_tx, data, len); + if (sent) { + aci_state.data_credit_available--; + } else { +#if SM_DEBUG == 1 + Serial.println("Sending failed"); #endif - } } } -- cgit v1.2.3