/
DS18B20_current_measured_values.ino
110 lines (88 loc) · 4.83 KB
/
DS18B20_current_measured_values.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*******************************************************************************
* The Things Network - ABP Feather
*
* This uses ABP (Activation by Personalization), where session keys for
* communication would be assigned/generated by TTN and hard-coded on the device.
*
* Copyright (c) 2015 Thomas Telkamp and Matthijs Kooijman
* Copyright (c) 2018 Terry Moore, MCCI
* Copyright (c) 2018 Brent Rubell, Adafruit Industries
*
* Permission is hereby granted, free of charge, to anyone
* obtaining a copy of this document and accompanying files,
* to do whatever they want with them without any restriction,
* including, but not limited to, copying, modification and redistribution.
* NO WARRANTY OF ANY KIND IS PROVIDED.
*
* Reference: https://github.com/mcci-catena/arduino-lmic
*
* Modified for DS18B20 - current measured values, 5. 4. 2022
*******************************************************************************/
#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 12 // Pin 12 on the Adafruit
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#include<CayenneLPP.h> // Cayenne Low Power Payload (LPP)
CayenneLPP lpp(51);
//--------------------------------------- Here change your keys -------------------------------------------------
static const PROGMEM u1_t NWKSKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // LoRaWAN NwkSKey, network session key, MSB
static const u1_t PROGMEM APPSKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // LoRaWAN AppSKey, application session key, MSB
static const u4_t DEVADDR = 0x00000000; // LoRaWAN end-device address (DevAddr), MSB
//---------------------------------------------------------------------------------------------------------------
const lmic_pinmap lmic_pins = { // Pin mapping for the Adafruit Feather 32U4 LoRa
.nss = 8,
.rxtx = LMIC_UNUSED_PIN,
.rst = 4,
.dio = {7, 6, LMIC_UNUSED_PIN},
.rxtx_rx_active = 0,
.rssi_cal = 8,
.spi_freq = 1000000,
};
static osjob_t sendjob; // Job
const unsigned TX_INTERVAL = 300; // 5 miutes
void onEvent (ev_t ev) {
if(ev == EV_TXCOMPLETE) {
os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send); // Schedule next transmission
}
}
void do_send(osjob_t* j){
float temp = 0.0;
sensors.requestTemperatures(); // Send the command to get temperature readings from DS18B20
temp = sensors.getTempCByIndex(0); // Current temperature
lpp.reset();
lpp.addTemperature(1, temp); // Add the current temperature into channel 1
LMIC_setTxData2(1, lpp.getBuffer(), lpp.getSize(), 0); // Prepare upstream data transmission at the next possible time.
}
void setup() {
os_init();
LMIC_reset();
uint8_t appskey[sizeof(APPSKEY)];
uint8_t nwkskey[sizeof(NWKSKEY)];
memcpy_P(appskey, APPSKEY, sizeof(APPSKEY));
memcpy_P(nwkskey, NWKSKEY, sizeof(NWKSKEY));
LMIC_setSession (0x13, DEVADDR, nwkskey, appskey);
//EU868
LMIC_setupChannel(0, 868100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(1, 868300000, DR_RANGE_MAP(DR_SF12, DR_SF7B), BAND_CENTI); // g-band
LMIC_setupChannel(2, 868500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(3, 867100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(4, 867300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(5, 867500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(6, 867700000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(7, 867900000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(8, 868800000, DR_RANGE_MAP(DR_FSK, DR_FSK), BAND_MILLI); // g2-band
LMIC_setLinkCheckMode(0); // Disable link check validation
LMIC.dn2Dr = DR_SF9; // TTN uses SF9 for its RX2 window.
LMIC_setDrTxpow(DR_SF9,14); // Set data rate and transmit power for uplink
LMIC_setAdrMode(0);
LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);
sensors.begin(); // DS18B20
do_send(&sendjob); // Start sendjob
}
void loop() {
os_runloop_once();
}