STS_E2/AirQuality/Src/user_data_send.c

76 lines
2.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "user_data_send.h"
#include <string.h>
#include <stdio.h>
#include "main.h"
#include "lora.h"
#include "usart_user.h"
extern volatile uint8_t LORA_STATE;
/*******************************************************************************
**函数名称SendData(uint8_t *sensorData)
**功能描述:发送传感器数据
**入口参数uint8_t *sensorData 要发送的数据
**输出:无
*******************************************************************************/
void SendData(uint8_t status,uint8_t time)
{
if(LORA_STATE == LORA_JOINED)
{
char sendBuffer[64];
uint8_t length = 0;
memset(sendBuffer, 0, sizeof(sendBuffer));
length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=53,0,2,<%02x%02x\r\n", status,time);
UsartxSendDataStr(USART2, (uint8_t *)sendBuffer, length);
}
}
/*******************************************************************************
**函数名称SendData(uint8_t *sensorData)
**功能描述:发送传感器数据
**入口参数uint8_t *sensorData 要发送的数据
**输出:无
*******************************************************************************/
void SendHbData(uint8_t sensorData)
{
if(LORA_STATE == LORA_JOINED)
{
char sendBuffer[64];
uint8_t length = 0;
memset(sendBuffer, 0, sizeof(sendBuffer));
length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=219,0,1,<%02x\r\n", sensorData);
UsartxSendDataStr(USART2, (uint8_t *)sendBuffer, length);
}
}
void SendDate_Lora(SensorDataTypeDef *sensorData)
{
if(LORA_STATE == LORA_JOINED)
{
char sendBuffer[64];
uint8_t length = 0;
memset(sendBuffer, 0, sizeof(sendBuffer));
length = snprintf(sendBuffer, sizeof(sendBuffer), "AT+LRSEND=101,0,18,<%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\r\n",
sensorData->symbol,sensorData->temperature1,sensorData->temperature2,sensorData->humidity1,sensorData->humidity2,sensorData->nh31,
sensorData->nh32,sensorData->h2s1,sensorData->h2s2,sensorData->ch2o1,sensorData->ch2o2,sensorData->co21,sensorData->co22,
sensorData->tvoc,sensorData->pm251,sensorData->pm252,sensorData->pm101,sensorData->pm102, sensorData->o31,sensorData->o32);
UsartxSendDataStr(LORA_USART, (uint8_t *)sendBuffer, length);
}
// char sendBuffer[256];
// uint8_t length = 0;
// memset(sendBuffer, 0, sizeof(sendBuffer));
// length = snprintf(sendBuffer, sizeof(sendBuffer), "symbol is %d, temperature is %f, humidity is %f, nh3 is %f, h2s is %f, ch2o is %f, co2 is %d tvoc is %d, pm2.5 is %d, pm10 is %d\r\n"
// , sensorData->symbol, sensorData->temperature, sensorData->humidity, sensorData->nh3
// , sensorData->h2s,sensorData->ch2o,sensorData->co2
// ,sensorData->tvoc,sensorData->pm25,sensorData->pm10);
// UsartxSendDataStr(DEBUG_USART, (uint8_t *)sendBuffer, length);
}