L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
mylora_process.c File Reference
#include "mylora_process.h"
#include "main.h"
#include "rtc.h"
#include "mysensors.h"
#include "mysensors_base.h"
#include "sys_app.h"
#include "stm32_seq.h"
#include "lora_app.h"
#include "mymems.h"
#include "CayenneLpp.h"
#include "LoRaMac.h"
#include <stdio.h>
Include dependency graph for mylora_process.c:

Go to the source code of this file.

Functions

static uint8_t myLoRaWAN_GetMaxPayloadSize (void)
 Get the maximum application payload size for the current data rate. Returns 0 if the query fails or channel is not available.
static void myLoraWan_Reconnect ()
static void myLoraWan_StartReconnect ()
static LmHandlerErrorStatus_t LoRaWAN_SendConfirmedData (uint8_t *data, uint8_t dataSize, uint8_t port)
 Send confirmed data to LoRaWAN network.
static uint8_t myloraWan_PrepareSendingBuffer (const mems_DataBlock_t *data, uint8_t reset, uint8_t maxSize)
 the preparing _currentSendingDataBuffer/_currentSendingDataSz from CayennelLpp to send data to LoRaWan gateway
static void myloraWan_MeasureFinish ()
 the measure has been finished, sensor data save to memory or local buffer, if no memory is exist or is not storing set _currentSendingDataBuffer - contains data _currentSendingDataSz - size of data in _currentSendingDataBuffer after measure is started myLoraWan_LastDataSend
static void myLoraWan_LastDataSend ()
 take data from LIFO - last data and send. Cannot be nested only if is LoRa connected
void GetTimeDate ()
 Filled up _currentTime & _currentDate.
void OnLoRaWanConnected (void)
 Called after LoRaWAN successfully connects to the server.
void OnTimeSynchronized (void)
 Called after date/time has been synchronized from LoRaWAN.
void OnLoRaWANRxData (LmHandlerAppData_t *appData, LmHandlerRxParams_t *params)
 Handle received downlink data from LoRaWAN server.
void OnLoRaWANTxData (LmHandlerTxParams_t *params)
 Handle transmission event callback.
void myloraWan_Init (uint32_t myloraWanAppBit)
 initialization of myloraWan process, sequencer

Variables

static struct tm _localTime = {}
static uint32_t _myloraWanAppBit = 0
static uint8_t _connectedCount = 0
static uint8_t _isDataSending = 0
static uint8_t _isConnected = 0
static uint8_t _currentSendingDataBuffer [256]
static uint8_t _currentSendingDataSz = 0
static uint8_t _fromEndInx = 0

Function Documentation

◆ GetTimeDate()

void GetTimeDate ( )

Filled up _currentTime & _currentDate.

Definition at line 291 of file mylora_process.c.

References _localTime.

Referenced by main(), and OnTimeSynchronized().

Here is the caller graph for this function:

◆ LoRaWAN_SendConfirmedData()

LmHandlerErrorStatus_t LoRaWAN_SendConfirmedData ( uint8_t * data,
uint8_t dataSize,
uint8_t port )
static

Send confirmed data to LoRaWAN network.

This function sends data that requires acknowledgment from the server. The server must respond with a downlink acknowledgment. This is useful for critical data that must be verified as received.

Parameters
dataPointer to the data buffer to send
dataSizeSize of the data in bytes (max 242 bytes)
portLoRaWAN application port (typically 2)
Returns
LmHandlerErrorStatus_t Status of the send operation
  • LORAMAC_HANDLER_SUCCESS: Data queued for transmission with confirmation
  • LORAMAC_HANDLER_ERROR: Failed to queue data
  • LORAMAC_HANDLER_BUSY_ERROR: MAC layer is busy
  • LORAMAC_HANDLER_NO_NETWORK_JOINED: Not connected to network

Definition at line 91 of file mylora_process.c.

References myLoraWan_StartReconnect(), and writeLog().

Referenced by myLoraWan_LastDataSend().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ myLoRaWAN_GetMaxPayloadSize()

uint8_t myLoRaWAN_GetMaxPayloadSize ( void )
static

Get the maximum application payload size for the current data rate. Returns 0 if the query fails or channel is not available.

Definition at line 37 of file mylora_process.c.

Referenced by myLoraWan_LastDataSend().

Here is the caller graph for this function:

◆ myloraWan_Init()

void myloraWan_Init ( uint32_t myloraWanAppBit)

initialization of myloraWan process, sequencer

Definition at line 474 of file mylora_process.c.

References _myloraWanAppBit, myLoraWan_LastDataSend(), myloraWan_MeasureFinish(), and myLoraWan_Reconnect().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ myLoraWan_LastDataSend()

void myLoraWan_LastDataSend ( )
static

take data from LIFO - last data and send. Cannot be nested only if is LoRa connected

Definition at line 204 of file mylora_process.c.

References _currentSendingDataBuffer, _currentSendingDataSz, _fromEndInx, _isConnected, _isDataSending, _memsMainBlock, _systemParams, CayenneLppMaxBuffer(), LoRaWAN_SendConfirmedData(), mems_GetLastData(), myLoRaWAN_GetMaxPayloadSize(), myloraWan_PrepareSendingBuffer(), and writeLog().

Referenced by myloraWan_Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ myloraWan_MeasureFinish()

void myloraWan_MeasureFinish ( )
static

the measure has been finished, sensor data save to memory or local buffer, if no memory is exist or is not storing set _currentSendingDataBuffer - contains data _currentSendingDataSz - size of data in _currentSendingDataBuffer after measure is started myLoraWan_LastDataSend

Definition at line 167 of file mylora_process.c.

References _memsMainBlock, _myloraWanAppBit, _systemParams, CFG_SEQ_Prio_0, mems_AddData(), MEMS_DATATYPE_SENSOR, mems_InicBuffer(), myloraWan_PrepareSendingBuffer(), sensors_CopyToBck(), sensors_WriteFromBckToDataBlock(), and writeLog().

Referenced by myloraWan_Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ myloraWan_PrepareSendingBuffer()

uint8_t myloraWan_PrepareSendingBuffer ( const mems_DataBlock_t * data,
uint8_t reset,
uint8_t maxSize )
static

the preparing _currentSendingDataBuffer/_currentSendingDataSz from CayennelLpp to send data to LoRaWan gateway

Parameters
data- memory data block, sensors measured values
reset- the sending buffer is reset or not(adding for _systemParams.SendInOnePacket == 1)
maxSize- the max size of payload for current datarate, 0 - no buffer is checked

Definition at line 143 of file mylora_process.c.

References _currentSendingDataBuffer, _currentSendingDataSz, sensors_CayennelFromBckData(), and sensors_ReadToBckFromDataBlock().

Referenced by myLoraWan_LastDataSend(), and myloraWan_MeasureFinish().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ myLoraWan_Reconnect()

void myLoraWan_Reconnect ( )
static

Definition at line 51 of file mylora_process.c.

References _isConnected, LORAWAN_DEFAULT_ACTIVATION_TYPE, and writeLog().

Referenced by myloraWan_Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ myLoraWan_StartReconnect()

void myLoraWan_StartReconnect ( )
static

Definition at line 65 of file mylora_process.c.

References _connectedCount, _myloraWanAppBit, CFG_SEQ_Prio_0, and writeLog().

Referenced by LoRaWAN_SendConfirmedData(), and OnLoRaWANTxData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnLoRaWanConnected()

void OnLoRaWanConnected ( void )

Called after LoRaWAN successfully connects to the server.

This function is called when the LoRaWAN join process completes successfully. It performs time synchronization with the LoRaWAN server by requesting the device time, which updates the RTC with the server's time.

Definition at line 304 of file mylora_process.c.

References _connectedCount, _isConnected, _myloraWanAppBit, _systemParams, CFG_SEQ_Prio_0, and writeLog().

Referenced by OnJoinRequest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnLoRaWANRxData()

void OnLoRaWANRxData ( LmHandlerAppData_t * appData,
LmHandlerRxParams_t * params )

Handle received downlink data from LoRaWAN server.

This callback function is triggered when the device receives data from the LoRaWAN server. This can be a response to a confirmed uplink or an application-level downlink message.

Parameters
appDataReceived application data including buffer and port
paramsReceive parameters including RSSI, SNR, and downlink counter

Definition at line 355 of file mylora_process.c.

References writeLog().

Referenced by OnRxData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnLoRaWANTxData()

void OnLoRaWANTxData ( LmHandlerTxParams_t * params)

Handle transmission event callback.

This callback is triggered after a transmission attempt, whether successful or not. It provides information about whether an ACK was received for confirmed messages.

Parameters
paramsTransmission parameters including status and ACK received flag

Definition at line 431 of file mylora_process.c.

References _currentSendingDataSz, _fromEndInx, _isConnected, _isDataSending, _myloraWanAppBit, CFG_SEQ_Prio_0, mems_RemoveLastData(), myLoraWan_StartReconnect(), and writeLog().

Referenced by OnTxData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnTimeSynchronized()

void OnTimeSynchronized ( void )

Called after date/time has been synchronized from LoRaWAN.

This function is called when the device receives a time synchronization response (DeviceTimeAns) from the LoRaWAN server. The RTC has already been updated with the server's time when this function is called.

Add your custom code here to perform actions after time synchronization, such as updating time-dependent schedules, logging the sync event, or triggering time-based operations.

Definition at line 338 of file mylora_process.c.

References _localTime, GetTimeDate(), and writeLog().

Referenced by OnSysTimeUpdate().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _connectedCount

uint8_t _connectedCount = 0
static

Definition at line 26 of file mylora_process.c.

Referenced by myLoraWan_StartReconnect(), and OnLoRaWanConnected().

◆ _currentSendingDataBuffer

uint8_t _currentSendingDataBuffer[256]
static

Definition at line 29 of file mylora_process.c.

Referenced by myLoraWan_LastDataSend(), and myloraWan_PrepareSendingBuffer().

◆ _currentSendingDataSz

uint8_t _currentSendingDataSz = 0
static

◆ _fromEndInx

uint8_t _fromEndInx = 0
static

Definition at line 31 of file mylora_process.c.

Referenced by myLoraWan_LastDataSend(), and OnLoRaWANTxData().

◆ _isConnected

uint8_t _isConnected = 0
static

◆ _isDataSending

uint8_t _isDataSending = 0
static

Definition at line 27 of file mylora_process.c.

Referenced by myLoraWan_LastDataSend(), and OnLoRaWANTxData().

◆ _localTime

struct tm _localTime = {}
static

Definition at line 24 of file mylora_process.c.

Referenced by GetTimeDate(), and OnTimeSynchronized().

◆ _myloraWanAppBit

uint32_t _myloraWanAppBit = 0
static