The Things Node not responding to button press/release

Hello
i just bought 3 things node
i managed to connect them on an application, i see traffic data for event “motion” or “interval”

However, nothing happens when i press on the button… for the 3 of them…

can you help me please ?

this is my sketch based upon the “example” sketch

#include <TheThingsNode.h>


const char *appEui = "****";
const char *appKey = "****";



#define loraSerial Serial1
#define debugSerial Serial

// Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915
#define freqPlan TTN_FP_EU868

TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
TheThingsNode *node;

#define PORT_SETUP 1
#define PORT_INTERVAL 2
#define PORT_MOTION 3
#define PORT_BUTTON 4

/*
Decoder payload function
------------------------

function Decoder(bytes, port) {
  var decoded = {};
  var events = {
    1: 'setup',
    2: 'interval',
    3: 'motion',
    4: 'button'
  };
  decoded.event = events[port];
  decoded.battery = (bytes[0] << 8) + bytes[1];
  decoded.light = (bytes[2] << 8) + bytes[3];
  if (bytes[4] & 0x80)
    decoded.temperature = ((0xffff << 16) + (bytes[4] << 8) + bytes[5]) / 100;
  else
    decoded.temperature = ((bytes[4] << 8) + bytes[5]) / 100;
  return decoded;
}
*/

void setup()
{
  loraSerial.begin(57600);
  debugSerial.begin(9600);

  // Wait a maximum of 10s for Serial Monitor
  while (!debugSerial && millis() < 10000)
    ;

  // Config Node
  node = TheThingsNode::setup();
  node->configLight(true);
  node->configInterval(true, 60000);
  node->configTemperature(true);
  node->configButton(true);
  node->onWake(wake);
  node->onInterval(interval);
  node->onSleep(sleep);
  node->onMotionStart(onMotionStart);
  node->onButtonRelease(onButtonRelease);
  node->onButtonPress(onButtonPress);
  
  // Test sensors and set LED to GREEN if it works
  node->showStatus();
  node->setColor(TTN_GREEN);

  debugSerial.println("-- TTN: STATUS");
  ttn.showStatus();

  debugSerial.println("-- TTN: JOIN");
  ttn.join(appEui, appKey);

  debugSerial.println("-- SEND: SETUP");
  sendData(PORT_SETUP);
}

void loop()
{
  node->loop();
}

void interval()
{
  node->setColor(TTN_BLUE);

  debugSerial.println("-- SEND: INTERVAL");
  sendData(PORT_INTERVAL);
}

void wake()
{
  node->setColor(TTN_GREEN);
}

void sleep()
{
  node->setColor(TTN_BLACK);
}

void onMotionStart()
{
  node->setColor(TTN_BLUE);

  debugSerial.print("-- SEND: MOTION");
  sendData(PORT_MOTION);
}

void onButtonPress()
{
  

  debugSerial.println("-- PRESS BUTTON");
 


}

void onButtonRelease(unsigned long duration)
{
  node->setColor(TTN_BLUE);

  debugSerial.print("-- SEND: BUTTON");
  debugSerial.println(duration);

  sendData(PORT_BUTTON);
}

void sendData(uint8_t port)
{
  // Wake RN2483
  ttn.wake();

  ttn.showStatus();
  node->showStatus();

  byte *bytes;
  byte payload[12];

  uint16_t battery = node->getBattery();
  bytes = (byte *)&battery;
  payload[0] = bytes[1];
  payload[1] = bytes[0];

  uint16_t light = node->getLight();
  bytes = (byte *)&light;
  payload[2] = bytes[1];
  payload[3] = bytes[0];

  int16_t temperature = round(node->getTemperatureAsFloat() * 100);
  bytes = (byte *)&temperature;
  payload[4] = bytes[1];
  payload[5] = bytes[0];


  float x,y,z;
  node->getAcceleration(&x, &y, &z);
  int16_t r_x = round(x * 100);
  int16_t r_y = round(y * 100);
  int16_t r_z = round(z * 100);

  bytes = (byte *)&r_x;
  payload[6] = bytes[1];
  payload[7] = bytes[0];


  bytes = (byte *)&r_y;
  payload[8] = bytes[1];
  payload[9] = bytes[0];


  bytes = (byte *)&r_z;
  payload[10] = bytes[1];
  payload[11] = bytes[0];


  ttn.sendBytes(payload, sizeof(payload), port);

  // Set RN2483 to sleep mode
  ttn.sleep(60000);

  // This one is not optionnal, remove it
  // and say bye bye to RN2983 sleep mode
  delay(50);
}

Are you sure you’re not triggering motion just before you’re pressing the button?

(Aside, please see How do I format my forum post? [HowTo])

1 Like

Thank you

but, even after a while, without moving any sensor, nothing happens when press a button and release it, on 3 of them…

To be very precise: with your code nothing will happen on button press, but only on its release.

I assume you only changed the appEUI and appKey? (It looks good, but I’ve not compared line-by-line.)

You could comment/remove the following just to be sure:

The sketch I use looks the same, but it does not have any node->onButtonPress(onButtonPress) defined.

1 Like

ok, i will give it a try , thank you

Even more: it also does not have node->configButton(true) (but surely acts on the button release). (Also, it does not send any acceleration details.)

Hi Arjan

a) even with the original example sketch, nothing happens with the button

b) when i shake the NODE, keeping the button pressed, the status shows
16:04:06.727 -> Button pressed: No

as it occurs on 3 different NODES, i think this is a problem with software (i don’t know which one)

example with “interval” event

16:04:58.634 -> -- SEND: INTERVAL
16:04:58.851 -> EUI: 0004A30B00EB2EA9
16:04:58.851 -> Battery: 3283
16:04:58.851 -> AppEUI: xxx (hidden)
16:04:58.884 -> DevEUI: xxx (hidden)
16:04:58.884 -> Data Rate: 5
16:04:58.884 -> RX Delay 1: 1000
16:04:58.884 -> RX Delay 2: 2000
16:04:58.884 -> Light: 24
16:04:58.884 -> Temperature: 23.25 C
16:04:58.884 -> Temperature alert: No
16:04:58.884 -> Moving: No
16:04:58.884 -> Button pressed: No
16:04:58.884 -> Color: Blue
16:04:58.884 -> USB connected: Yes
16:04:58.884 -> Battery voltage: 4742 MV
16:04:58.884 -> Sending: mac tx uncnf 2 128600180915
16:05:01.018 -> Successful transmission
16:05:01.018 -> Sending: sys sleep 60000

example with “motion” event

16:07:15.624 -> -- SEND: MOTIONEUI: 0004A30B00EB2EA9
16:07:15.858 -> Battery: 3283
16:07:15.858 -> AppEUI: ***
16:07:15.858 -> DevEUI: ***
16:07:15.892 -> Data Rate: 5
16:07:15.892 -> RX Delay 1: 1000
16:07:15.892 -> RX Delay 2: 2000
16:07:15.892 -> Light: 17
16:07:15.892 -> Temperature: 23.19 C
16:07:15.892 -> Temperature alert: No
16:07:15.892 -> Moving: Yes
16:07:15.892 -> Button pressed: No
16:07:15.892 -> Color: Blue
16:07:15.892 -> USB connected: Yes
16:07:15.892 -> Battery voltage: 4736 MV
16:07:15.892 -> Sending: mac tx uncnf 3 12860012090F
16:07:18.050 -> Successful transmission
16:07:18.050 -> Sending: sys sleep 60000
16:07:20.798 -> -- SEND: MOTIONEUI: 0004A30B00EB2EA9
16:07:21.012 -> Battery: 3294
16:07:21.012 -> AppEUI: ***hidden***
16:07:21.047 -> DevEUI: ***hidden***
16:07:21.047 -> Data Rate: 5
16:07:21.047 -> RX Delay 1: 1000
16:07:21.047 -> RX Delay 2: 2000
16:07:21.047 -> Light: 17
16:07:21.047 -> Temperature: 23.19 C
16:07:21.047 -> Temperature alert: No
16:07:21.047 -> Moving: Yes
16:07:21.047 -> Button pressed: No
16:07:21.047 -> Color: Blue
16:07:21.047 -> USB connected: Yes
16:07:21.047 -> Battery voltage: 4742 MV
16:07:21.047 -> Sending: mac tx uncnf 3 12800011090F
16:07:23.221 -> Successful transmission
16:07:23.221 -> Sending: sys sleep 60000

Well, keeping the button pressed won’t generate button events, I assume. The device will/should act on changes, and will remember its state to return when requested at a later time. But of course, it should have handled and remembered the button press (unless you already had it pressed while booting the device).

It seems GitHub - TheThingsNetwork/arduino-node-lib: Arduino Library for The Things Node has not changed since February. Can you tell which version you’re using? (I was using 2.0.8 it seems.)

1 Like

I tried with both
“TheThingsNetwork” library : 2.6.0
“TheThingsNode” library : 2.0.9

i also tried with
“TheThingsNetwork” library : 2.5.16
“TheThingsNode” library : 2.0.8

(Sorry, just bricked my device by selecting the wrong Arduino board. Oh well. I know how to fix that, but that’s not going to happen right now. Success!)

1 Like

i had the same problem :slight_smile:
Arjan, don’t waste your time, you helped me a lot, it’s sunday :wink:

1 Like

I have the exact same problem as ysimonx.
I bought my “the things node” last week but due to a flyer packed with the node I understand that this node is probably a little older.
Has something changed with the library or the basic example program last year?

1 Like

A bit of an old thread - but I am having the same problem as @ysimonx (and @stonecroft , of course).
Did you guys find any solution? Or is it just faulty hardware? Or simply my misunderstanding?

Thx, cheers
Floating

Hi @FloatingOne

I did not find one solution. Not sure if it is hardware ou firmware … but i never heard about someone who managed to use it…

regards