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 "nfc.h"
#include "i2c.h"
#include "adc_if.h"
#include <stdio.h>
Include dependency graph for mylora_process.c:

Go to the source code of this file.

Macros

#define MAX_NOACKREPEATCOUNT   3

Functions

static void myLoraWan_ResetDataDefault ()
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 ()
 Reconnect to LoRa gateway. In case is measure data are queued, the myloraWan_MeasureFinish is called via sequencer to process current measure data.
static void myLoraWan_StartReconnect ()
 StartReconnect - processing of myLoraWan_Reconnect via sequencer in case ConnectedCount is not falled on 0.
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, SysTime_t prevMeasureTime)
 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(in case if no memory is exist or is not storing set)
static void myLoraWan_LastDataSend ()
 take data from LIFO - last data and send. Cannot be nested only if is LoRa connected
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 (uint8_t myloraWanAppBit)
 initialization of myloraWan process, sequencer

Variables

struct { 
   uint8_t   MyloraWanAppBit:4 
   uint8_t   ConnectedCount:5 
   uint8_t   NoAckRepeatCount:4 
   uint8_t   IsDataSending:1 
   uint8_t   IsMeasureQueued:1 
   uint8_t   IsConnected:1 
   uint8_t   CurrentSendingDataBuffer [256] 
   uint8_t   CurrentSendingDataSz 
   int8_t   FromEndInx:5 
   uint8_t   AckFromServer:1 
   loraWanPort_t   LoraWanPort 
   uint16_t   DataSendSz 
   uint16_t   DataSendInx 
   const uint8_t *   DataSendBuffer 
_ = {}
 anonymous global struct for saving of current mylorawan data flow

Macro Definition Documentation

◆ MAX_NOACKREPEATCOUNT

#define MAX_NOACKREPEATCOUNT   3

Definition at line 24 of file mylora_process.c.

Referenced by OnLoRaWanConnected(), and OnLoRaWANTxData().

Function Documentation

◆ 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 118 of file mylora_process.c.

References _, 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 60 of file mylora_process.c.

Referenced by myLoraWan_LastDataSend().

Here is the caller graph for this function:

◆ myloraWan_Init()

void myloraWan_Init ( uint8_t myloraWanAppBit)

initialization of myloraWan process, sequencer

Parameters
myloraWanAppBitthe bit for sequencer - this value, +2

Definition at line 646 of file mylora_process.c.

References _, 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 278 of file mylora_process.c.

References _, _memsMainBlock, _systemParams, CayenneLppMaxBuffer(), CFG_SEQ_Prio_0, LoRaWAN_SendConfirmedData(), mems_GetLastData(), myLoRaWAN_GetMaxPayloadSize(), myloraWan_PrepareSendingBuffer(), sensors_GetTimeFromBlock(), SYS_GetBatteryLevel(), SYSTEMPARAMS_BATTMINWORK, 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(in case if no memory is exist or is not storing set)

_currentSendingDataBuffer - contains data
_currentSendingDataSz - size of data in _currentSendingDataBuffer

the task myLoraWan_LastDataSend is started for start of sending data LIFO direction

Definition at line 203 of file mylora_process.c.

References _, _memsMainBlock, _systemParams, CFG_SEQ_Prio_0, measureDataNFC_t::Data, hi2c2, mems_AddData(), MEMS_DATATYPE_SENSOR, mems_InicBuffer(), myloraWan_PrepareSendingBuffer(), nfc_WriteMeasureData(), sensors_CopyToBck(), sensors_GetTimeFromBlock(), sensors_WriteFromBckToDataBlock(), measureDataNFC_t::UTCMeasureTime, 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,
SysTime_t prevMeasureTime )
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
prevMeasureTime- the time of previous block or 0, if time is unknown or is 1st
Return values
1- data stored in _currentSendingDataBuffer for send
0- not stored, the maximum buffer has been reached

Definition at line 177 of file mylora_process.c.

References _, 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

Reconnect to LoRa gateway. In case is measure data are queued, the myloraWan_MeasureFinish is called via sequencer to process current measure data.

Definition at line 71 of file mylora_process.c.

References _, CFG_SEQ_Prio_0, 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_ResetDataDefault()

void myLoraWan_ResetDataDefault ( )
static

Definition at line 49 of file mylora_process.c.

References _, and _systemParams.

Referenced by OnLoRaWanConnected(), and OnLoRaWANTxData().

Here is the caller graph for this function:

◆ myLoraWan_StartReconnect()

void myLoraWan_StartReconnect ( )
static

StartReconnect - processing of myLoraWan_Reconnect via sequencer in case ConnectedCount is not falled on 0.

Definition at line 92 of file mylora_process.c.

References _, CFG_SEQ_Prio_0, and writeLog().

Referenced by 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 416 of file mylora_process.c.

References _, _systemParams, CFG_SEQ_Prio_0, MAX_NOACKREPEATCOUNT, myLoraWan_ResetDataDefault(), 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 477 of file mylora_process.c.

References _, _systemParams, _systemParamsBck, CFG_SEQ_Prio_0, LORAWANPORT_CONFIG_GET, LORAWANPORT_CONFIG_GET_LAST, LORAWANPORT_CONFIG_SET_PART, mems_RemoveLastData(), systemParams_CheckCRC(), systemParams_SetCRCSystemParams(), systemParams_SetFromPart(), and 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 597 of file mylora_process.c.

References _, CFG_SEQ_Prio_0, MAX_NOACKREPEATCOUNT, myLoraWan_ResetDataDefault(), 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 452 of file mylora_process.c.

References systemParams_CorrectSystemTime(), and writeLog().

Referenced by OnSysTimeUpdate().

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

Variable Documentation

◆ [struct]

struct { ... } _

anonymous global struct for saving of current mylorawan data flow

◆ AckFromServer

uint8_t AckFromServer

the ACK from server came, data can be processed

Definition at line 41 of file mylora_process.c.

◆ ConnectedCount

uint8_t ConnectedCount

the connection counter for repeating reconnect after NoAckRepeatCount falled on 0 - max 32, _systemParams.LoRaRepeatTryConnect

Definition at line 33 of file mylora_process.c.

◆ CurrentSendingDataBuffer

uint8_t CurrentSendingDataBuffer[256]

buffer for sending data - max 222, with reserve

Definition at line 38 of file mylora_process.c.

◆ CurrentSendingDataSz

uint8_t CurrentSendingDataSz

the count of data in buffer

Definition at line 39 of file mylora_process.c.

◆ DataSendBuffer

const uint8_t* DataSendBuffer

pointer to data for send - if not null, this buffer is processed

Definition at line 46 of file mylora_process.c.

◆ DataSendInx

uint16_t DataSendInx

the index into DataSendBuffer from the context is copying

Definition at line 45 of file mylora_process.c.

◆ DataSendSz

uint16_t DataSendSz

the size of buffer to send, the last buffer is send with port LoraWanPort+1

Definition at line 44 of file mylora_process.c.

◆ FromEndInx

int8_t FromEndInx

the index from end of memory to send data in case if _systemParams.SendInOnePacket - more data in one pack

Definition at line 40 of file mylora_process.c.

◆ IsConnected

uint8_t IsConnected

the connection to gateway is ON/OFF

Definition at line 37 of file mylora_process.c.

◆ IsDataSending

uint8_t IsDataSending

data is in process of sending, the memory is blocked, until IsDataSending is ON

Definition at line 35 of file mylora_process.c.

◆ IsMeasureQueued

uint8_t IsMeasureQueued

the measure has been finished, but _IsDataSending is ON and memory is blocked, so current measurement is queued

Definition at line 36 of file mylora_process.c.

◆ LoraWanPort

loraWanPort_t LoraWanPort

the port for data sending

Definition at line 42 of file mylora_process.c.

◆ MyloraWanAppBit

uint8_t MyloraWanAppBit

Sequencer bits, CFG_SEQ_Task_MyLora, CFG_SEQ_Task_MyLoraReconect, CFG_SEQ_Task_MyLoraResend - !!! max 4 bits !!!

Definition at line 32 of file mylora_process.c.

◆ NoAckRepeatCount

uint8_t NoAckRepeatCount

the count of repeating to resend data in case if no ACK comes from gateway - max 16 - default

Definition at line 34 of file mylora_process.c.