LoRa-BLE-Sensor
Loading...
Searching...
No Matches
Classes | Functions | Variables
sensor_data.c File Reference

This is a library to keep track of sensor data, using the sensor_reading library to collect data from the sensors. This library will also handle the data storage and retrieval. More...

#include "sensor_data.h"
#include "sensor_power.h"
#include "sensor_reading.h"
#include <stdint.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
Include dependency graph for sensor_data.c:

Classes

struct  sensor_data_config_t
 

Functions

 LOG_MODULE_REGISTER (sensor_data, LOG_LEVEL_INF)
 
int sensor_data_setup (sensor_data_t *sensor_data, enum sensor_types type, enum sensor_voltage voltage_enum)
 Setup the sensor data. If the sensor chosen has continuous power, the power will be turned on when the sensor is setup. If not the power will be turned on only when the data is read. PULSE_SENSORs use continuous power. To disable a sensor, set the type to NULL_SENSOR. This is important when using a sensor with continuous power, as it will turn off the power when the sensor is deinitialized.
 
int sensor_data_read (sensor_data_t *sensor_data, int timestamp)
 Read the sensor data, and store the data in the buffer. It adds a tinestamp to the data buffer.
 
int sensor_data_print_data (sensor_data_t *sensor_data)
 Print the sensor data from data and timestamp ring buffers. Displaying it from the oldest to newest.
 
int sensor_data_clear (sensor_data_t *sensor_data)
 Clear the sensor data.
 
int sensor_data_format_for_lorawan (sensor_data_t *sensor_data, uint8_t *data, uint8_t *data_len)
 Format the sensor data for LoRaWAN, this breaks the data into a uint8_t array.
 

Variables

sensor_reading_config_t sensor1_reading_config
 
sensor_reading_config_t sensor2_reading_config
 

Detailed Description

This is a library to keep track of sensor data, using the sensor_reading library to collect data from the sensors. This library will also handle the data storage and retrieval.

Author
Tyler Garcia
Version
0.1
Date
2025-05-14

Function Documentation

◆ sensor_data_clear()

int sensor_data_clear ( sensor_data_t sensor_data)

Clear the sensor data.

Parameters
sensor_dataThe sensor data to clear.

◆ sensor_data_format_for_lorawan()

int sensor_data_format_for_lorawan ( sensor_data_t sensor_data,
uint8_t *  data,
uint8_t *  data_len 
)

Format the sensor data for LoRaWAN, this breaks the data into a uint8_t array.

Parameters
sensor_dataThe sensor data to format.
dataThe data to format.
data_lenThe length of the data.
Returns
int 0 if successful, -1 if failed.

◆ sensor_data_print_data()

int sensor_data_print_data ( sensor_data_t sensor_data)

Print the sensor data from data and timestamp ring buffers. Displaying it from the oldest to newest.

Parameters
sensor_dataThe sensor data to print.

◆ sensor_data_read()

int sensor_data_read ( sensor_data_t sensor_data,
int  timestamp 
)

Read the sensor data, and store the data in the buffer. It adds a tinestamp to the data buffer.

Parameters
sensor_dataThe sensor data to read.
timestampThe timestamp to add to the data buffer.
Returns
int 0 if successful, -1 if failed.

◆ sensor_data_setup()

int sensor_data_setup ( sensor_data_t sensor_data,
enum sensor_types  type,
enum sensor_voltage  voltage_enum 
)

Setup the sensor data. If the sensor chosen has continuous power, the power will be turned on when the sensor is setup. If not the power will be turned on only when the data is read. PULSE_SENSORs use continuous power. To disable a sensor, set the type to NULL_SENSOR. This is important when using a sensor with continuous power, as it will turn off the power when the sensor is deinitialized.

Parameters
sensor_dataThe sensor data to setup holding the sensor id and power id.
typeThe type of sensor to setup.
voltage_enumThe voltage to use for the sensor.
Returns
int 0 if successful, -1 if failed.

Variable Documentation

◆ sensor1_reading_config

sensor_reading_config_t sensor1_reading_config
Initial value:
= {
.id = SENSOR_1,
.d1 = GPIO_DT_SPEC_GET(DT_ALIAS(sensor1d1), gpios),
.d2 = GPIO_DT_SPEC_GET(DT_ALIAS(sensor1d2), gpios),
.voltage_read = ADC_DT_SPEC_GET_BY_NAME(DT_PATH(zephyr_user), voltage_sensor1),
.current_read = ADC_DT_SPEC_GET_BY_NAME(DT_PATH(zephyr_user), current_sensor1)
}

◆ sensor2_reading_config

sensor_reading_config_t sensor2_reading_config
Initial value:
= {
.id = SENSOR_2,
.d1 = GPIO_DT_SPEC_GET(DT_ALIAS(sensor2d1), gpios),
.d2 = GPIO_DT_SPEC_GET(DT_ALIAS(sensor2d2), gpios),
.voltage_read = ADC_DT_SPEC_GET_BY_NAME(DT_PATH(zephyr_user), voltage_sensor2),
.current_read = ADC_DT_SPEC_GET_BY_NAME(DT_PATH(zephyr_user), current_sensor2)
}