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
|
||||
|
||||
```
|
||||
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;
|
||||
}
|
||||
```
|
||||
take a look in ttn folder
|
||||
|
||||
## License
|
||||
The firmware-code in this repository is licensed under the 3-clause BSD License (see LICENSE-File)
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
SHT21 sensor;
|
||||
#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;
|
||||
|
||||
// Get the Interrupt Mask for the selected Alarm PIN
|
||||
|
@ -92,6 +92,12 @@
|
|||
DallasTemperature sensors(&oneWire);
|
||||
#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
|
||||
uint16_t sleep_interval;
|
||||
|
||||
|
@ -174,15 +180,25 @@ ISR(WATCHDOG_vect) {
|
|||
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
|
||||
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();
|
||||
#ifdef HAS_LED
|
||||
blink(1);
|
||||
#endif
|
||||
alarm = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -265,7 +281,7 @@ void setup()
|
|||
radio.sleep();
|
||||
#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
|
||||
GIMSK = (1<<PCIE0);
|
||||
PCMSK0 = (1<<ALARM_INT);
|
||||
|
@ -290,6 +306,12 @@ void loop()
|
|||
struct lora_data {
|
||||
uint8_t bat;
|
||||
} __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
|
||||
struct lora_data {
|
||||
uint8_t bat;
|
||||
|
@ -407,8 +429,11 @@ void loop()
|
|||
delay(25);
|
||||
}
|
||||
#else
|
||||
// Send LoRa Packet, Increment Frame Counter
|
||||
lora.Send_Data((unsigned char *)&data, sizeof(data), Frame_Counter_Tx, SF7BW125, 0x01);
|
||||
// Send LoRa Packet, Increment Frame Counter
|
||||
lora.Send_Data((unsigned char *)&data, sizeof(data), Frame_Counter_Tx, SF7BW125, 0x01);
|
||||
#ifdef HAS_MANNLCOUNTER
|
||||
count_min = 0;
|
||||
#endif
|
||||
#endif
|
||||
// Save the next FrameCounter to EEPROM
|
||||
Frame_Counter_Tx++;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#define HAS_ALARM - send message when pin is triggered
|
||||
#define HAS_SHT21_ALARM - combined Sensor with SHT21 and Alarm trigger
|
||||
#define HAS_BME280_ALARM - combined Sensor with BME280 and Alarm trigger
|
||||
#define HAS_MANNLCOUNTER - count persons via click button
|
||||
|
||||
* LED Support
|
||||
#define LED_PIN PIN_A7 - LED is connected to ATTiny84 Pin A7 on TinyTX SMD / TinyLora
|
||||
|
@ -42,8 +43,10 @@
|
|||
|
||||
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
|
||||
|
||||
* Mannl-Counter
|
||||
#define ALARM_PIN PIN_A0 - The pin defined here will increase the counter if pulled low.
|
||||
|
||||
|
||||
* Time between Measurements
|
||||
#define SLEEP_TIME 528 - Time in Seconds between Measurements. Try it out to get a good Approximation
|
||||
Examples from my Tests::
|
||||
|
@ -57,7 +60,9 @@
|
|||
// LoRa RFM95 + SHT21, LED on Pin A7
|
||||
|
||||
#define RF_LORA
|
||||
#define HAS_SHT21
|
||||
//#define HAS_SHT21
|
||||
#define HAS_MANNLCOUNTER
|
||||
#define ALARM_PIN PIN_A0
|
||||
#define LED_PIN PIN_A7
|
||||
#define SLEEP_TIME 544
|
||||
// Information from The Things Network, device configuration ACTIVATION METHOD: ABP, msb left
|
||||
|
|
|
@ -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 New Issue