The Things Node button release does not provide time pressed

I have noticed that the function in onButtonRelease() in the The Things Node library is not delivering the time the button is pressed. Has anyone noticed this too? If so did you finde a solution?

Peeking at the library code, if the callback is invoked it seems there’s no way it does not pass that time, unless millis() is always zero (in which case it would pass zero):

Do you get passed the value 0, and if so: what does printing millis() give you?

And do you use code like this?

yes

Yes the value is 0 and no, I have not added millis() somewhere. I will try later.

I also observe that the onButtonRelease() is called immediately after pressing the button. When I release the button after many seconds no info is presented. This could be the argument why the value stays 0.

It suggests that something goes wrong with interrupts?

I am also having the same issue with TheThingsNode.
On all four nodes onButtonRelease returns 0 for duration.

Although I have noticed that under some “yet unknown conditions” it used to work.
I was able to trigger a different function with a long press, but now after uploading the code again, it stopped working again and it always immediately triggers onButtonRelease with duration 0.

void onButtonRelease(unsigned long duration)
{
  debugSerial.print("-- SEND: BUTTON");
  debugSerial.println(duration);
  if (duration==0) {
    node->setColor(TTN_RED); // oh no, it's broken again.. no duration provided
    sendData(PORT_INTERVAL);
  } else if (duration>600) {
    node->setColor(TTN_GREEN); // long press, send BUTTON 
    sendData(PORT_BUTTON);
  } else {
    node->setColor(TTN_YELLOW); // short press, send INTERVAL
    sendData(PORT_INTERVAL);
  }
}

any ideas?

So I have added two println statements in TheThingsNode.cpp to show RISING and FALLING button status:

void TTN_BUTTON_FN()
{
  uint8_t trigger = getPinChangeInterruptTrigger(digitalPinToPCINT(TTN_BUTTON));
  if (trigger == FALLING)
  {
    TTN_BUTTON_PRESS = true;
	Serial.println("##### FALLING ###");
  }
  else if (trigger == RISING)
  {
    TTN_BUTTON_RELEASE = true;
	Serial.println("##### RISING ###");
  }
}

and suddenly onButtonRelease reports duration again…

##### FALLING ###
-- onButtonPress 10883
##### RISING ###
-- onButtonRelease duration 200
##### FALLING ###
-- onButtonPress 14385
##### RISING ###
-- onButtonRelease duration 901
##### FALLING ###
-- onButtonPress 20588
##### RISING ###
-- onButtonRelease duration 301

adding delay(10) in TheThingsNode.cpp will fix the onButtonRelease duration issue :slight_smile: :sunglasses:

void TTN_BUTTON_FN()
{
  uint8_t trigger = getPinChangeInterruptTrigger(digitalPinToPCINT(TTN_BUTTON));
  if (trigger == FALLING)
  {
    TTN_BUTTON_PRESS = true;
    delay(10); // FIX FOR DURATION = 0
  }
  else if (trigger == RISING)
  {
    TTN_BUTTON_RELEASE = true;
    delay(10); // FIX FOR DURATION = 0
  }
}

oh snap… the fix only works while beeing connected to USB.
as soon as you switch to battery power, duration is again not reported correctly.

words cannot describe how much I hate “TheThingsNode”.

since the battery won’t last more than a week, it’s probably not worth investigating further in this piece of carp.

Sounds like this could be an compiler optimization problem?

Or the button is bad and generating many events, which need to be debounced? (Chatter; contact bounce?)

My ttn node does not have that problem but it is running the cayenne LPP example sketch and devicefrom the ttn node and ttn device library from ch2i/arduino-device-lib and ch2i/arduino-node-lib from Charles for minimizing the power usage of the ttn node of the cayenneLPP sketch

grafik

or see another button press

grafik


If you install the new software the ttn node will run for 1 or 2 month depending on the size of the payload sent and the send interval e.g once per hour...
1 Like