mannl-counter first commit
This commit is contained in:
parent
453851d1df
commit
d39bd6b8b0
|
@ -10,64 +10,7 @@ Project was created using PlatformIO Atmel-AVR Framework
|
||||||
|
|
||||||
## Decoder for the TTN Application
|
## Decoder for the TTN Application
|
||||||
|
|
||||||
```
|
take a look in ttn folder
|
||||||
function Decoder(bytes, port) {
|
|
||||||
var decoded = {};
|
|
||||||
|
|
||||||
if (bytes.length == 16) {
|
|
||||||
// Old Payload Format
|
|
||||||
decoded.t = ((bytes[0]) | (bytes[1] << 8 ) | (bytes[2] << 16 ) | (bytes[3] << 24)) / 100.0;
|
|
||||||
decoded.p = ((bytes[4]) | (bytes[5] << 8 ) | (bytes[6] << 16 ) | (bytes[7] << 24)) / 100.0;
|
|
||||||
decoded.h = ((bytes[8]) | (bytes[9] << 8 ) | (bytes[10] << 16 ) | (bytes[11] << 24)) / 100.0;
|
|
||||||
decoded.v = ((bytes[12]) | (bytes[13] << 8 ) | (bytes[14] << 16 ) | (bytes[15] << 24)) / 1000.0;
|
|
||||||
} else {
|
|
||||||
// New Payload Format
|
|
||||||
// We always have Battery Voltage (uint8_t)
|
|
||||||
decoded.v = (bytes[0] * 20) / 1000.0;
|
|
||||||
|
|
||||||
// Alarm Triggered (uint8_t)
|
|
||||||
if (bytes.length == 2)
|
|
||||||
decoded.a = bytes[1];
|
|
||||||
|
|
||||||
// Temperature 2 * DS18B20
|
|
||||||
if (bytes.length == 6){
|
|
||||||
decoded.t1 = ((bytes[2]) | (bytes[3] << 8 )) / 100.0;
|
|
||||||
decoded.t2 = ((bytes[4]) | (bytes[5] << 8 )) / 100.0;
|
|
||||||
return decoded;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Temperature (int32_t)
|
|
||||||
if (bytes.length >= 5)
|
|
||||||
decoded.t = ((bytes[1]) | (bytes[2] << 8 ) | (bytes[3] << 16 ) | (bytes[4] << 24)) / 100.0;
|
|
||||||
|
|
||||||
// Humidity (int32_t)
|
|
||||||
if (bytes.length >= 9)
|
|
||||||
decoded.h = ((bytes[5]) | (bytes[6] << 8 ) | (bytes[7] << 16 ) | (bytes[8] << 24)) / 100.0;
|
|
||||||
|
|
||||||
// Alarm Triggered (uint8_t)
|
|
||||||
if (bytes.length == 10)
|
|
||||||
decoded.a = bytes[9];
|
|
||||||
|
|
||||||
// SHT21 + Brightness (int16_t)
|
|
||||||
if (bytes.length == 11)
|
|
||||||
decoded.b = ((bytes[9]) | (bytes[10] << 8 ));
|
|
||||||
|
|
||||||
// Atmospheric Pressure (int32_t)
|
|
||||||
if (bytes.length >= 13)
|
|
||||||
decoded.p = ((bytes[9]) | (bytes[10] << 8 ) | (bytes[11] << 16 ) | (bytes[12] << 24)) / 100.0;
|
|
||||||
|
|
||||||
// Alarm Triggered (uint8_t)
|
|
||||||
if (bytes.length == 14)
|
|
||||||
decoded.a = bytes[13];
|
|
||||||
|
|
||||||
// BME280 + Brightness (int16_t)
|
|
||||||
if (bytes.length == 15)
|
|
||||||
decoded.b = ((bytes[13]) | (bytes[14] << 8 ));
|
|
||||||
}
|
|
||||||
|
|
||||||
return decoded;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
The firmware-code in this repository is licensed under the 3-clause BSD License (see LICENSE-File)
|
The firmware-code in this repository is licensed under the 3-clause BSD License (see LICENSE-File)
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
SHT21 sensor;
|
SHT21 sensor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM
|
#if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM || defined HAS_MANNLCOUNTER
|
||||||
volatile boolean alarm = false;
|
volatile boolean alarm = false;
|
||||||
|
|
||||||
// Get the Interrupt Mask for the selected Alarm PIN
|
// Get the Interrupt Mask for the selected Alarm PIN
|
||||||
|
@ -92,6 +92,12 @@
|
||||||
DallasTemperature sensors(&oneWire);
|
DallasTemperature sensors(&oneWire);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAS_MANNLCOUNTER
|
||||||
|
volatile uint8_t count_min = 0;
|
||||||
|
volatile uint32_t count_all = 0;
|
||||||
|
volatile unsigned long alteZeit=0, entprellZeit=20; //ms
|
||||||
|
#endif
|
||||||
|
|
||||||
// Global Variable to Track Deep Sleep
|
// Global Variable to Track Deep Sleep
|
||||||
uint16_t sleep_interval;
|
uint16_t sleep_interval;
|
||||||
|
|
||||||
|
@ -174,15 +180,25 @@ ISR(WATCHDOG_vect) {
|
||||||
WDTCSR = (1<<WDIE)|(1<<WDP3)|(1<<WDP0);
|
WDTCSR = (1<<WDIE)|(1<<WDP3)|(1<<WDP0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM
|
#if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM || defined HAS_MANNLCOUNTER
|
||||||
// innterrupt handler pin change
|
// innterrupt handler pin change
|
||||||
ISR(PCINT0_vect)
|
ISR(PCINT0_vect)
|
||||||
{
|
{
|
||||||
|
#ifdef HAS_MANNLCOUNTER //counter mode
|
||||||
|
if((millis() - alteZeit) > entprellZeit) {
|
||||||
|
// innerhalb der entprellZeit nichts machen
|
||||||
|
count_min++;
|
||||||
|
count_all++;
|
||||||
|
alteZeit = millis(); // last button push
|
||||||
|
}
|
||||||
|
|
||||||
|
#else //Alarm mode
|
||||||
sleep_disable();
|
sleep_disable();
|
||||||
#ifdef HAS_LED
|
#ifdef HAS_LED
|
||||||
blink(1);
|
blink(1);
|
||||||
#endif
|
#endif
|
||||||
alarm = true;
|
alarm = true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -265,7 +281,7 @@ void setup()
|
||||||
radio.sleep();
|
radio.sleep();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM
|
#if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM || defined HAS_MANNLCOUNTER
|
||||||
MCUCR = (MCUCR & ~(bit(ISC01)|bit(ISC00))) | bit(ISC01); // fallende Flanke
|
MCUCR = (MCUCR & ~(bit(ISC01)|bit(ISC00))) | bit(ISC01); // fallende Flanke
|
||||||
GIMSK = (1<<PCIE0);
|
GIMSK = (1<<PCIE0);
|
||||||
PCMSK0 = (1<<ALARM_INT);
|
PCMSK0 = (1<<ALARM_INT);
|
||||||
|
@ -290,6 +306,12 @@ void loop()
|
||||||
struct lora_data {
|
struct lora_data {
|
||||||
uint8_t bat;
|
uint8_t bat;
|
||||||
} __attribute__ ((packed)) data;
|
} __attribute__ ((packed)) data;
|
||||||
|
#elif defined HAS_MANNLCOUNTER
|
||||||
|
struct lora_data {
|
||||||
|
uint8_t bat;
|
||||||
|
uint8_t count_min;
|
||||||
|
uint32_t count_all;
|
||||||
|
} __attribute__ ((packed)) data;
|
||||||
#elif defined HAS_ALARM
|
#elif defined HAS_ALARM
|
||||||
struct lora_data {
|
struct lora_data {
|
||||||
uint8_t bat;
|
uint8_t bat;
|
||||||
|
@ -407,8 +429,11 @@ void loop()
|
||||||
delay(25);
|
delay(25);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// Send LoRa Packet, Increment Frame Counter
|
// Send LoRa Packet, Increment Frame Counter
|
||||||
lora.Send_Data((unsigned char *)&data, sizeof(data), Frame_Counter_Tx, SF7BW125, 0x01);
|
lora.Send_Data((unsigned char *)&data, sizeof(data), Frame_Counter_Tx, SF7BW125, 0x01);
|
||||||
|
#ifdef HAS_MANNLCOUNTER
|
||||||
|
count_min = 0;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
// Save the next FrameCounter to EEPROM
|
// Save the next FrameCounter to EEPROM
|
||||||
Frame_Counter_Tx++;
|
Frame_Counter_Tx++;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#define HAS_ALARM - send message when pin is triggered
|
#define HAS_ALARM - send message when pin is triggered
|
||||||
#define HAS_SHT21_ALARM - combined Sensor with SHT21 and Alarm trigger
|
#define HAS_SHT21_ALARM - combined Sensor with SHT21 and Alarm trigger
|
||||||
#define HAS_BME280_ALARM - combined Sensor with BME280 and Alarm trigger
|
#define HAS_BME280_ALARM - combined Sensor with BME280 and Alarm trigger
|
||||||
|
#define HAS_MANNLCOUNTER - count persons via click button
|
||||||
|
|
||||||
* LED Support
|
* LED Support
|
||||||
#define LED_PIN PIN_A7 - LED is connected to ATTiny84 Pin A7 on TinyTX SMD / TinyLora
|
#define LED_PIN PIN_A7 - LED is connected to ATTiny84 Pin A7 on TinyTX SMD / TinyLora
|
||||||
|
@ -43,6 +44,8 @@
|
||||||
If you want to turn your sensor(s) on and off connect Vdd Pin of DS18B20 with Pin defined here
|
If you want to turn your sensor(s) on and off connect Vdd Pin of DS18B20 with Pin defined here
|
||||||
#define DS18B20_POWER PIN_A1 - DS18B20 Power pin is connected on D9/ATtiny pin 12
|
#define DS18B20_POWER PIN_A1 - DS18B20 Power pin is connected on D9/ATtiny pin 12
|
||||||
|
|
||||||
|
* Mannl-Counter
|
||||||
|
#define ALARM_PIN PIN_A0 - The pin defined here will increase the counter if pulled low.
|
||||||
|
|
||||||
* Time between Measurements
|
* Time between Measurements
|
||||||
#define SLEEP_TIME 528 - Time in Seconds between Measurements. Try it out to get a good Approximation
|
#define SLEEP_TIME 528 - Time in Seconds between Measurements. Try it out to get a good Approximation
|
||||||
|
@ -57,7 +60,9 @@
|
||||||
// LoRa RFM95 + SHT21, LED on Pin A7
|
// LoRa RFM95 + SHT21, LED on Pin A7
|
||||||
|
|
||||||
#define RF_LORA
|
#define RF_LORA
|
||||||
#define HAS_SHT21
|
//#define HAS_SHT21
|
||||||
|
#define HAS_MANNLCOUNTER
|
||||||
|
#define ALARM_PIN PIN_A0
|
||||||
#define LED_PIN PIN_A7
|
#define LED_PIN PIN_A7
|
||||||
#define SLEEP_TIME 544
|
#define SLEEP_TIME 544
|
||||||
// Information from The Things Network, device configuration ACTIVATION METHOD: ABP, msb left
|
// Information from The Things Network, device configuration ACTIVATION METHOD: ABP, msb left
|
||||||
|
|
63
Firmware/ttn/decoder.js
Normal file
63
Firmware/ttn/decoder.js
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
|
||||||
|
function Decoder(bytes, port) {
|
||||||
|
var decoded = {};
|
||||||
|
|
||||||
|
if (bytes.length == 16) {
|
||||||
|
// Old Payload Format
|
||||||
|
decoded.t = ((bytes[0]) | (bytes[1] << 8 ) | (bytes[2] << 16 ) | (bytes[3] << 24)) / 100.0;
|
||||||
|
decoded.p = ((bytes[4]) | (bytes[5] << 8 ) | (bytes[6] << 16 ) | (bytes[7] << 24)) / 100.0;
|
||||||
|
decoded.h = ((bytes[8]) | (bytes[9] << 8 ) | (bytes[10] << 16 ) | (bytes[11] << 24)) / 100.0;
|
||||||
|
decoded.v = ((bytes[12]) | (bytes[13] << 8 ) | (bytes[14] << 16 ) | (bytes[15] << 24)) / 1000.0;
|
||||||
|
} else {
|
||||||
|
// New Payload Format
|
||||||
|
// We always have Battery Voltage (uint8_t)
|
||||||
|
decoded.v = (bytes[0] * 20) / 1000.0;
|
||||||
|
|
||||||
|
// Alarm Triggered (uint8_t)
|
||||||
|
if (bytes.length == 2)
|
||||||
|
decoded.a = bytes[1];
|
||||||
|
|
||||||
|
// Temperature 2 * DS18B20
|
||||||
|
if (bytes.length == 6){
|
||||||
|
decoded.t1 = ((bytes[2]) | (bytes[3] << 8 )) / 100.0;
|
||||||
|
decoded.t2 = ((bytes[4]) | (bytes[5] << 8 )) / 100.0;
|
||||||
|
return decoded;
|
||||||
|
}
|
||||||
|
// Mannl-counter
|
||||||
|
if (bytes.length == 8){
|
||||||
|
decoded.countmin = ((bytes[1]) | (bytes[2] << 8 ));
|
||||||
|
decoded.countall = ((bytes[1]) | (bytes[2] << 8 ) | (bytes[3] << 16 ) | (bytes[4] << 24));
|
||||||
|
return decoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Temperature (int32_t)
|
||||||
|
if (bytes.length >= 5)
|
||||||
|
decoded.t = ((bytes[1]) | (bytes[2] << 8 ) | (bytes[3] << 16 ) | (bytes[4] << 24)) / 100.0;
|
||||||
|
|
||||||
|
// Humidity (int32_t)
|
||||||
|
if (bytes.length >= 9)
|
||||||
|
decoded.h = ((bytes[5]) | (bytes[6] << 8 ) | (bytes[7] << 16 ) | (bytes[8] << 24)) / 100.0;
|
||||||
|
|
||||||
|
// Alarm Triggered (uint8_t)
|
||||||
|
if (bytes.length == 10)
|
||||||
|
decoded.a = bytes[9];
|
||||||
|
|
||||||
|
// SHT21 + Brightness (int16_t)
|
||||||
|
if (bytes.length == 11)
|
||||||
|
decoded.b = ((bytes[9]) | (bytes[10] << 8 ));
|
||||||
|
|
||||||
|
// Atmospheric Pressure (int32_t)
|
||||||
|
if (bytes.length >= 13)
|
||||||
|
decoded.p = ((bytes[9]) | (bytes[10] << 8 ) | (bytes[11] << 16 ) | (bytes[12] << 24)) / 100.0;
|
||||||
|
|
||||||
|
// Alarm Triggered (uint8_t)
|
||||||
|
if (bytes.length == 14)
|
||||||
|
decoded.a = bytes[13];
|
||||||
|
|
||||||
|
// BME280 + Brightness (int16_t)
|
||||||
|
if (bytes.length == 15)
|
||||||
|
decoded.b = ((bytes[13]) | (bytes[14] << 8 ));
|
||||||
|
}
|
||||||
|
|
||||||
|
return decoded;
|
||||||
|
}
|
Loading…
Reference in a new issue