|
L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
|
#include "mysensors_def.h"#include "tmphm_sht45.h"#include "amb_tsl2591.h"#include "bar_ils22qs.h"#include "bar_bmp585.h"#include "scd41.h"#include "sps30.h"#include <stdint.h>Go to the source code of this file.
Data Structures | |
| struct | systemParams_t |
| System configuration parameters – persisted in NFC EEPROM at address 0. The structure contains all modifiable variables/settings of system, can be read/writa via NFC tool or LoRa special read/write process The structure is 90 bytes (SZ_SYSTEMPARAMS) with a CRC8 byte at the end. 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. More... | |
Macros | |
| #define | SYSTEMPARAMS_SIGN "MTTV" |
| 4-byte ASCII signature stored at offset 0 of systemParams_t to validate data integrity. | |
| #define | SZ_SYSTEMPARAMS 90 |
| 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 and it doens't match, the Error_Handler() is called. | |
| #define | SYSTEMPARAMS_STRUCTVER 1 |
| Version of the systemParams_t layout; increment when fields are added or reordered. | |
| #define | SYSTEMPARAMS_APPVER00 0x01 |
| Application firmware minor version number (plain integer). | |
| #define | SYSTEMPARAMS_APPVER01 0x01 |
| Application firmware major version number (plain integer) - check of validity struct together with SYSTEMPARAMS_SIGN. | |
| #define | SYSTEMPARAMS_DEFAULTALTITUDE 300 |
| The default sensor altitue. | |
| #define | SYSTEMPARAMS_MINSENSORTIME 30000 |
| Minimum allowed sensor measurement interval in milliseconds (30 seconds). | |
| #define | SYSTEMPARAMS_DEFAULTSENSORTIME 60*1000*10 |
| Default sensor measurement interval in milliseconds (10 minutes). | |
| #define | SYSTEMPARAMS_MAXSENSORTIME 60*1000*60*18 |
| Maximum allowed sensor measurement interval in milliseconds (18 hour). | |
| #define | SYSTEMPARAMS_MINTIME2OFF 10000 |
| Minimum idle time in milliseconds before the device enters OFF (standby) mode. Values below ~10 s are too short because the LoRaWAN stack may still be finishing a transmission when the timer fires. | |
| #define | SYSTEMPARAMS_MINLORAWANPORT 1 |
| Minimum valid LoRaWAN application port number (port 0 is reserved by the stack). | |
| #define | SYSTEMPARAMS_DEFAULTLORAWANPORT 2 |
| Default LoRaWAN application port used for sensor uplinks. | |
| #define | SYSTEMPARAMS_MAXLORAWANPORT 223 |
| Maximum valid LoRaWAN application port number (ports 224–255 are reserved). | |
| #define | SYSTEM_APP_EUI 00,00,00,00,00,00,00,00 |
| Default LoRaWAN JoinEUI / AppEUI (8 bytes, all zeros – overridden via NFC). | |
| #define | SYSTEM_APP_KEY AB,CD,EF,01,02,03,10,11,12,05,06,07,EF,EF,EF,EF |
| Default LoRaWAN AppKey (16 bytes – overridden via NFC before deployment). | |
| #define | SYSTEM_APP_DevEUI0 0x45 |
| First byte of the 3-byte OUI prefix used in the auto-generated DevEUI. | |
| #define | SYSTEM_APP_DevEUI1 0x87 |
| Second byte of the 3-byte OUI prefix used in the auto-generated DevEUI. | |
| #define | SYSTEM_APP_DevEUI2 0xF2 |
| Third byte of the 3-byte OUI prefix used in the auto-generated DevEUI. | |
| #define | SIZE_SHT45 sizeof(tmphm_sht45_t) |
| Byte size of tmphm_sht45_t in the packed sensor record. | |
| #define | SIZE_TSL2591 sizeof(amb_tsl2591_t) |
| Byte size of amb_tsl2591_t in the packed sensor record. | |
| #define | SIZE_ILS22QS sizeof(bar_ils22qs_t) |
| Byte size of bar_ils22qs_t in the packed sensor record. | |
| #define | SIZE_BMP585 sizeof(bar_bmp585_t) |
| Byte size of bar_bmp585_t in the packed sensor record. | |
| #define | SIZE_SCD41 sizeof(scd41_t) |
| Byte size of scd41_t in the packed sensor record. | |
| #define | SIZE_SPS30 sizeof(sps30_t) |
| Byte size of sps30_t in the packed sensor record. | |
| #define | SENSORS_DATASIZE |
| Total size in bytes of one packed sensor data record. Computed as the sum of all enabled sensor struct sizes. Stored as Data_ItemSize in mems_MainBlock_t; changing the set of active sensors changes this value and requires a memory reset. The struct size contains 2bytes - represent the timeout of sensor measuring, in 0.1minutes (10min -> value 100, 0.5min value 50). | |
Enumerations | |
| enum | systemParams_Sensors_t { SYSPARAM_TEMP_HUM = 0x01 , SYSPARAM_BAR = 0x02 , SYSPARAM_AMBIENT = 0x04 , SYSPARAM_CO2 = 0x08 , SYSPARAM_PARTICULAR = 0x10 } |
| Bitmask of sensor modules that are enabled / available for data collection. Used in systemParams_t.AvailableSensors; individual bits can be ORed together. More... | |
Functions | |
| uint8_t * | systemParams_getAppDevEUI () |
| Return a pointer to the DevEUI stored in _systemParams. The DevEUI is auto-generated from the chip UID during initialisation and is read-only from the phone app's perspective. | |
| uint8_t * | systemParams_getAppEUI () |
| Return a pointer to the AppEUI (JoinEUI) stored in _systemParams. Used by the LoRaWAN stack during the OTAA join procedure. | |
| uint8_t * | systemParams_getAppKey () |
| Return a pointer to the AppKey stored in _systemParams. Used by the LoRaWAN stack to derive session keys during OTAA join. | |
| uint8_t | systemParams_CalculateCrc (uint8_t *data, uint8_t len) |
| Calculate a CRC-8 checksum (Sensirion polynomial) over a byte buffer. Used to validate sensor I2C response packets as well as the CRC field of systemParams_t. | |
| uint8_t | systemParams_CheckCRC (const systemParams_t *par) |
| Verify the CRC field of a systemParams_t structure. | |
| void | systemParams_SetCRCSystemParams () |
| Recalculate and store the CRC in _systemParams.Crc. Call this after modifying any field of _systemParams before writing the structure to the NFC EEPROM. | |
| void | systemParams_Correction () |
| 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). | |
| uint8_t | systemParams_IsSensorAvaiable (systemParams_Sensors_t sensorType) |
| Check whether a particular sensor is enabled in _systemParams.AvailableSensors. | |
| void | systemParams_Log (const char *info) |
| Log the current _systemParams fields to the UART debug output. | |
| void | sensorsBase_Init () |
| Initialization of base sensor data structure. | |
| void | sensorsBase_StartTimerToOff () |
| start timer to off the function is called from PWR_EnterStopMode - timer is started | |
| void | sensorsBase_StopTimerToOff () |
| stop timer to off 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) | |
Variables | |
| int8_t | _tryInit |
| systemParams_t | _systemParams |
| #define SENSORS_DATASIZE |
Total size in bytes of one packed sensor data record. Computed as the sum of all enabled sensor struct sizes. Stored as Data_ItemSize in mems_MainBlock_t; changing the set of active sensors changes this value and requires a memory reset. The struct size contains 2bytes - represent the timeout of sensor measuring, in 0.1minutes (10min -> value 100, 0.5min value 50).
Definition at line 329 of file mysensors_base.h.
Referenced by sensors_WriteFromBckToDataBlock().
| #define SYSTEM_APP_DevEUI0 0x45 |
First byte of the 3-byte OUI prefix used in the auto-generated DevEUI.
Definition at line 79 of file mysensors_base.h.
Referenced by getDevEuiFromHardware().
| #define SYSTEM_APP_DevEUI1 0x87 |
Second byte of the 3-byte OUI prefix used in the auto-generated DevEUI.
Definition at line 81 of file mysensors_base.h.
Referenced by getDevEuiFromHardware().
| #define SYSTEM_APP_DevEUI2 0xF2 |
Third byte of the 3-byte OUI prefix used in the auto-generated DevEUI.
Definition at line 83 of file mysensors_base.h.
Referenced by getDevEuiFromHardware().
| #define SYSTEM_APP_EUI 00,00,00,00,00,00,00,00 |
Default LoRaWAN JoinEUI / AppEUI (8 bytes, all zeros – overridden via NFC).
Definition at line 73 of file mysensors_base.h.
| #define SYSTEM_APP_KEY AB,CD,EF,01,02,03,10,11,12,05,06,07,EF,EF,EF,EF |
Default LoRaWAN AppKey (16 bytes – overridden via NFC before deployment).
Definition at line 76 of file mysensors_base.h.
| #define SYSTEMPARAMS_APPVER00 0x01 |
Application firmware minor version number (plain integer).
Definition at line 37 of file mysensors_base.h.
| #define SYSTEMPARAMS_APPVER01 0x01 |
Application firmware major version number (plain integer) - check of validity struct together with SYSTEMPARAMS_SIGN.
Definition at line 40 of file mysensors_base.h.
Referenced by nfc_ReadSystemParamsToBck().
| #define SYSTEMPARAMS_DEFAULTALTITUDE 300 |
The default sensor altitue.
Definition at line 43 of file mysensors_base.h.
| #define SYSTEMPARAMS_DEFAULTLORAWANPORT 2 |
Default LoRaWAN application port used for sensor uplinks.
Definition at line 66 of file mysensors_base.h.
| #define SYSTEMPARAMS_DEFAULTSENSORTIME 60*1000*10 |
Default sensor measurement interval in milliseconds (10 minutes).
Definition at line 49 of file mysensors_base.h.
| #define SYSTEMPARAMS_MAXLORAWANPORT 223 |
Maximum valid LoRaWAN application port number (ports 224–255 are reserved).
Definition at line 69 of file mysensors_base.h.
Referenced by systemParams_Correction().
| #define SYSTEMPARAMS_MAXSENSORTIME 60*1000*60*18 |
Maximum allowed sensor measurement interval in milliseconds (18 hour).
Definition at line 52 of file mysensors_base.h.
Referenced by systemParams_Correction().
| #define SYSTEMPARAMS_MINLORAWANPORT 1 |
Minimum valid LoRaWAN application port number (port 0 is reserved by the stack).
Definition at line 63 of file mysensors_base.h.
Referenced by systemParams_Correction().
| #define SYSTEMPARAMS_MINSENSORTIME 30000 |
Minimum allowed sensor measurement interval in milliseconds (30 seconds).
Definition at line 46 of file mysensors_base.h.
Referenced by systemParams_Correction().
| #define SYSTEMPARAMS_MINTIME2OFF 10000 |
Minimum idle time in milliseconds before the device enters OFF (standby) mode. Values below ~10 s are too short because the LoRaWAN stack may still be finishing a transmission when the timer fires.
Definition at line 59 of file mysensors_base.h.
Referenced by sensorsBase_StartTimerToOff(), and sensorsBase_StopTimerToOff().
| #define SYSTEMPARAMS_SIGN "MTTV" |
4-byte ASCII signature stored at offset 0 of systemParams_t to validate data integrity.
Definition at line 26 of file mysensors_base.h.
Referenced by nfc_ReadSystemParamsToBck().
| #define SYSTEMPARAMS_STRUCTVER 1 |
Version of the systemParams_t layout; increment when fields are added or reordered.
Definition at line 34 of file mysensors_base.h.
| #define SZ_SYSTEMPARAMS 90 |
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 and it doens't match, the Error_Handler() is called.
Definition at line 31 of file mysensors_base.h.
Referenced by sensorsBase_Init().
Bitmask of sensor modules that are enabled / available for data collection. Used in systemParams_t.AvailableSensors; individual bits can be ORed together.
Definition at line 109 of file mysensors_base.h.
| void sensorsBase_Init | ( | ) |
Initialization of base sensor data structure.
Definition at line 195 of file mysensors_base.c.
References Error_Handler(), systemParams_getAppDevEUI(), systemParams_SetCRCSystemParams(), SZ_SYSTEMPARAMS, and writeLog().
Referenced by main().
| void sensorsBase_StartTimerToOff | ( | ) |
start timer to off the function is called from PWR_EnterStopMode - timer is started
Definition at line 206 of file mysensors_base.c.
References _timerTick, _timerToOff, HAL_GetTick(), OnTimerToOff(), and SYSTEMPARAMS_MINTIME2OFF.
Referenced by PWR_EnterStopMode().
| void sensorsBase_StopTimerToOff | ( | ) |
stop timer to off 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)
Definition at line 214 of file mysensors_base.c.
References _timerTick, _timerToOff, HAL_GetTick(), MODEDEVICE_OFF, sensors_Retiming(), setModeDevice(), and SYSTEMPARAMS_MINTIME2OFF.
Referenced by PWR_ExitStopMode().
| uint8_t systemParams_CalculateCrc | ( | uint8_t * | data, |
| uint8_t | len ) |
Calculate a CRC-8 checksum (Sensirion polynomial) over a byte buffer. Used to validate sensor I2C response packets as well as the CRC field of systemParams_t.
| data | Pointer to the data buffer. |
| len | Number of bytes to include in the calculation. |
Definition at line 167 of file mysensors_base.c.
Referenced by getDevEuiFromHardware(), scd41_IsDataReady(), scd41_Read(), scd41_WriteWithCRC(), sps30_GetAutoCleanInterval(), sps30_On(), sps30_Read(), sps30_SetAutoCleanInterval(), systemParams_CheckCRC(), and systemParams_SetCRCSystemParams().
| uint8_t systemParams_CheckCRC | ( | const systemParams_t * | par | ) |
Verify the CRC field of a systemParams_t structure.
| par | Pointer to the systemParams_t to check. |
| 1 | – CRC is valid (structure is intact). |
| 0 | – CRC mismatch (structure is corrupt or uninitialised). |
Definition at line 189 of file mysensors_base.c.
References systemParams_t::Crc, and systemParams_CalculateCrc().
Referenced by nfc_ReadSystemParamsToBck().
| void systemParams_Correction | ( | ) |
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).
Definition at line 226 of file mysensors_base.c.
References _systemParams, CLAMP, SYSTEMPARAMS_MAXLORAWANPORT, SYSTEMPARAMS_MAXSENSORTIME, SYSTEMPARAMS_MINLORAWANPORT, and SYSTEMPARAMS_MINSENSORTIME.
Referenced by nfc_Init().
| uint8_t * systemParams_getAppDevEUI | ( | ) |
Return a pointer to the DevEUI stored in _systemParams. The DevEUI is auto-generated from the chip UID during initialisation and is read-only from the phone app's perspective.
Definition at line 140 of file mysensors_base.c.
References _systemParams, GetDevAddr(), and getDevEuiFromHardware().
Referenced by LoRaWAN_Init(), and sensorsBase_Init().
| uint8_t * systemParams_getAppEUI | ( | ) |
Return a pointer to the AppEUI (JoinEUI) stored in _systemParams. Used by the LoRaWAN stack during the OTAA join procedure.
Definition at line 154 of file mysensors_base.c.
References _systemParams.
Referenced by LoRaWAN_Init().
| uint8_t * systemParams_getAppKey | ( | ) |
Return a pointer to the AppKey stored in _systemParams. Used by the LoRaWAN stack to derive session keys during OTAA join.
Definition at line 159 of file mysensors_base.c.
References _systemParams.
Referenced by LoRaWAN_Init().
| uint8_t systemParams_IsSensorAvaiable | ( | systemParams_Sensors_t | sensorType | ) |
Check whether a particular sensor is enabled in _systemParams.AvailableSensors.
| sensorType | One of the systemParams_Sensors_t bitmask values. |
| 1 | – sensor is marked as available and should be polled. |
| 0 | – sensor is disabled in the configuration. |
Definition at line 238 of file mysensors_base.c.
References _systemParams.
Referenced by sensors_Init(), sensors_OnOff(), sensors_Read(), and sensors_Service().
| void systemParams_Log | ( | const char * | info | ) |
Log the current _systemParams fields to the UART debug output.
| info | Optional prefix string printed before the dump (e.g. "LOAD" or "SAVE"). |
Definition at line 271 of file mysensors_base.c.
References _systemParams, SYS_WR, SYS_WR_ARR, SYS_WR_STR, and writeLog().
Referenced by main().
| void systemParams_SetCRCSystemParams | ( | ) |
Recalculate and store the CRC in _systemParams.Crc. Call this after modifying any field of _systemParams before writing the structure to the NFC EEPROM.
Definition at line 184 of file mysensors_base.c.
References _systemParams, and systemParams_CalculateCrc().
Referenced by nfc_WriteSystemParams(), and sensorsBase_Init().
|
extern |
Global system parameters read from / written to the NFC tag EEPROM
Definition at line 20 of file mysensors_base.c.
Referenced by bar_bmp585_Read(), bar_ils22qs_Read(), checkResetRestart(), main(), mems_WriteToSystemParams(), myLoraWan_LastDataSend(), myloraWan_MeasureFinish(), nfc_Init(), nfc_ReadSystemParams(), nfc_WriteSystemParams(), OnLoRaWanConnected(), scd41_Init(), sensors_Retiming(), sensors_WriteFromBckToDataBlock(), sensorsSeq_Init(), systemParams_Correction(), systemParams_getAppDevEUI(), systemParams_getAppEUI(), systemParams_getAppKey(), systemParams_IsSensorAvaiable(), systemParams_Log(), systemParams_SetCRCSystemParams(), systemParams_SetLoRaWanParams(), and tasksensors_OnTimeout().
|
extern |
Flag used by xxx_Is() calls; when set to 1, the Is function attempts to (re-)initialise the sensor
Definition at line 60 of file mysensors_base.c.
Referenced by nfc_FactoryReset(), nfc_ReadSystemParams(), nfc_ReadSystemParamsToBck(), nfc_WriteSystemParams(), and sensors_Read().