2020-09-10 14:37:54 +00:00
# ATTNode Firmware
2019-09-19 03:40:34 +00:00
2020-04-21 06:13:10 +00:00
Example Sensor Node Firmware with a BMP/E280 or SHT21 Sensor. Used Sensor has to be set via #define in the src/secconfig.h (HAS_BME280 or HAS_SHT21). Please change the values in src/secconfig.h to your Keys from https://console.thethingsnetwork.org. Device has to be set to ABP Mode and the Frame Counter has to be set to 16 Bit.
2019-10-07 17:07:07 +00:00
2020-09-10 14:37:54 +00:00
For a complete explanation of the Parameters possible in the secconfig.h see https://www.attno.de/sites/attnode/20-firmware
2020-02-08 16:43:35 +00:00
2019-10-07 17:06:27 +00:00
The code also supports the RFM69W wireless module instead of the RFM95W LoRa module. For this purpose you need a receiver. Example code for a receiver in python (tested on a Raspberry Pi, RFM69 connected via SPI) can be found at https://www.seiichiro0185.org/git/IOT/sensord
2019-09-19 17:40:32 +00:00
2019-09-19 18:14:51 +00:00
Project was created using PlatformIO Atmel-AVR Framework
## Decoder for the TTN Application
```
function Decoder(bytes, port) {
var decoded = {};
2020-01-26 16:14:12 +00:00
2020-02-07 07:24:17 +00:00
if (bytes.length == 16) {
// Old Payload Format
2020-02-13 04:44:11 +00:00
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 ;
2020-02-07 07:24:17 +00:00
} else {
// New Payload Format
// We always have Battery Voltage (uint8_t)
decoded.v = (bytes[0] * 20) / 1000.0;
2020-06-13 09:02:51 +00:00
// Alarm Triggered (uint8_t)
if (bytes.length == 2)
2020-06-13 14:13:18 +00:00
decoded.a = bytes[1];
2020-06-13 09:02:51 +00:00
2020-07-08 16:24:40 +00:00
// 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;
}
2020-02-07 07:24:17 +00:00
// Temperature (int32_t)
if (bytes.length >= 5)
2020-02-13 04:44:11 +00:00
decoded.t = ((bytes[1]) | (bytes[2] < < 8 ) | ( bytes [ 3 ] < < 16 ) | ( bytes [ 4 ] < < 24 ) ) / 100 . 0 ;
2020-01-26 16:14:12 +00:00
2020-02-07 07:24:17 +00:00
// Humidity (int32_t)
if (bytes.length >= 9)
2020-02-13 04:44:11 +00:00
decoded.h = ((bytes[5]) | (bytes[6] < < 8 ) | ( bytes [ 7 ] < < 16 ) | ( bytes [ 8 ] < < 24 ) ) / 100 . 0 ;
2020-02-07 07:24:17 +00:00
2020-06-21 19:35:40 +00:00
// Alarm Triggered (uint8_t)
if (bytes.length == 10)
decoded.a = bytes[9];
2020-05-10 08:09:29 +00:00
// SHT21 + Brightness (int16_t)
if (bytes.length == 11)
decoded.b = ((bytes[9]) | (bytes[10] < < 8 ) ) ;
// Atmospheric Pressure (int32_t)
2020-02-07 07:24:17 +00:00
if (bytes.length >= 13)
2020-02-13 04:44:11 +00:00
decoded.p = ((bytes[9]) | (bytes[10] < < 8 ) | ( bytes [ 11 ] < < 16 ) | ( bytes [ 12 ] < < 24 ) ) / 100 . 0 ;
2020-05-10 08:09:29 +00:00
2020-06-21 19:35:40 +00:00
// Alarm Triggered (uint8_t)
if (bytes.length == 14)
decoded.a = bytes[13];
2020-05-10 08:09:29 +00:00
// BME280 + Brightness (int16_t)
if (bytes.length == 15)
decoded.b = ((bytes[13]) | (bytes[14] < < 8 ) ) ;
2020-02-07 07:24:17 +00:00
}
2019-09-19 18:14:51 +00:00
return decoded;
}
2019-09-20 10:16:20 +00:00
```
2020-04-19 09:13:31 +00:00
## License
The firmware-code in this repository is licensed under the 3-clause BSD License (see LICENSE-File)