76 lines
2.7 KiB
C
76 lines
2.7 KiB
C
#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);
|
||
|
||
|
||
}
|
||
|
||
|