Hi all,
I’m trying to get official the things node working for a descent time, my first tests have not been really successful.
Looking at this post seems I’m not the only one.
Here is the pdf of schematics of the Things Node
An idea would be to have a real sketch example for Low Power on this node. So may be we can post on this thread all trick and suggestion.
The first test I’ve done was to remove sending Lora frame on motion to preserve battery, but even with that (and node not moving) it survived only 2 weeks.
So I decided to tweak again the code to monitor battery, sending frame every 5 minutes or with button press. And of course disabling all sensors. We’ll see if it’s better, here is new code
#include <TheThingsNode.h>
#include <CayenneLPP.h>
// Set your AppEUI and AppKey
const char *appEui = "XXXXXXXXXXXXXXXX";
const char *appKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
#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;
CayenneLPP lpp(32);
#define PORT_SETUP 1
#define PORT_INTERVAL 2
#define PORT_MOTION 3
#define PORT_BUTTON 4
void interval()
{
node->setColor(TTN_BLUE);
debugSerial.println(F("-- SEND: INTERVAL"));
sendData(PORT_INTERVAL);
}
void wake()
{
node->setColor(TTN_GREEN);
}
void sleep()
{
node->setColor(TTN_BLACK);
// Just in case, disable all sensors
// this couldn't hurt except time to do job
node->configMotion(false);
node->configLight(false);
node->configTemperature(false);
}
void onButtonRelease(unsigned long duration)
{
uint16_t adc_value;
node->setColor(TTN_BLUE);
debugSerial.print(F("-- SEND: BUTTON"));
debugSerial.println(duration);
sendData(PORT_BUTTON);
}
void sendData(uint8_t port)
{
// Read battery voltage
uint16_t vbat = node->getBattery();
debugSerial.print(F("Battery:\t"));
debugSerial.print(vbat);
debugSerial.println(F("mV"));
// Just send battery voltage
lpp.reset();
lpp.addAnalogInput(4, vbat/1000.0);
ttn.sendBytes(lpp.getBuffer(), lpp.getSize(), port);
}
void setup()
{
loraSerial.begin(57600);
debugSerial.begin(9600);
// Wait a maximum of 10s for Serial Monitor
while (!debugSerial && millis() < 10000)
;
// Config Node, Disable all sensors
// Check node schematics here
// https://github.com/TheThingsProducts/node
node = TheThingsNode::setup();
// Each 5 minutes
node->configInterval(true, 300000);
node->onWake(wake);
node->onInterval(interval);
node->onSleep(sleep);
// We monitor just button release
node->onButtonRelease(onButtonRelease);
// Test sensors and set LED to GREEN if it works
node->showStatus();
node->setColor(TTN_GREEN);
debugSerial.println(F("-- TTN: STATUS"));
ttn.showStatus();
debugSerial.println(F("-- TTN: JOIN"));
ttn.join(appEui, appKey);
debugSerial.println(F("-- SEND: SETUP"));
sendData(PORT_SETUP);
}
void loop()
{
node->loop();
}
Sad news, I measured current consumption, 3.2mA in sleep mode with 3 x 1.5V AA battery, what’s going on? Is there any sample sketch with real low power mode? I should have missed something.
Any tips or ideas are welcome (@BoRRoZ, @bluejedi, @ursm, @lex_ph2lb ) , I used to know perfectly how to low power a 328P but looks like for 32U4 things are different so I can’t use my ULPNode Ultra Low Power library without tweaking.