L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
mysensors_base.h
Go to the documentation of this file.
1/*
2 * mysensors_base.h
3 *
4 * The base definition/declaration for sensors, global control variables and sensor availability
5 *
6 * Created on: 29. 1. 2026
7 * Author: Milan
8 */
9
10#ifndef INC_MYSENSORS_BASE_H_
11#define INC_MYSENSORS_BASE_H_
12
13#include "mysensors_def.h"
14
15#include "tmphm_sht45.h"
16#include "amb_tsl2591.h"
17#include "bar_ils22qs.h"
18#include "bar_bmp585.h"
19#include "scd41.h"
20#include "sps30.h"
21#include "systime.h"
22#include <stdint.h>
23
24#pragma pack(1)
25
26/**
27 * @brief
28 * The chunk structure for read/write data from/to device. The data buffer size depends on current DataRate, and cannot exceed the maximimum
29 * for current data rate, otherwise the lora process fails.
30 * @code
31 * Max payload per DR (EU868 region):
32 * Data Rate Spreading Factor Max App Payload
33 * DR0 SF12 / 125kHz 51 bytes
34 * DR1 SF11 / 125kHz 51 bytes
35 * DR2 SF10 / 125kHz 51 bytes
36 * DR3 SF9 / 125kHz 115 bytes
37 * DR4 SF8 / 125kHz 222 bytes
38 * DR5 SF7 / 125kHz 222 bytes
39 * @endcode
40 *
41 */
42
43
44/**
45 * @defgroup SensorSizes Per-sensor payload size helpers
46 * @{
47 * Each macro evaluates to sizeof(sensor_data_struct) when the corresponding
48 * sensor is enabled, or 0 when it is disabled. Used to compute SENSORS_DATASIZE.
49 */
50#ifdef SENSOR_SHT45
51 /** @brief Byte size of tmphm_sht45_t in the packed sensor record. */
52 #define SIZE_SHT45 sizeof(tmphm_sht45_t)
53 /** @brief Byte size of payload CayennelLpp data for NFC stored into */
54 #define SIZE_SHT45_NFC (4+3) // LPP_TEMPERATURE_SIZE+LPP_RELATIVE_HUMIDITY_SIZE
55 #define SIZE_SHT45_NFC_NEG 0 // in case, if SHT45 is not defined - to SCD41
56#else
57 #define SIZE_SHT45 0
58 #define SIZE_SHT45_NFC 0
59 #define SIZE_SHT45_NFC_NEG (4+3) // in case, if SHT45 is not defined - to SCD41
60#endif
61
62#ifdef SENSOR_AMB_TSL2591
63 /** @brief Byte size of amb_tsl2591_t in the packed sensor record. */
64 #define SIZE_TSL2591 sizeof(amb_tsl2591_t)
65 /** @brief Byte size of payload CayennelLpp data for NFC stored into */
66 #define SIZE_TSL2591_NFC 4 // LPP_LUMINOSITY_SIZE
67#else
68 #define SIZE_TSL2591 0
69 #define SIZE_TSL2591_NFC 0
70#endif
71
72#ifdef SENSOR_BAR_ILS22QS
73 /** @brief Byte size of bar_ils22qs_t in the packed sensor record. */
74 #define SIZE_ILS22QS sizeof(bar_ils22qs_t)
75 /** @brief Byte size of payload CayennelLpp data for NFC stored into */
76 #define SIZE_ILS22QS_NFC (4+0) // LPP_BAROMETRIC_PRESSURE_SIZE + LPP_TEMPERATURE_SIZE
77#else
78 #define SIZE_ILS22QS 0
79 #define SIZE_ILS22QS_NFC 0
80#endif
81
82#ifdef SENSOR_BAR_BMP585
83 /** @brief Byte size of bar_bmp585_t in the packed sensor record. */
84 #define SIZE_BMP585 sizeof(bar_bmp585_t)
85 /** @brief Byte size of payload CayennelLpp data for NFC stored into */
86 #define SIZE_BMP585_NFC (4+0) // LPP_BAROMETRIC_PRESSURE_SIZE + LPP_TEMPERATURE_SIZE
87#else
88 #define SIZE_BMP585 0
89 #define SIZE_BMP585_NFC 0
90#endif
91
92#ifdef SENSOR_SCD41
93 /** @brief Byte size of scd41_t in the packed sensor record. */
94 #define SIZE_SCD41 sizeof(scd41_t)
95 /** @brief Byte size of payload CayennelLpp data for NFC stored into */
96 #define SIZE_SCD41_NFC (4+SIZE_SHT45_NFC_NEG) // LPP_CONCENTRATION_SIZE + LPP_TEMPERATURE_SIZE + LPP_RELATIVE_HUMIDITY_SIZE
97#else
98 #define SIZE_SCD41 0
99 #define SIZE_SCD41_NFC 0
100#endif
101
102#ifdef SENSOR_SPS30
103 /** @brief Byte size of sps30_t in the packed sensor record. */
104 #define SIZE_SPS30 sizeof(sps30_t)
105 /** @brief Byte size of payload CayennelLpp data for NFC stored into */
106 #define SIZE_SPS30_NFC (4+4) // LPP_PARTICULATE_MATTER_SIZE + LPP_PARTICULATE_MATTER_SIZE (1_0, 2_5)
107#else
108 #define SIZE_SPS30 0
109 #define SIZE_SPS30_NFC 0
110#endif
111/** @} */
112
113/**
114 * @brief Total size in bytes of one packed sensor data record.
115 * Computed as the sum of all enabled sensor struct sizes.
116 * Stored as Data_ItemSize in mems_MainBlock_t; changing the set of
117 * active sensors changes this value and requires a memory reset.
118 * The struct size contains sizeof(SysTime_t) - represent the time of measure in UTC
119
120 sizeof(SysTime_t) // 6 bytes (uint32_t Seconds + int16_t SubSeconds)
121 + SIZE_SHT45 // 9 bytes
122 + SIZE_TSL2591 // 5 bytes
123 + SIZE_ILS22QS // 13 bytes
124 + SIZE_BMP585 // 13 bytes
125 + SIZE_SCD41 // 13 bytes
126 + SIZE_SPS30 // 41 bytes
127 */
128
129#define SENSORS_DATASIZE (\
130 sizeof(SysTime_t) \
131 + SIZE_SHT45 \
132 + SIZE_TSL2591 \
133 + SIZE_ILS22QS \
134 + SIZE_BMP585 \
135 + SIZE_SCD41 \
136 + SIZE_SPS30 \
137 )
138
139
140/** @brief 4-byte ASCII signature stored at offset 0 of systemParams_t to validate data integrity. */
141#define SYSTEMPARAMS_SIGN "MTTV"
142
143/** @brief Total size in bytes of the systemParams_t structure stored on the NFC tag and send via LoRa - the size is used for check of struct systemParams_t
144 * and it doens't match, the Error_Handler() is called
145 * the size of structure must be modulo 4
146 */
147#define SZ_SYSTEMPARAMS 92
148
149/** @brief Total size in byte for one chunk between DEV and gateway - DR_0
150#define SZ_DATACHUNK 50
151 */
152
153/** @brief Version of the systemParams_t layout; increment when fields are added or reordered. */
154#define SYSTEMPARAMS_STRUCTVER 1
155
156/** @brief Application firmware minor version number (plain integer). */
157#define SYSTEMPARAMS_APPVER00 0x01
158
159/** @brief Application firmware major version number (plain integer) - check of validity struct together with SYSTEMPARAMS_SIGN. */
160#define SYSTEMPARAMS_APPVER01 0x01
161
162/** @brief The default sensor altitue */
163#define SYSTEMPARAMS_DEFAULTALTITUDE 300
164
165/** @brief Minimum allowed sensor measurement interval in milliseconds (30 seconds). */
166#define SYSTEMPARAMS_MINSENSORTIME 30000
167
168/** @brief Default sensor measurement interval in milliseconds (10 minutes). */
169#define SYSTEMPARAMS_DEFAULTSENSORTIME 60*1000*10
170
171/** @brief Maximum allowed sensor measurement interval in milliseconds (18 hour). */
172#define SYSTEMPARAMS_MAXSENSORTIME 60*1000*60*18
173
174/**
175 * @brief Minimum idle time in milliseconds before the device enters OFF (standby) mode.
176 * Values below ~10 s are too short because the LoRaWAN stack may still be
177 * finishing a transmission when the timer fires.
178 */
179#define SYSTEMPARAMS_MINTIME2OFF 10000
180
181/** @brief Default LoRaWAN JoinEUI / AppEUI (8 bytes, all zeros – overridden via NFC). */
182#define SYSTEM_APP_EUI 00,00,00,00,00,00,00,00
183
184/** @brief Default LoRaWAN AppKey (16 bytes – overridden via NFC before deployment). */
185#define SYSTEM_APP_KEY AB,CD,EF,01,02,03,10,11,12,05,06,07,EF,EF,EF,EF
186
187/** @brief First byte of the 3-byte OUI prefix used in the auto-generated DevEUI. */
188#define SYSTEM_APP_DevEUI0 0x45
189/** @brief Second byte of the 3-byte OUI prefix used in the auto-generated DevEUI. */
190#define SYSTEM_APP_DevEUI1 0x87
191/** @brief Third byte of the 3-byte OUI prefix used in the auto-generated DevEUI. */
192#define SYSTEM_APP_DevEUI2 0xF2
193
194/*
195 * The DevEUI is defined as fixed 3 bytes and CRC to identify of Amica RAK devices
196 * [ 45 87 F2 ] [ uid_4bytes ] [ crc8 ]
197 * 0 1 2 3 4 5 6 7
198 *
199 *
200 * The first 3 bytes of a DevEUI in LoRaWAN are typically an IEEE OUI (Organizationally Unique Identifier).
201 * Using a random value like 4587F2 risks colliding with a registered vendor. For example, 45:87:F2 may already belong to someone.
202 *
203 * Options:
204 * Register your own OUI with IEEE (~$730 USD, gives you a block of 4096+ EUIs) — overkill for most projects.
205 * Use the locally-administered bit — set bit 1 of byte 0 (0x02 mask), which signals "this is locally assigned, not globally unique."
206 * Example: 46 87 F2 (note 46 has bit 1 set). This is the standard way to signal a private/local identifier.
207 * Keep 4587F2 if this is purely internal/private LoRaWAN (no public network, no TTN/Helium), since collisions don't matter in a closed network.
208 *
209 * if (DevEUI[0] == 0x45 && DevEUI[1] == 0x87 && DevEUI[2] == F2 && calculateCrc(DevEUI, 7) == DevEUI[7])
210 * {
211 * }
212 */
213
214/** @brief The time, in seconds, the battery level sending interval - 12h*/
215#define SYSTEMPARAMS_BATTIMESEND (12*3600)
216
217/** @brief the voltage (mV) for processing. The system goes to OFF mode, if current votage is lower SYSTEMPARAMS_BATTMINWORK */
218#define SYSTEMPARAMS_BATTMINWORK 2600
219
220
221/**
222 * @brief Bitmask of sensor modules that are enabled / available for data collection.
223 * Used in systemParams_t.AvailableSensors; individual bits can be ORed together.
224 */
225typedef enum
226{
227 SYSPARAM_TEMP_HUM = 0x01, /**< Temperature and humidity sensor (SHT45) */
228 SYSPARAM_BAR = 0x02, /**< Barometric pressure sensor (ILPS22QS or BMP585) */
229 SYSPARAM_AMBIENT = 0x04, /**< Ambient light sensor (TSL2591) */
230 SYSPARAM_CO2 = 0x08, /**< CO2 / temperature / humidity sensor (SCD41) */
231 SYSPARAM_PARTICULAR = 0x10 /**< Particular matter sensor (SPS30) */
233
234
235/**
236 * @brief the list of LORAWAN port.\n
237 * @note must ensure that there is no conflict with the port settings\n
238 * The setting of systemParams_t is going via systemParamsRef_t - particular set the setting for each field separately in OnLoRaWANRxData function
239 */
240typedef enum
241{
242 LORAWANPORT_DATA_DEFAULT = 2, /**< the defaullt data lorawan port - sensor data sending via this port, can be changed via NFC or downlink */
243 LORAWANPORT_CONFIG_GET = 100, /**< config port data - read - server requires the systemParams_t data, write - via this port is send block to server (not last) */
244 LORAWANPORT_CONFIG_GET_LAST = LORAWANPORT_CONFIG_GET + 1, /**< config port data - write - the last chunk(or only one chunk) has been send/read */
245 LORAWANPORT_CONFIG_SET_PART = 102 /**< the port for set the part of configuration in systemParams_t via references defined in systemParamsRef_t */
247
248
249/**
250 * @brief System configuration parameters – persisted in NFC EEPROM at address 0.
251 * The structure contains all modifiable variables/settings of system, can be read/writa via NFC tool or LoRa special read/write process
252 * The structure is 92 bytes (SZ_SYSTEMPARAMS) with a CRC8 byte at the end.
253 * Fields marked RO are written by the firmware; fields marked RW can be updated by a phone app via the NFC EEPROM or via LoRa special process
254 *
255 * The following code is used for checking the structure validity:
256 * @code
257 * if (strcmp(_systemParams.Sign, SYSTEMPARAMS_SIGN) != 0 || _systemParams.AppVersion[1] != SYSTEMPARAMS_APPVER01)
258 * {
259 * .... the structure is not valid
260 * }
261 *
262 * // crc checking
263 * if (!systemParams_CheckCRC(&_systemParams))
264 * {
265 * .... the structure is not valid
266 * }
267 *
268 * @endcode
269 *
270 * @note Do not reorder fields – the phone app and MQTT server rely fixed offsets.
271 * @note Add/delete field, check the references in systemParamsRef_t
272 */
273typedef struct
274{
275 // header - identification of structure, sign & version
276 char Sign[5]; /**< RO Magic signature "MTTV" – used to detect uninitialized memory */
277 uint8_t AppVersion[2]; /**< RO Firmware version bytes [major, minor] (see SYSTEMPARAMS_APPVER00/01) */
278 // ----------------------------------------------------
279
280 // sensor settings
281 uint32_t SensTimeoutMeasure; /**< RW Sensor measurement interval in ms (min 30 s, default 10 min, max 18 h) */
282 uint16_t SensAltitude; /**< RW Elevation above sea level in metres used for sea-level pressure correction */
283 uint8_t SensSendInOnePacket; /**< RW 1 – pack all sensor values into one uplink; 0 – send separately (default 0) */
284 uint8_t SensPollSensors; /**< RW Bitmask of sensors to poll (see systemParams_Sensors_t); default 0x1F (all) */
285 uint8_t SensExistSensors; /**< RO Bitmask of sensors compiled available - existing sensors (see systemParams_Sensors_t) */
286
287 // ----------------------------------------------------
288
289 // memory settings
290 uint8_t MemsStoreSensorData; /**< RW 1 – store readings in external flash; 0 – transmit only (default 1) */
291 uint16_t MemsMaxSensorData; /**< RO Maximum number of sensor records the flash circular queue can hold */
292 uint16_t MemsCurrentCountSensorData; /**< RO Number of sensor records currently stored in the queue/flash */
293 // ----------------------------------------------------
294
295 // LoRaWan settings
296 uint8_t LoRaPort; /**< RW LoRaWAN data uplink port (min 1, default 2, max 99; settings/config ports 100-110, ports ≥224 are reserved) MT 9.4.2026 - fixed ports*/
297 uint8_t LoRaRepeatTryConnect; /**< RW Number of join retries after duty-cycle back-off (default 2, max 32) */
298 uint8_t LoRaAdaptiveDataRate; /**< RW 1 – enable ADR (DataRate field is then ignored); 0 – fixed DR (default 1) */
299 uint8_t LoRaDataRate; /**< RW Fixed data rate when ADR is disabled (0=DR_0 slowest … 5=DR_5 fastest) */
300 uint8_t LoRaTxPower; /**< RW TX power index (0=max power … 7=min power, default 0) */
301 uint8_t LoRaClass; /**< RW LoRaWAN device class: 0=Class A (default), 1=Class B, 2=Class C */
302 uint8_t LoRaRegion; /**< RW LoRaWAN region index (default 5 = EU868; range 0–9) */
303 //----------------------------------------------------
304
305 // hardware settings
306 uint8_t HWBatteryLevelStatus; /**< RO Battery charge level on a 1–254 scale (1 = very low, 254 = full) */
307 uint16_t HWBatteryMV; /**< RO Battery voltage in millivolts */
308 uint8_t HWDevEUI[8]; /**< RO DevEUI derived from chip UID (format: [45 87 F2][4-byte UID][crc8]) */
309 uint8_t HWAppEUI[8]; /**< RW LoRaWAN JoinEUI / AppEUI (default: all zeros) */
310 uint8_t HWAppKEY[16]; /**< RW LoRaWAN AppKey used for OTAA join (change before deployment) */
311 uint32_t HWDevADDR; /**< RO LoRaWAN DevAddr assigned after a successful OTAA join */
312 // ----------------------------------------------------
313
314 // device settings
315 uint8_t DevRestart; /**< RW Write 1 from phone app to trigger a software restart on next poll */
316 uint8_t DevReset; /**< RW Write 1 from phone app to reset to factory defaults on next poll */
317 uint8_t DevOnOff; /**< RW 0 – device wakes periodically by RTC timer; 1 – stay on (default 0) */
318 // ----------------------------------------------------
319
320 // MQTT settings
321 uint8_t MqttConfirm; /**< RW MQTT confirmation of data written to server database, default 0 */
322 uint64_t MqttTime; /**< Linux time of uint64 - UTC set from NFC and time when MCU goes to OFF state */
323 // ----------------------------------------------------
324
325 // internal params
326 uint32_t IntBatTimeSendUNIX; /**< internal setting - the time when was the battery status send via CayenneLpp - UNIX UTC time
327 repeatedly every SYSTEMPARAMS_BATTIMESEND */
328 // ----------------------------------------------------
329
330 // dummy
331 uint8_t Dummy[8]; /**< RW Reserved for future use; initialised to 0 */
332 // ------ CRC covers all fields above; Crc itself is excluded from the calculation
333 uint8_t Crc; /**< CRC8 of bytes 0..(SZ_SYSTEMPARAMS-2); must be the last field */
335
336/**
337 * @brief The references to systemParams_t for change values from server via downlink.\n
338 * The server sends via downlink the requirements for change of systemParams_t field, one by one. This struct is reference for finding the address of valid
339 * field in systemParams_t - its position and size:\n
340 */
341typedef struct
342{
343 uint8_t Inx; /**< index to systemParams_t. 0-Sign, 1-AppVersion, 2-SensTimeoutMeasure, 3-SensAltitude ... */
344 uint8_t Size; /**< size of specified field in systemParams_t according to Inx. 0-Sign,5, 1-AppVersion,2, 2-SensTimeoutMeasure,4, 3-SensAltitude,2 ... */
345 uint8_t Addr; /**< address(offset) from begin to field specified by Inx. */
346#ifdef DEBUG
347 char Name[30]; /**< only for Tamas */
348#endif
350
351
352/**
353 * @brief The last 50 records of payload (CayeneeLPP) are store in NFC for debuging. These data can be received via mobile phone application - NFC as systemParams_t\n
354 * the size of measureNFC_t
355 */
356#define SZ_MEASURENFC 16
357
358/**
359 * @brief The address, on which is the begin of measured data in NFC. The address is modulo 4, and space between 92 - 128 is reserver for future expanded structure of
360 * systemParams_t\n
361 * The address of measureNFC_t struct (nfc measure header) is on: MEASUREDATANFC_ADDR + sizeof(measureNFC_t);
362 */
363#define MEASUREDATANFC_ADDR 128
364
365/**
366 * @brief one data NFC block of measure data in payload CaynnelLPP format\n
367 * 32 - maximum for all sensors, can be compiled specified\n
368 * The 4 - is battery perc + reserve
369 * The size should be even boundary
370 */
371#define MEASUEREDATANFC_SIZE (\
372 4 \
373 + SIZE_SHT45_NFC \
374 + SIZE_TSL2591_NFC \
375 + SIZE_ILS22QS_NFC \
376 + SIZE_BMP585_NFC \
377 + SIZE_SCD41_NFC \
378 + SIZE_SPS30_NFC \
379 )
380
381/**
382 * @brief the maximum size EEPROM.
383 */
384#define MEASUEREDATANFC_EEPROMSIZE 2048
385/**
386 * @brief block of one measure data in CayennelLPP payload format\n
387 * The Data field contains the same payload as in LoRaWan processing, without UTC/TIME8/TIME16 fields, because the UTC time of measure is in UTCMeasureTime field.
388 * - the size of struct must be boundary 4 - because of NFC\n
389 * - ensure adding of other types to have boundary 4, otherwise the Error_Handler is called in sensorsBase_Init
390 *
391 */
392typedef struct
393{
394 uint32_t UTCMeasureTime; /**< the UTC absolute time of data measurement */
395 uint8_t Data[MEASUEREDATANFC_SIZE]; /**< max buffer data - ensure enough place for all data of sensors */
396 uint8_t DummyOn4[4 - ((sizeof(uint32_t) + MEASUEREDATANFC_SIZE) % 4)]; /**< dummy for boundary on 4 */
398
399/**
400 * @brief the control block of NFC on address MEASUREDATANFC_ADDR where are stored the last measure data\n
401 * The EEPROM of NFC has 2kB, 2048bytes on address 128(MEASUREDATANFC_ADDR), max size for sensor data is 1920 bytes\n
402 * sizeof(measureNFC_t) is 16(SZ_MEASURENFC) fixed struct size - !!! the size my be boundary 4 !!!\n
403 * it is followed by measure data, on Data field\n
404 * measureDataNFC_t - circular queue
405 */
406typedef struct
407{
408 uint8_t Count; /**< current count of payload data in NFC EEPROM from address MEASUEREDATANFC_SIZE */
409 uint8_t MaxCount;/**< maximum available payload data in NFC EEPROM */
410 uint8_t Size; /**< size of measureDataNFC_t (UTC+Data) */
411 uint8_t Inx; /**< the index of write for new value */
412 uint8_t Dummy[11];
413 // ------ CRC covers all fields above; Crc itself is excluded from the calculation
414 uint8_t Crc; /**< CRC8 of bytes 0..(SZ_MEASURENFC-2); must be the last field */
415 measureDataNFC_t Data[0]; /**< Data - only for information, where the measured data started */
417
418
419#pragma pack()
420
421extern int8_t _tryInit; /**< Flag used by xxx_Is() calls; when set to 1, the Is function attempts to (re-)initialize the sensor */
422extern systemParams_t _systemParams; /**< Global system parameters read from / written to the NFC tag EEPROM */
423extern systemParams_t _systemParamsBck; /**< Global system parameters backup buffer for NFC reading and and for sending via downlink to server */
424extern measureNFC_t _measureNFC; /**< Global measure NFC block for saving of measure data */
425extern uint8_t _batPercLevel; /**< The battery percentage level on start - the value is stored in CayeneeLPP buffer */
426
427/**
428 * @brief Return a pointer to the DevEUI stored in _systemParams.
429 * The DevEUI is auto-generated from the chip UID during initialisation
430 * and is read-only from the phone app's perspective.
431 * @return Pointer to the 8-byte DevEUI array inside _systemParams.
432 */
434
435/**
436 * @brief Return a pointer to the AppEUI (JoinEUI) stored in _systemParams.
437 * Used by the LoRaWAN stack during the OTAA join procedure.
438 * @return Pointer to the 8-byte AppEUI array inside _systemParams.
439 */
440uint8_t* systemParams_getAppEUI();
441
442/**
443 * @brief Return a pointer to the AppKey stored in _systemParams.
444 * Used by the LoRaWAN stack to derive session keys during OTAA join.
445 * @return Pointer to the 16-byte AppKey array inside _systemParams.
446 */
447uint8_t* systemParams_getAppKey();
448
449
450
451/**
452 * @brief Verify the CRC field of a systemParams_t structure.
453 * @param par Pointer to the systemParams_t to check.
454 * @retval 1 – CRC is valid (structure is intact).
455 * @retval 0 – CRC mismatch (structure is corrupt or uninitialised).
456 */
457uint8_t systemParams_CheckCRC(const systemParams_t* par);
458
459/**
460 * @brief Recalculate and store the CRC in _systemParams.Crc.
461 * Call this after modifying any field of _systemParams before writing
462 * the structure to the NFC EEPROM.
463 */
465
466/**
467 * @brief Clamp all RW fields of _systemParams to their valid ranges, called after loading parameters from NFC to ensure no out-of-range values are used (e.g. port numbers, timeouts, data rates).\n
468 * The DEVEui cannot be changed - problem of rewrite of DEVUi accross devices.
469 */
471
472/**
473 * @brief Check whether a particular sensor is enabled in _systemParams.AvailableSensors.
474 * @param sensorType One of the systemParams_Sensors_t bitmask values.
475 * @retval 1 – sensor is marked as available and should be polled.
476 * @retval 0 – sensor is disabled in the configuration.
477 */
479
480/**
481 * @brief setting/correction of the system time from _systemParams.MqttTime, if contains valid UNIX time(low uint32_t).
482 * MCU is reading MqttTime from NFC and compares with current system time - SysTimeGet
483 * The system time is changed(SysTimeSet) if is less that time in _systemParams.MqttTime
484 * @retval 0 - no changes
485 * @retval 1 - the system time has been update
486 * @retval 2 - the _systemParams.MqttTime
487 */
489
490/**
491 * @brief The setting of systemParams_t from server dowlink. The buffer contains the combination for setting of value\n
492 * @code
493 * 2-SensTimeoutMeasure,4,
494 * [2][C0D40100] - the setting for SensTimeoutMeasure -> inx:2 size:4, value:4bytes (120000)
495 * 3-SensAltitude,2
496 * [3][4803] - the setting for SensAltitude -> inx:3 size:2, value:2bytes (840)
497 *
498 * in buffer: [2][C0D40100]|[3][4803] or [3][4803]|[2][C0D40100]
499 * @endcode
500 */
501void systemParams_SetFromPart(const uint8_t* buffer, uint8_t bufSize);
502
503
504#ifdef WRITELOG
505/**
506 * @brief Log the current _systemParams fields to the UART debug output.
507 * @param info Optional prefix string printed before the dump (e.g. "LOAD" or "SAVE").
508 */
509void systemParams_Log(const char* info);
510#else
511#define systemParams_Log(...)
512#endif
513
514
515
516
517/**
518 * @brief Initialization of base sensor data structure
519 */
520void sensorsBase_Init();
521
522/**
523 * @brief start timer to off
524 * the function is called from PWR_EnterStopMode - timer is started
525 */
527
528/**
529 * @brief stop timer to off
530 * the function is called from PWR_ExitStopMode - the timer value is checked and the PWR_ExitStopMode was invoked from this times, system goes to OFF mode setModeDevice(MODEDEVICE_OFF)
531 */
533
534/**
535 * @brief the default initialization of _measureNFC struct
536 */
538
539/**
540 * @brief Recalculate and store the CRC in _measureNFC.Crc.\n
541 * Call this after modifying any field of _measureNFC before writing the structure to the NFC EEPROM.
542 */
544
545/**
546 * @brief Verify the CRC field of a _measureNFC structure.
547 * @retval 1 – CRC is valid (structure is intact).
548 * @retval 0 – CRC mismatch (structure is corrupt or uninitialised).
549 */
551
552//uint8_t sensorsBase_GetCRCMeasureNFC();
553
554//void systemParams_SetCRCSystemParams();
555
556#endif /* INC_MYSENSORS_BASE_H_ */
void sensorsBase_StartTimerToOff()
start timer to off the function is called from PWR_EnterStopMode - timer is started
systemParams_t _systemParams
uint8_t * systemParams_getAppKey()
Return a pointer to the AppKey stored in _systemParams. Used by the LoRaWAN stack to derive session k...
void sensorsBase_SetCRCMeasureNFC()
Recalculate and store the CRC in _measureNFC.Crc. Call this after modifying any field of _measureNFC ...
uint8_t systemParams_CorrectSystemTime()
setting/correction of the system time from _systemParams.MqttTime, if contains valid UNIX time(low ui...
void systemParams_SetCRCSystemParams()
Recalculate and store the CRC in _systemParams.Crc. Call this after modifying any field of _systemPar...
systemParams_Sensors_t
Bitmask of sensor modules that are enabled / available for data collection. Used in systemParams_t....
@ SYSPARAM_CO2
@ SYSPARAM_BAR
@ SYSPARAM_PARTICULAR
@ SYSPARAM_AMBIENT
@ SYSPARAM_TEMP_HUM
uint8_t * systemParams_getAppEUI()
Return a pointer to the AppEUI (JoinEUI) stored in _systemParams. Used by the LoRaWAN stack during th...
void sensorsBase_MeasureNFCInit()
the default initialization of _measureNFC struct
uint8_t * systemParams_getAppDevEUI()
Return a pointer to the DevEUI stored in _systemParams. The DevEUI is auto-generated from the chip UI...
uint8_t _batPercLevel
void sensorsBase_StopTimerToOff()
stop timer to off the function is called from PWR_ExitStopMode - the timer value is checked and the P...
void systemParams_SetFromPart(const uint8_t *buffer, uint8_t bufSize)
The setting of systemParams_t from server dowlink. The buffer contains the combination for setting of...
uint8_t sensorsBase_CheckCRCMeasureNFC()
Verify the CRC field of a _measureNFC structure.
systemParams_t _systemParamsBck
uint8_t systemParams_CheckCRC(const systemParams_t *par)
Verify the CRC field of a systemParams_t structure.
void systemParams_Log(const char *info)
Log the current _systemParams fields to the UART debug output.
int8_t _tryInit
void systemParams_Correction()
Clamp all RW fields of _systemParams to their valid ranges, called after loading parameters from NFC ...
#define MEASUEREDATANFC_SIZE
one data NFC block of measure data in payload CaynnelLPP format 32 - maximum for all sensors,...
measureNFC_t _measureNFC
void sensorsBase_Init()
Initialization of base sensor data structure.
uint8_t systemParams_IsSensorAvaiable(systemParams_Sensors_t sensorType)
Check whether a particular sensor is enabled in _systemParams.AvailableSensors.
loraWanPort_t
the list of LORAWAN port.
@ LORAWANPORT_CONFIG_GET
@ LORAWANPORT_CONFIG_GET_LAST
@ LORAWANPORT_DATA_DEFAULT
@ LORAWANPORT_CONFIG_SET_PART
block of one measure data in CayennelLPP payload format The Data field contains the same payload as i...
uint8_t Data[(4+(4+3)+0+0+(4+0)+0+0)]
uint8_t DummyOn4[4 -((sizeof(uint32_t)+(4+(4+3)+0+0+(4+0)+0+0)) % 4)]
the control block of NFC on address MEASUREDATANFC_ADDR where are stored the last measure data The EE...
uint8_t Dummy[11]
measureDataNFC_t Data[0]
System configuration parameters – persisted in NFC EEPROM at address 0. The structure contains all mo...
uint8_t AppVersion[2]
uint8_t SensExistSensors
uint8_t HWBatteryLevelStatus
uint8_t MemsStoreSensorData
uint8_t SensPollSensors
uint8_t HWAppEUI[8]
uint8_t HWAppKEY[16]
uint16_t MemsCurrentCountSensorData
uint8_t SensSendInOnePacket
uint32_t IntBatTimeSendUNIX
uint8_t HWDevEUI[8]
uint32_t SensTimeoutMeasure
uint8_t LoRaAdaptiveDataRate
uint16_t MemsMaxSensorData
uint8_t LoRaRepeatTryConnect
uint16_t SensAltitude
The references to systemParams_t for change values from server via downlink. The server sends via dow...
Map middleware systime.