-
Notifications
You must be signed in to change notification settings - Fork 2
/
ErriezOregonTHN128Receive.ino
109 lines (94 loc) · 3.51 KB
/
ErriezOregonTHN128Receive.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
/*
* MIT License
*
* Copyright (c) 2020-2022 Erriez
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <Arduino.h>
#include <ErriezOregonTHN128Receive.h> // https://github.com/Erriez/ErriezOregonTHN128
#if defined(ARDUINO_ARCH_AVR)
#include <LowPower.h> // https://github.com/LowPowerLab/LowPower
#define RF_RX_PIN 2 // Connect RF receive pin to Arduino pin 2 (INT0) or pin 3 (INT1)
#elif defined(ARDUINO_ARCH_ESP8266)
#define RF_RX_PIN 14 // GPIO14 NodeMCU D5
#elif defined(ARDUINO_ARCH_ESP32)
#define RF_RX_PIN 19 // GPIO19
#else
#error "May work, but not tested on this target"
#endif
void printReceivedData(OregonTHN128Data_t *data)
{
bool negativeTemperature = false;
static unsigned long rxCount = 0;
int16_t tempAbs;
char msg[80];
// Convert to absolute temperature
tempAbs = data->temperature;
if (tempAbs < 0) {
negativeTemperature = true;
tempAbs *= -1;
}
snprintf_P(msg, sizeof(msg),
PSTR("RX %lu: Rol: %d, Channel %d, Temp: %s%d.%d, Low batt: %d (0x%08lx)"),
rxCount++,
data->rollingAddress, data->channel,
(negativeTemperature ? "-" : ""), (tempAbs / 10), (tempAbs % 10), data->lowBattery,
(unsigned long)data->rawData);
Serial.println(msg);
}
void setup()
{
// Initialize serial port
Serial.begin(115200);
Serial.println(F("\nErriez Oregon THN128 433MHz temperature receive"));
// Turn LED on
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
// Initialize receiver
OregonTHN128_RxBegin(RF_RX_PIN);
}
void loop()
{
OregonTHN128Data_t data;
// Check temperature received
if (OregonTHN128_Available()) {
// Turn LED on
digitalWrite(LED_BUILTIN, HIGH);
// Read temperature
OregonTHN128_Read(&data);
// Print received data
printReceivedData(&data);
//#if defined(ARDUINO_ARCH_AVR)
// // Wait ~30 seconds before receiving next temperature from one transmitter
// // Works only when using one channel
// Serial.flush();
// LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
// LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
// LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
// LowPower.powerDown(SLEEP_2S, ADC_OFF, BOD_OFF);
//#else
// delay(30 * 60);
//#endif
// Turn LED off
digitalWrite(LED_BUILTIN, LOW);
// Enable receive
OregonTHN128_RxEnable();
}
}