Lights on/Off TTN Node Code

Hi guys,

I am having issues with some code. I was hoping someone would be able to help. I am not great at code.

I would like to active a strip of LED’s using a downlink payload of 1 byte.

This is the code I have, which is activating on the things console but when I send the 01 payload the lights do not turn on.

#include <TheThingsNetwork.h>
#include <Adafruit_NeoPixel.h>

// Set your AppEUI and AppKey
const char *appEui = "70B3D57ED0011FDC";
const char *appKey = "D224375430C2C65A7D3B4D2E0A71A157";

#define loraSerial Serial1
#define debugSerial Serial

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

#define RINGPIN 6

uint8_t NUMPIXELS = 14;      // total number of LED's in the ring display
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, RINGPIN, NEO_RGB + NEO_KHZ800); 
TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);

void setup()
{ 
  strip.begin();
  for (int i = 0; i < NUMPIXELS; i++) {
    strip.setPixelColor(i, strip.Color(0, 0, 0));
  }
  strip.show();
  loraSerial.begin(57600);
  debugSerial.begin(9600);

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

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

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

  ttn.onMessage(message);
}

void loop()
{
  debugSerial.println("-- LOOP");

  ttn.poll();

  delay(10000);
}

void message(const uint8_t *payload, size_t size, port_t port) {
  if (payload[0] == 1) {
    for (int i = 0; i < NUMPIXELS; i++) {
      strip.setPixelColor(i, strip.Color(64, 0, 0));
    }
    strip.show();
  }
  
    if (payload[0] == 2) {
    for (int i = 0; i < NUMPIXELS; i++) {
      strip.setPixelColor(i, strip.Color(0, 0, 0));
    }
    strip.show();
  }
}

Wondering if anyone has any thoughts here.

The wiring and everything works perfectly without the TTN activation code added so I know that is all good, it is just the On/Off from the payload I am trying to get working.

After this line, add a line like debugSerial.println("-- DOWNLINK"); to ensure you’re getting data.

(And note that, while a nice test, this is not a good use case for LoRaWAN. The poll methods sends an uplink to TTN, and sending every 10 seconds will soon get to the maximum of 30 seconds daily air time on TTN. Also, please see How do I format my forum post? [HowTo] Success!)

Hi Arjanvanb,

Thank you for this information. Very helpful. I apologise about my formatting. I am new to this forum.

I am in the process of developing a light which can be turned on remotely using LoRa signal via the TTN.

In regards to the poll method. What would be an acceptable type of method to use?

If you had any other thoughts on how I could make this more effective and connect I would be very appreciative.

Cheers.

There isn’t, for LoRaWAN: https://www.thethingsnetwork.org/docs/lorawan/limitations.html