mini-beieli-node/mini_beieli_node.h

115 lines
5.8 KiB
C++

// mini_beieli_node.h
/****************************************************************************\
|
| MANIFEST CONSTANTS & TYPEDEFS
|
\****************************************************************************/
constexpr uint8_t kUplinkPort = 2;
/* how long do we wait between transmissions? (in seconds) */
enum {
// set this to interval between transmissions, in seconds
// Actual time will be a little longer because have to
// add measurement and broadcast time, but we attempt
// to compensate for the gross effects below.
CATCFG_T_CYCLE = 6 * 60, // every 6 minutes
//CATCFG_T_CYCLE = 30, // for Testing
CATCFG_T_CYCLE_TEST = 30, // every 10 seconds
CATCFG_T_CYCLE_INITIAL = 30, // every 30 seconds initially
CATCFG_INTERVAL_COUNT_INITIAL = 30, // repeat for 15 minutes
CATCFG_T_REBOOT = 30 * 24 * 60 * 60, // reboot every 30 days
};
/* additional timing parameters; ususually you don't change these. */
enum {
CATCFG_T_WARMUP = 1,
CATCFG_T_SETTLE = 5,
CATCFG_T_OVERHEAD = (CATCFG_T_WARMUP + CATCFG_T_SETTLE),
CATCFG_T_MIN = CATCFG_T_OVERHEAD,
CATCFG_T_MAX = CATCFG_T_CYCLE < 60 * 60 ? 60 * 60 : CATCFG_T_CYCLE, // normally one hour max.
CATCFG_INTERVAL_COUNT = 30,
};
constexpr uint32_t CATCFG_GetInterval(uint32_t tCycle)
{
return (tCycle < CATCFG_T_OVERHEAD)
? CATCFG_T_OVERHEAD
: tCycle - CATCFG_T_OVERHEAD;
}
enum {
CATCFG_T_INTERVAL = CATCFG_GetInterval(CATCFG_T_CYCLE),
};
enum {
PIN_ONE_WIRE = A2, // XSDA1 == A2
PIN_SHT10_CLK = 8, // XSCL0 == D8
PIN_SHT10_DATA = 12, // XSDA0 == D12
};
/****************************************************************************\
|
| READ-ONLY DATA
|
\****************************************************************************/
static const int32_t fwVersion = 202002129;
static const byte INIT_PACKAGE_INTERVAL = 100; // send an init package every 100 packages;
static const byte MAX_VALUES_TO_SEND = 8;
//static const byte MAX_VALUES_TO_SEND = 1; // Testing
static const uint8_t LORA_DATA_VERSION = 1;
static const uint8_t LORA_DATA_VERSION_FIRST_PACKAGE = 128;
static const uint32_t PRESSURE_OFFSET = 825;
static const uint16_t SEND_DIFF_THRESHOLD_5GRAMS = 10; // when weight value drops by 50g, then send data
static const long NOT_ATTACHED = -2147483648;
// must be 64 bytes long (size of kAppConf)
typedef struct {
long cal_w1_0; // 4 Bytes, Wert Waegezelle 1 ohne Gewicht, LONG_MIN when not connected
long cal_w2_0; // 4 Bytes, Wert Waegezelle 2 ohne Gewicht, LONG_MIN when not connected
float cal_w1_factor; // 4 Bytes, Kalibrationsfaktor Waegezelle 1
float cal_w2_factor; // 4 Bytes, Kalibrationsfaktor Waegezelle 2
byte debug_level; // 0 => no debugging, no led, 1 => infos, no led, 2 => infos, 3 => error, 4 => highest level
byte fill[47];
} __attribute__((packed)) CONFIG_data;
typedef struct {
uint8_t version; // Version of Packet Format (must be increased every time format changes...)
uint8_t vbat; // Batteriespannung (0: <= 2510mV, 70: 3000mV, 170: 3700mV, 255: >= 4295mV [1 Einheit => 7mV])
uint8_t humidity[MAX_VALUES_TO_SEND]; // Luftfeuchtigkeit in Prozent
int16_t temperature; // Temperatur (Startwert) in 1/10 Grad Celsius
int8_t temperature_change[MAX_VALUES_TO_SEND - 1]; // Unterschied Temperatur seit letztem Messwert in 1/10 Grad Celsius
uint8_t pressure[MAX_VALUES_TO_SEND]; // Luftdruck in Hekto-Pascal (0 entspricht 825 hPa)
uint16_t weight[MAX_VALUES_TO_SEND]; // Waegezelle Gesamtgewicht, in 5g
uint8_t offset_last_reading; // Zeitunterschied letzte zu erste Messung (in Minuten)
} __attribute__((packed)) LORA_data;
typedef struct {
uint8_t version; // Version of Packet Format (must be increased every time format changes...)
int32_t fw_version; // Version of Firmware, Nummer entspricht YYYYMMDD
uint8_t vbat; // Batteriespannung (0: <= 2510mV, 70: 3000mV, 170: 3700mV, 255: >= 4295mV [1 Einheit => 7mV])
uint8_t humidity; // Luftfeuchtigkeit in Prozent
int16_t temperature; // Temperatur in 1/10 Grad Celsius
uint8_t pressure; // Luftdruck in Hekto-Pascal (0 entspricht 825 hPa)
int32_t weight1; // Waegezelle 1, Raw Value
int32_t weight2; // Waegezelle 2, Raw Value
long cal_w1_0; // 4 Bytes, Wert Waegezelle 1 ohne Gewicht
long cal_w2_0; // 4 Bytes, Wert Waegezelle 2 ohne Gewicht
float cal_w1_factor; // 4 Bytes, Kalibrationsfaktor Waegezelle 1
float cal_w2_factor; // 4 Bytes, Kalibrationsfaktor Waegezelle 2
} __attribute__((packed)) LORA_data_first;
typedef struct {
uint8_t vbat; // Batteriespannung (0: <= 2510mV, 70: 3000mV, 170: 3700mV, 255: >= 4295mV [1 Einheit => 7mV])
uint8_t humidity; // Luftfeuchtigkeit in Prozent
int16_t temperature; // Temperatur in 1/10 Grad Celsius
uint8_t pressure; // Luftdruck in Hekto-Pascal (0 entspricht 825 hPa)
int32_t weight1; // Waegezelle 1, Raw Value
int32_t weight2; // Waegezelle 2, Raw Value
uint16_t weight; // Waegezelle Gesamtgewicht, in 5g
} SENSOR_data;