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.