aabmets / SIM800

A comprehensive SIM800 Series library for simplified and in-depth chip access.
GNU Affero General Public License v3.0
38 stars 27 forks source link

Delay caused by `smsSend()`? #3

Closed IainIsCreative closed 6 years ago

IainIsCreative commented 7 years ago

Hey there!

I have a query regarding the smsSend() function — I have an array of buttons and an accompanying LED to show that the buttons are working as expected.

With the LED, it works — if I press a button, the LED turns on, and switches of when I release said button.

However, if I place the smsSend() function in that same context, the LED stays on for a few seconds even if I've released the button. Does the smsSend() function cause any delays in the loop?

Many thanks in advance.

aabmets commented 7 years ago

It is very difficult for me to troubleshoot your issue from your description, because it is quite vague about the details of your implementation. At this point, all I can do is guess that you have not implemented button debounce correctly.

Generally, you should make sure that you are not continuously sending "turn LED on" messages to your remote device, when the button is being kept pressed. The correct way to implement button debouncing is as follows.

The timer is a class one must implement themselves, preferably using timestamps and micros(). This is used to regulate the frequency the button can be pressed and removes erratic button jittery.

define DEF_TIMEOUT 100 // microseconds, used in timer class

void loop() { static bool state = true;

if (digitalRead(button) == state && timer.timeOut()) {
    if (state == true) {
        /* send SMS to turn LED on */
    } else {
        /* send SMS to turn LED off */
    }
    timer.reset();
    state = !state;
}

}

If your problem persists after using this button debouncing code, the problem is either in the mobile network or your remote device code. Keep in mind that SMS messages are slow and their delivery is not guaranteed in millisecond range.

On 5 July 2017 at 18:57, Iain notifications@github.com wrote:

Hey there!

I have a query regarding the smsSend() function — I have an array of buttons and an accompanying LED to show that the buttons are working as expected.

With the LED, it works — if I press a button, the LED turns on, and switches of when I release said button.

However, if I place the smsSend() function in that same context, the LED stays on for a few seconds even if I've released the button. Does the smsSend() function cause any delays in the loop?

Many thanks in advance.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/aspenforest/SIM800/issues/3, or mute the thread https://github.com/notifications/unsubscribe-auth/AGoExJehaT00lfl5z9HOpb0Oavn7yZRzks5sK7JWgaJpZM4OOiVG .