当前位置:网站首页>Lora illumination sensor node data acquisition
Lora illumination sensor node data acquisition
2022-07-27 02:18:00 【Did Li fish today?】
One 、 Mission requirements
Based on the temperature and humidity sensor node code , Development Lora Photosensitive node Application , Data collection required , After receiving the command of the gateway to read the sensor , Respond the sensing data to the gateway .
(1) Modify the device address , Define sensing variables .
// Define network number and device address
#define MY_NET_ID 0xD0C2 // The Internet ID
#define MY_ADDR 0x02 // Device address
/* Global variables */
uint16_t LightLux = 200; // The illuminance collected by the light sensor , Company :lux(2) Response sending code , When string formatting output , take LightLux The sensor identification name is added .
uint8_t RspBuf[BUFFER_SIZE]= {0};
memset(RspBuf, '\0', BUFFER_SIZE);
RspBuf[0]=START_HEAD;
RspBuf[1]=CMD_READ;
RspBuf[2]=(uint8_t)(MY_NET_ID>>8);
RspBuf[3]=(uint8_t)MY_NET_ID;
RspBuf[4]=MY_ADDR;
RspBuf[5]=ACK_OK;
sprintf((char *)(RspBuf+7),"LightLux(lux):%d", LightLux);// Data fields ,sprintf in , Two “%” Indicative output “%”.ADC Pass the value after collection LightLux send out .
RspBuf[6]=strlen((const char *)(RspBuf+7))+1;// Data field length
RspBuf[6+RspBuf[6]]=CheckSum((uint8_t *)RspBuf, 6+RspBuf[6]);
Radio.Send( RspBuf, 7+RspBuf[6]);// Send response data
GpioToggle( &Led1 );// Send data switching light (3) initialization ADC:void AdcInit( Adc_t *obj, PinNames adcInput ) It's defined in adc.c in , The user can call ,board.c It defines Adc_t Adc; board.h Defined #define ADC_0 PA_0.
void PlatformInit(void)
{
// Development board platform initialization
BoardInitMcu();
BoardInitPeriph();
// Development board device initialization
OLED_Init();// LCD initialization
USART1_Init(115200);// A serial port 1 initialization
OLED_Clear();
OLED_InitView();//OLED The screen displays the initial information
printf(" Education in the new world LoRa \r\n");
//Lora Module initialization
NS_RadioInit( (uint32_t) RF_PING_PONG_FREQUENCY, (int8_t) TX_OUTPUT_POWER, (uint32_t) TX_TIMEOUT_VALUE, (uint32_t) RX_TIMEOUT_VALUE );
// Please add user initialization code below
printf("LoRa Light\r\n");
AdcInit( &Adc, ADC_0);//ADC Initialize channel 0
Tim3McuInit(1);// Timer initialization , Set timing interrupt 1ms Break once
//IWDG_PrmInit(2048);// Independent watchdog initialization , The timeout is set to 2048ms
}(4)ADC Data collection conversion report
void LoRa_GetSensorDataProcess(void)
{
const uint16_t time = 1000;
if(User0Timer_MS > time)
{
User0Timer_MS = 0;
uint16_t AdcNum,voltage;
AdcNum = AdcReadChannel( &Adc, ADC_CHANNEL_0 );//ADC precision 12 position , Reference voltage 3.3V
// stay adc.c Define read ADC0 Value channel
voltage = AdcNum*3300/(4096-1.0);// Sensor voltage value , Company :mV
LightLux = (5/2.0)*(voltage/10.0);
char StrBuf[64]={0};
memset(StrBuf, '\0', 64);
sprintf(StrBuf, " %d lux",LightLux);
OLED_ShowString(0,4,(uint8_t *)StrBuf);
}
}(5) This experiment is improved in the temperature and humidity sensor node experiment , Please refer to the following connection for details !https://blog.csdn.net/qq_41742056/article/details/125515371?spm=1001.2014.3001.5501
边栏推荐
- 第四讲—讲解GPIO_Write函数以及相关例程
- C语言——数据类型、基本数据类型的取值范围
- VLAN原理简述、具体实验配置
- 关于在VS2022或者高级版本运行环境下遇到fopen,strerror等不安全的问题
- MySQL课程2.表的各种查询
- Codeforces Round #807 (Div. 2), problem: (C) Mark and His Unfinished Essay
- ACM模式输入输出练习
- 【volatile原理】volatile原理
- JS 99 multiplication table
- 2022 open source work of the latest text generated image research (papers with code)
猜你喜欢

HCIA动态路由OSPF实验

Republishing and routing strategy of OSPF

Pseudo class of a element

关于在VS2022或者高级版本运行环境下遇到fopen,strerror等不安全的问题
![[详解C语言]一文带你玩转循环结构(for_while_do-while)](/img/d9/75053297873a5b5458514e7f557cdc.png)
[详解C语言]一文带你玩转循环结构(for_while_do-while)

Experiment of OSPF in mGRE environment

OSPF的重发布及路由策略

初识C语言(2)

微信小程序:用户微信登录流程(附:流程图+源码)

Codeforces Round #807 (Div. 2), problem: (C) Mark and His Unfinished Essay
随机推荐
Introduction to STM32 lesson 1
mgre的全连和星型拓扑实验
Golang中的错误处理
C语言——字符和字符串、算术运算符、类型转换
2022最新直播监控24小时监控(三)直播间弹幕解析
Text to image paper intensive reading ssa-gan: text to image generation with semantic spatial aware Gan
OSPF在MGRE环境下的实验
JS logical operator
Solution: various error reports and pit stepping and pit avoidance records encountered in the alchemist cultivation plan pytoch+deeplearning (I)
C语言——二维数组、指针
HCIA基础知识(1)
OSPF static experiment
机械硬盘选购指南——从选购经历谈起
CF 1333C Eugene and an array
2022 open source work of the latest text generated image research (papers with code)
JS 99 multiplication table
2022zui新抖音24小时循环值守直播监控(一)直播间开播监控
OSPF的重发布及路由策略
Lora通信应用开发
7.7 SHEIN希音笔试