Erriez Oregon THN128 433MHz temperature sensor library for Arduino  1.1.0
This is an Oregon THN128 433MHz temperature sensor transmit/receive library for Arduino.
ErriezOregonTHN128.h
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2020-2022 Erriez
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
25 #ifndef ERRIEZ_OREGON_THN128_H_
26 #define ERRIEZ_OREGON_THN128_H_
27 
28 /* Check platform */
29 #if !defined(ARDUINO_ARCH_AVR) && !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32)
30 #error "Platform not supported."
31 #endif
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #include <stdbool.h>
38 #include <stdint.h>
39 
40 /* Timing micro's in micro seconds */
41 #define T_RX_TOLERANCE_US 400
42 #define T_PREAMBLE_SPACE_US 3000
43 #define T_SYNC_US 5500
44 #define T_BIT_US 1450
45 #define T_SPACE_FRAMES_MS 100
46 
47 #define T_SYNC_H_MIN (T_SYNC_US - T_RX_TOLERANCE_US)
48 #define T_SYNC_H_MAX (T_SYNC_US + T_RX_TOLERANCE_US)
49 
50 #define T_SYNC_L_MIN_0 (T_SYNC_US + T_BIT_US - T_RX_TOLERANCE_US)
51 #define T_SYNC_L_MAX_0 (T_SYNC_US + T_BIT_US + T_RX_TOLERANCE_US)
52 #define T_SYNC_L_MIN_1 (T_SYNC_US - T_RX_TOLERANCE_US)
53 #define T_SYNC_L_MAX_1 (T_SYNC_US + T_RX_TOLERANCE_US)
54 
55 #define T_BIT_SHORT_MIN (T_BIT_US - T_RX_TOLERANCE_US)
56 #define T_BIT_SHORT_MAX (T_BIT_US + T_RX_TOLERANCE_US)
57 #define T_BIT_LONG_MIN ((T_BIT_US * 2) - T_RX_TOLERANCE_US)
58 #define T_BIT_LONG_MAX ((T_BIT_US * 2) + T_RX_TOLERANCE_US)
59 
63 typedef struct {
64  uint32_t rawData;
65  uint8_t rollingAddress;
66  uint8_t channel;
67  int16_t temperature;
68  bool lowBattery;
70 
71 /* Public functions */
72 bool OregonTHN128_CheckCRC(uint32_t rawData);
73 void OregonTHN128_TempToString(char *temperatureStr, uint8_t temperatureStrLen, int16_t temperature);
75 bool OregonTHN128_RawToData(uint32_t rawData, OregonTHN128Data_t *data);
76 
77 #ifdef __cplusplus
78 }
79 #endif
80 
81 #endif /* ERRIEZ_OREGON_THN128_H_ */
uint32_t OregonTHN128_DataToRaw(OregonTHN128Data_t *data)
Convert data structure to 32-bit raw data.
bool OregonTHN128_RawToData(uint32_t rawData, OregonTHN128Data_t *data)
Cnonvert 32-bit raw data to OregonTHN128Data_t structure.
void OregonTHN128_TempToString(char *temperatureStr, uint8_t temperatureStrLen, int16_t temperature)
Convert temperature to string.
bool OregonTHN128_CheckCRC(uint32_t rawData)
Verify checksum.