The Things Node - Cayenne

Has anyone tried to get the Cayenne Integration working with the Things Node … I just posted this in the Cayenne forum …

1 Like

did you load the basic sketch in the TTN node

Yes, that’s what I’m running!

you should run the (edited) CayenneLPP sketch

1 Like

Thanks!! I am relatively new to all this - how do I do that please?

Pat

obvious first question : do you have an Cayenne account ?

if not create one here

I can confirm its fully integrated, with a few clicks you see your dashboard

ttn-nodeCayenne

see temp demo

oh and the graph is working fine to :slight_smile:

cayenne-tempgraphdemo

Yes, have been using Cayenne on other devices and also with the MicroChip LoRa Mote with no problems so at a basic level I get it. I just expected the Things Node to work without any fiddling :slight_smile: It’s the fiddling bit I am not clear on.

I can see my Things Node in Cayenne, but all I see is RSSI and SNR and Location. None of sensors.

Thanks so much for your help!

Pat

Ok, so I need to modify the sketch that runs on the Node to use LPP?

If’ you’ve done it, are you willing to share?

Pat

use the CayenneLPP sketch

and edit 3 things :

editedsketchCayeneLPP

log in to Cayenne and select The Things node (you need the device id to register )

Thanks! I completely follow, but the only CayenneLPP file I have is at Examples->TheThingsNetwork->CayenneLPP

And it contains only this (below) … i.e. knows nothing about the Node :frowning: I assume I need to weave the two files together (i.e. the CayenneLPP and Examples->TheThingsNode->Basic.

#include <TheThingsNetwork.h>
#include <CayenneLPP.h>

// Set your AppEUI and AppKey
const char *appEui = “0000000000000000”;
const char *appKey = “00000000000000000000000000000000”;

#define loraSerial Serial1
#define debugSerial Serial

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

TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
CayenneLPP lpp(51);

void setup()
{
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);
}

void loop()
{
debugSerial.println(“-- LOOP”);

lpp.reset();
lpp.addTemperature(1, 22.5);
lpp.addBarometricPressure(2, 1073.21);
lpp.addGPS(3, 52.37365, 4.88650, 2);

// Send it off
ttn.sendBytes(lpp.getBuffer(), lpp.getSize());

delay(10000);
}

ah ok

install the things node library … comes with the CayenneLPP example

ttn node lib

ttn node lib 2

You are very patient. Thank you :slight_smile: I thought I had done that … but will give it another go!!

Pat

Yeah - it is installed :frowning: This is what I see … no CayenneLPP in TheThingsNode library.

image

image

I can’t read your screenshot… must be my old eyes :wink:

TTN lib 3

maybe click and update the lib version ?

TTN lib 4

Very very odd. Sorry for the wild goose chase. I will go hunting. I did update the lib. Will fool around before asking any more :slight_smile: Thanks a million.

1 Like

TTN node CayenneLPP:

#include <TheThingsNode.h>
#include <CayenneLPP.h>

// Set your AppEUI and AppKey
const char *appEui = "0000000000000000";
const char *appKey = "00000000000000000000000000000000";

#define loraSerial Serial1
#define debugSerial Serial

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

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

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

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->onWake(wake);
  node->onInterval(interval);
  node->onSleep(sleep);
  node->onMotionStart(onMotionStart);
  node->onButtonRelease(onButtonRelease);

  // 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 onButtonRelease(unsigned long duration)
{
  node->setColor(TTN_BLUE);

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

  sendData(PORT_BUTTON);
}

void sendData(uint8_t port)
{
  printSensors();

  lpp.reset();
  lpp.addDigitalInput(1, node->isButtonPressed());
  lpp.addDigitalInput(2, node->isUSBConnected());
  lpp.addDigitalInput(3, node->isMoving());
  lpp.addAnalogInput(4, node->getBattery()/1000.0);
  lpp.addTemperature(5, node->getTemperatureAsFloat());
  lpp.addLuminosity(6, node->getLight());
  
  float x,y,z;
  node->getAcceleration(&x, &y, &z);
  lpp.addAccelerometer(7, x, y, z);
  
  ttn.sendBytes(lpp.getBuffer(), lpp.getSize());
}

void printSensors()
{
  debugSerial.println();
  debugSerial.println("SENSORS:");
  debugSerial.println("--------");
  
  debugSerial.print("LED Colour:\t");
  debugSerial.println(node->colorToString(node->getColor()));

  debugSerial.print("Temperature:\t");
  debugSerial.print(node->getTemperatureAsFloat());
  debugSerial.println("°C");

  debugSerial.print("Light Sensor:\t");
  debugSerial.print(node->getLight());
  debugSerial.println("lux");
  
  debugSerial.print("Moving now:\t");
  if(node->isMoving())
  {
    debugSerial.println("yes");
  }
  else
  {
    debugSerial.println("no");
  }
  
  debugSerial.print("Button pressed:\t");
  if(node->isButtonPressed())
  {
    debugSerial.println("yes");
  }
  else
  {
    debugSerial.println("no");
  }

  debugSerial.print("USB connected:\t");
  if(node->isUSBConnected())
  {
    debugSerial.println("yes");
  }
  else
  {
    debugSerial.println("no");
  }

  debugSerial.print("Battery:\t");
  debugSerial.print(node->getBattery());
  debugSerial.println("mV");

  float x,y,z;
  node->getAcceleration(&x, &y, &z);

  debugSerial.print("Acceleration:\tx=");
  debugSerial.print(x);
  debugSerial.print("g\n\t\ty=");
  debugSerial.print(y);
  debugSerial.print("g\n\t\tz=");
  debugSerial.print(z);
  debugSerial.println("g");

  debugSerial.println("--------");
  debugSerial.println();
  
}

Fab :slight_smile:

I just found it in the Github repo too … definitely not in my examples!

Compiling now!

Pat

Woop !!

image

Some definite odd stuff with my libraries … now apparently fixed and worked instantly.

Cannot thank you enough for all your help!

Now for a few hours on my day job :slight_smile:

Pat

This is better :slight_smile:

{
“accelerometer_7”: {
“x”: -0.063,
“y”: -0.008,
“z”: -0.969
},
“analog_in_4”: 4.74,
“digital_in_1”: 0,
“digital_in_2”: 1,
“digital_in_3”: 0,
“luminosity_6”: 28,
“temperature_5”: 25.7
}