sht30_collect.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-05-23 Administrator the first version
  9. */
  10. #include <rtthread.h>
  11. #include <board.h>
  12. #include <sht3x.h>
  13. #include "sht30_collect.h"
  14. #include <string.h>
  15. #include <stdio.h>
  16. #include "control.h"
  17. #include "hmi.h"
  18. #include "math.h"
  19. #define DBG_ENABLE
  20. #define DBG_COLOR
  21. #define DBG_TAG "control"
  22. #define DBG_LEVEL DBG_LOG
  23. #include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
  24. //温湿度
  25. #define THREAD_PRIORITY 21 //线程优先级
  26. #define THREAD_STACK_SIZE 1024 //栈大小
  27. #define THREAD_TIMESLICE 5 //时间片
  28. //电压,电流
  29. #define P_THREAD_PRIORITY 13 //线程优先级
  30. #define P_THREAD_STACK_SIZE 1024 //栈大小
  31. #define P_THREAD_TIMESCLICE 5 //时间片
  32. //ADC
  33. #define ADC_DEV_NAME "adc1" /*ADC设备名称*/
  34. #define ADC_DEV_CHANNLE_0 0 /*ADC通道*///电流
  35. #define ADC_DEV_CHANNLE_1 1 /*ADC通道*///电压
  36. #define ADC_DEV_CHANNLE_2 10 /*雨控*/
  37. #define ADC_DEV_CHANNLE_3 11 /*光控*/
  38. #define ADC_DEV_CHANNLE_4 12 /*加热仓温度*/
  39. #define ADC_DEV_CHANNLE_5 13 /*保险丝之后的电压*/
  40. #define ADC_DEV_CHANNLE_6 16 /*内部温度传感器*/
  41. #define REFER_VOLTAGE 330 /* 参考电压 3.3V,数据精度乘以100保留2位小数*/
  42. #define CONVERT_BITS (1<<12) /* 转换位数为12位 */
  43. Device_Status_typedef device_status;
  44. rt_device_t serial_485; /*串口设备句柄*/
  45. struct serial_configure uart_config_485 = RT_SERIAL_CONFIG_DEFAULT; /*初始化配置参数*/
  46. rt_uint32_t adc0_value,adc1_value,in_adc_17,adc13_value,adc16_value;
  47. rt_uint32_t adc10_rain,adc11_light,adc12_ntc;
  48. int8_t hum_value,tem_value;
  49. static rt_thread_t tid1 = RT_NULL;
  50. static rt_thread_t tid2 = RT_NULL;
  51. ADC_HandleTypeDef hadc1;
  52. /*串口初始化*/
  53. int UART_485_INIT(void)
  54. {
  55. serial_485 = rt_device_find(UART_485);
  56. /*修改串口配置参数*/
  57. uart_config_485.baud_rate = BAUD_RATE_9600; //修改波特率9600
  58. uart_config_485.data_bits = DATA_BITS_8; //数据位8
  59. uart_config_485.stop_bits = STOP_BITS_1; //停止位1
  60. uart_config_485.bufsz = 512; //缓冲区1k
  61. uart_config_485.parity = PARITY_NONE; //奇校验
  62. /* step3:控制串口设备。通过控制接口传入命令控制字,与控制参数 */
  63. rt_device_control(serial_485, RT_DEVICE_CTRL_CONFIG, &uart_config_485);
  64. /* step4:打开串口设备。以DMA接收及轮询发送模式打开串口设备 */
  65. rt_device_open(serial_485, RT_DEVICE_FLAG_INT_RX);
  66. return 0;
  67. }
  68. /* 入口函数 */
  69. static void sht30_collect_thread_entry(void *parameter)
  70. {
  71. sht3x_device_t sht3x_device;
  72. static int checklightnum = 0;
  73. static int checknightnum = 0;
  74. sht3x_device = sht3x_init("i2c1", 0x44);
  75. //此处需要短暂的延时,否则会出现连续读取失败的问题
  76. rt_thread_mdelay(150);
  77. uint8_t log_en_inr = 30; // 打印log的速度 数值越小 打印越频繁
  78. static int8_t log_en_cnt = -1;
  79. while (1)
  80. {
  81. if(sht3x_device)
  82. {
  83. if(RT_EOK == sht3x_read_singleshot(sht3x_device))
  84. {
  85. hum_value = sht3x_device->humidity;
  86. tem_value = sht3x_device->temperature;
  87. if(hum_value!=0)
  88. {
  89. rt_sprintf(device_status.humidity,"%d.%d",(int)sht3x_device->humidity, (uint)(sht3x_device->humidity * 10) % 10);
  90. rt_sprintf(device_status.tempture,"%d.%d",(int)sht3x_device->temperature, (uint)(sht3x_device->temperature * 10) % 10);
  91. }
  92. else {
  93. rt_kprintf("sht3x_read_singleshot eRR:%d",hum_value);
  94. }
  95. }
  96. else {
  97. sht3x_softreset(sht3x_device);
  98. }
  99. //// rt_kprintf("sht30 humidity : %d.%d ", (int)sht3x_device->humidity, (int)(sht3x_device->humidity * 10) % 10);
  100. //// rt_kprintf("temperature: %d.%d\n", (int)sht3x_device->temperature, (int)(sht3x_device->temperature * 10) % 10);
  101. }
  102. else
  103. {
  104. rt_kprintf("read sht3x fail.\r\n");
  105. //重新初始化
  106. sht3x_deinit(sht3x_device);
  107. sht3x_device = sht3x_init("i2c1", 0x44);
  108. rt_thread_mdelay(150);
  109. }
  110. if(Read_Light_Voltage()>500)
  111. {
  112. checklightnum++;
  113. if(checklightnum==20)
  114. {
  115. device_status.sun_status = 1;
  116. checklightnum =0;
  117. }
  118. }
  119. else {
  120. checknightnum ++;
  121. if(checknightnum==20)
  122. {
  123. device_status.sun_status = 0;
  124. checknightnum = 0;
  125. }
  126. }
  127. //温控
  128. if(atoi(device_status.tempture)>=device_status.tph||atoi(device_status.tempture)<=device_status.tpl)
  129. {
  130. device_status.temp_status = 1;
  131. }
  132. else if(atoi(device_status.tempture)>=(device_status.tpl+5)&&atoi(device_status.tempture)<=(device_status.tph-10)) {
  133. device_status.temp_status = 0;
  134. }
  135. if (chk_log_time)
  136. {
  137. LOG_I("光控计数:%d-%d",checklightnum,checknightnum);
  138. }
  139. rt_thread_mdelay(5000);
  140. }
  141. }
  142. static void Power_ReadCheck(void *parameter)
  143. {
  144. int rain_cnt = 0;
  145. int RV;
  146. uint8_t log_en_inr = 30; // 打印log的速度 数值越小 打印越频繁
  147. static int8_t log_en_cnt = -1;
  148. while(1)
  149. {
  150. sprintf(device_status.power,"%.2f",(float)Read_Real_Current()/100*2.5);
  151. if (Read_Real_Voltage()/100<12) {
  152. //关闭外设
  153. ctr_photo(OFF); //关闭相机供电
  154. ctr_led(OFF); //关闭补光灯
  155. ctr_Heat(OFF); //关闭加热
  156. ctr_Cold(OFF); //关闭制冷
  157. #if Color_EN == 0
  158. ctr_cangmen_down(OFF); //关闭下仓门输出(转盘)
  159. ctr_cangmen_up(OFF); //关闭上仓门输出(散热)
  160. #endif
  161. }
  162. if(Read_Real_Voltage()/100<21)
  163. {
  164. #if ROBOT_EN == 1
  165. ctr_led(OFF);
  166. HMI_WRITE("sleep=%d",1);
  167. #endif
  168. device_status.bat_status = 1; //欠压
  169. }
  170. else {
  171. device_status.bat_status = 0; //解除欠压
  172. ctr_router(ON); //打开路由器供电
  173. ctr_photo(ON); //打开相机供电
  174. #if ROBOT_EN == 1
  175. ctr_led(ON); //打开补光灯
  176. ctr_lamp(ON, 1); //打开镇流器输出,用于24V转12V给相机供电
  177. ctr_router(ON);
  178. HMI_WRITE("sleep=%d",0);
  179. #endif
  180. }
  181. //
  182. if(device_status.dtype==7)
  183. {
  184. //箱体温度
  185. RV = 10000 * (4096 - Read_Rain_Voltage()) / Read_Rain_Voltage();
  186. if(TempCalculate(RV, 3950, 10000)-TempCalculate(RV, 3950, 10000)>10)
  187. {
  188. LOG_E("temp value err!!!!");
  189. }
  190. else
  191. {
  192. device_status.box_temp = TempCalculate(RV, 3950, 10000);
  193. if(device_status.box_temp>160)
  194. {
  195. device_status.box_temp = 25;
  196. }
  197. }
  198. //培养仓温度
  199. RV = 10000 * (4096 - Read_Light_Voltage()) / Read_Light_Voltage();
  200. if(TempCalculate(RV, 3950, 10000)-TempCalculate(RV, 3950, 10000)>10)
  201. {
  202. LOG_E("temp value err!!!!");
  203. }
  204. else
  205. {
  206. device_status.pre_temp = TempCalculate(RV, 3950, 10000);
  207. if(device_status.pre_temp>160)
  208. {
  209. device_status.pre_temp = 25;
  210. }
  211. }
  212. }
  213. else {
  214. RV = 10000 * (4096 - Read_Ntc_Voltage()) / Read_Ntc_Voltage();
  215. if(TempCalculate(RV, 3950, 10000)-TempCalculate(RV, 3950, 10000)>10)
  216. {
  217. LOG_E("temp value err!!!!");
  218. }
  219. else {
  220. device_status.heattem = TempCalculate(RV, 3950, 10000);
  221. if(device_status.heattem>160)
  222. {
  223. device_status.heattem = 25;
  224. }
  225. }
  226. //雨控
  227. if(Read_Rain_Voltage()>1500)
  228. {
  229. device_status.rain_status = 1;
  230. ctr_lamp(OFF,1);
  231. ctr_lamp(OFF,2);
  232. ctr_lamp(OFF,3);
  233. rain_cnt = 0;
  234. }
  235. else {
  236. rain_cnt++;
  237. if (chk_log_time)
  238. {
  239. //雨控消抖,1分钟
  240. LOG_D("rain_cnt:%d-value:%d",rain_cnt,Read_Rain_Voltage());
  241. }
  242. if(rain_cnt==60&&Read_Rain_Voltage()<1500)
  243. {
  244. rain_cnt = 0;
  245. device_status.rain_status = 0;
  246. }
  247. }
  248. }
  249. #if ROBOT_EN == 0
  250. rt_sprintf(device_status.voltage,"%d.%02d",filter_voltage()/100,filter_voltage()%100);
  251. //LOG_D("voltage is:%sV",device_status.voltage);
  252. sprintf(device_status.fuse_voltage, "%d.%02d",Read_Fuse_Voltage()/100,Read_Fuse_Voltage()%100);
  253. #endif
  254. rt_thread_mdelay(10);
  255. }
  256. }
  257. /*读取电流值*/
  258. int Read_Real_Current(void)
  259. {
  260. rt_adc_device_t adc_dev; /*ADC设备句柄*/
  261. adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
  262. if (adc_dev == RT_NULL)
  263. {
  264. LOG_E("adc sample run failed! can't find %s device!", ADC_DEV_NAME);
  265. return RT_ERROR;// adc 采样值不可能为负值,返回负值表示出错
  266. }
  267. HAL_ADCEx_Calibration_Start(adc_dev->parent.user_data);
  268. rt_adc_enable(adc_dev, ADC_DEV_CHANNLE_1);
  269. //rt_adc_enable(adc_dev, 17);
  270. adc1_value = filter_Mid(rt_adc_read(adc_dev, ADC_DEV_CHANNLE_1));
  271. in_adc_17 = filter_Mid(rt_adc_read(adc_dev, 17));
  272. /* 关闭通道 */
  273. rt_adc_disable(adc_dev, ADC_DEV_CHANNLE_1);
  274. //rt_adc_disable(adc_dev, 17);
  275. //rt_kprintf("read in adc:ADC17:%d-ADC1:%d\n",in_adc_17,adc1_value);
  276. //return (int)((ADC_VOL_BASE * (adc1_value*1.0)/(in_adc_17*1.0))*100000/250.0);
  277. return (int)((ADC_VOL_BASE * (adc1_value*1.0)/(in_adc_17*1.0))*100000);
  278. //INA293B:I = Vadc / (Rsense * Gain) = 0.0952V / (0.02 * 50) = 0.0952V / 1
  279. #if INA293B2 == 1
  280. return (int)((ADC_VOL_BASE * (adc1_value*1.0)/(in_adc_17*1.0))*1000); //扩大1000倍,把A转换为mA 50*? = 250 R = 0.5欧
  281. #endif
  282. }
  283. /*
  284. * https://blog.csdn.net/loop222/article/details/120497425
  285. 采样电阻0.01 Ω
  286. 运放为INA240A2,放大倍数50
  287. 背面需分别短接A0/A2至输出
  288. C1_OUT=INA_VCC/2 + 0.01 * I * 50
  289. 如果INA_VCC=3.3V,C1_OUT=1.65 + 0.01 * I * 50,电流范围(-3.3A,3.3A)
  290. 如果INA_VCC=5.0V,C1_OUT=2.50 + 0.01 * I * 50,电流范围(-5A,5A)
  291. B相采样输入在PCB上为走线方便做了反向输入,所以放大倍数需乘以 -1(移植后的代码已经做了处理)
  292. */
  293. /*读取电压值*/
  294. int Read_Real_Voltage(void)
  295. {
  296. rt_adc_device_t adc_dev; /*ADC设备句柄*/
  297. adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
  298. if (adc_dev == RT_NULL)
  299. {
  300. rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME);
  301. return RT_ERROR;// adc 采样值不可能为负值,返回负值表示出错
  302. }
  303. HAL_ADCEx_Calibration_Start(adc_dev->parent.user_data);
  304. rt_adc_enable(adc_dev, ADC_DEV_CHANNLE_0);
  305. //adc0_value = rt_adc_read(adc_dev, ADC_DEV_CHANNLE_0);
  306. adc0_value = filter_Mid(rt_adc_read(adc_dev, ADC_DEV_CHANNLE_0));
  307. /* 关闭通道 */
  308. rt_adc_disable(adc_dev, ADC_DEV_CHANNLE_0);
  309. return (adc0_value * REFER_VOLTAGE/CONVERT_BITS*12+20);
  310. }
  311. /*读取保险丝的电压值*/
  312. int Read_Fuse_Voltage(void)
  313. {
  314. rt_adc_device_t adc_dev; /*ADC设备句柄*/
  315. adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
  316. if (adc_dev == RT_NULL)
  317. {
  318. rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME);
  319. return RT_ERROR;// adc 采样值不可能为负值,返回负值表示出错
  320. }
  321. HAL_ADCEx_Calibration_Start(adc_dev->parent.user_data);
  322. rt_adc_enable(adc_dev, ADC_DEV_CHANNLE_5);
  323. adc13_value = rt_adc_read(adc_dev, ADC_DEV_CHANNLE_5);
  324. /* 关闭通道 */
  325. rt_adc_disable(adc_dev, ADC_DEV_CHANNLE_5);
  326. return (adc13_value * REFER_VOLTAGE/CONVERT_BITS*12+8);
  327. }
  328. /*读取雨控*/
  329. int Read_Rain_Voltage(void)
  330. {
  331. rt_adc_device_t adc_dev; /*ADC设备句柄*/
  332. adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
  333. if (adc_dev == RT_NULL)
  334. {
  335. rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME);
  336. return RT_ERROR;// adc 采样值不可能为负值,返回负值表示出错
  337. }
  338. rt_adc_enable(adc_dev, ADC_DEV_CHANNLE_3);
  339. adc11_light = rt_adc_read(adc_dev,ADC_DEV_CHANNLE_3);
  340. rt_adc_disable(adc_dev, ADC_DEV_CHANNLE_3);
  341. HAL_ADCEx_Calibration_Start(adc_dev->parent.user_data);
  342. //rt_kprintf("read rain value:%d\n",adc11_light);
  343. return adc11_light;
  344. // rt_pin_mode(RAIN_PIN,PIN_MODE_INPUT);
  345. // return rt_pin_read(RAIN_PIN);
  346. }
  347. /*读取光控*/
  348. int Read_Light_Voltage(void)
  349. {
  350. rt_adc_device_t adc_dev; /*ADC设备句柄*/
  351. adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
  352. if (adc_dev == RT_NULL)
  353. {
  354. rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME);
  355. return RT_ERROR;// adc 采样值不可能为负值,返回负值表示出错
  356. }
  357. rt_adc_enable(adc_dev, ADC_DEV_CHANNLE_2);
  358. adc10_rain = rt_adc_read(adc_dev,ADC_DEV_CHANNLE_2);
  359. rt_adc_disable(adc_dev, ADC_DEV_CHANNLE_2);
  360. HAL_ADCEx_Calibration_Start(adc_dev->parent.user_data);
  361. //rt_kprintf("read light value:%d\n",adc10_rain);
  362. return adc10_rain;
  363. }
  364. //获取内部温度传感器值
  365. short Get_Temprate(void)
  366. {
  367. short result;
  368. double temperate;
  369. rt_adc_device_t adc_dev; /*ADC设备句柄*/
  370. adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
  371. if (adc_dev == RT_NULL)
  372. {
  373. rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME);
  374. return RT_ERROR;// adc 采样值不可能为负值,返回负值表示出错
  375. }
  376. HAL_ADCEx_Calibration_Start(adc_dev->parent.user_data);
  377. rt_adc_enable(adc_dev, ADC_DEV_CHANNLE_6);
  378. adc16_value = rt_adc_read(adc_dev, ADC_DEV_CHANNLE_6);
  379. /* 关闭通道 */
  380. rt_adc_disable(adc_dev, ADC_DEV_CHANNLE_6);
  381. temperate = (float)adc16_value*(3.3/4096); //电压值
  382. temperate = (1.43-temperate)/0.0043+25; //转换为温度值
  383. result = temperate*=100; //扩大100倍.
  384. return result;
  385. }
  386. /**
  387. * Rv: 热敏电阻当前阻值
  388. * B: 热敏电阻参数B值
  389. * Revise: 校正温度
  390. * BasicRx: 热敏电阻25度时电阻(标称电阻数值)
  391. * 返回: 摄氏度
  392. */
  393. int TempCalculate(float Rv,int B,int BasicRx)
  394. {
  395. float Rx;
  396. Rx = Rv * 1.0 / BasicRx;
  397. Rx = log(Rx);
  398. Rx = Rx / B;
  399. Rx = 1/(Rx+0.003354);
  400. //Rx = Rx + 0.003356;
  401. //Rx = 1 / Rx;
  402. Rx = Rx - 273.13;
  403. return (int)(Rx+0.5);
  404. }
  405. /*
  406. * 中位值平均滤波法
  407. * */
  408. unsigned int filter_Mid(int adc_return)
  409. {
  410. unsigned char count,i,j;
  411. unsigned int value_buf[N],temp=0;
  412. int sum = 0;
  413. for(count = 0;count<N;count++)
  414. {
  415. value_buf[count] = adc_return;
  416. //rt_kprintf("value_buf:%d-%d\n",value_buf[count],count);
  417. rt_thread_delay(10);
  418. }
  419. for(j=0;j<N-1;j++)
  420. {
  421. for(i=0;i<N-j-1;i++)
  422. {
  423. if(value_buf[i]>value_buf[i+1])
  424. {
  425. temp = value_buf[i];
  426. value_buf[i] = value_buf[i+1];
  427. value_buf[i+1] = temp;
  428. }
  429. }
  430. }
  431. for(count = 1;count < N - 1;count++)
  432. {
  433. sum+= value_buf[count];
  434. }
  435. return (int)(sum/(N-2));
  436. }
  437. /*
  438. 限幅消抖滤波法
  439. A、方法:
  440. 相当于“限幅滤波法”+“消抖滤波法”
  441. 先限幅,后消抖
  442. B、优点:
  443. 继承了“限幅”和“消抖”的优点
  444. 改进了“消抖滤波法”中的某些缺陷,避免将干扰值导入系统
  445. C、缺点:
  446. 对于快速变化的参数不宜
  447. */
  448. unsigned int filter_voltage(void)
  449. {
  450. uint8_t data_cnt = 0;
  451. int value = 0,new_value = 0;
  452. new_value = Read_Real_Voltage();
  453. while(value!=new_value)
  454. {
  455. data_cnt++;
  456. if(data_cnt>=N) return new_value;
  457. rt_thread_delay(10);
  458. new_value = Read_Real_Voltage();
  459. }
  460. return value;
  461. }
  462. /*读取加热仓温度*/
  463. int Read_Ntc_Voltage(void)
  464. {
  465. rt_adc_device_t adc_dev; /*ADC设备句柄*/
  466. adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
  467. if (adc_dev == RT_NULL)
  468. {
  469. rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME);
  470. return RT_ERROR;// adc 采样值不可能为负值,返回负值表示出错
  471. }
  472. rt_adc_enable(adc_dev, ADC_DEV_CHANNLE_4);
  473. adc12_ntc = filter_Mid(rt_adc_read(adc_dev,ADC_DEV_CHANNLE_4));
  474. //LOG_D("Read_Ntc_Voltage:%d",adc12_ntc);
  475. rt_adc_disable(adc_dev, ADC_DEV_CHANNLE_4);
  476. HAL_ADCEx_Calibration_Start(adc_dev->parent.user_data);
  477. return adc12_ntc;
  478. }
  479. /* 创建线程 */
  480. int sht30_collect(void)
  481. {
  482. /* 创建线程*/
  483. tid1 = rt_thread_create("sht30_collect_thread",sht30_collect_thread_entry, RT_NULL,THREAD_STACK_SIZE,THREAD_PRIORITY, THREAD_TIMESLICE);
  484. tid2 = rt_thread_create("Power Check thread", Power_ReadCheck, RT_NULL, P_THREAD_STACK_SIZE, P_THREAD_PRIORITY, P_THREAD_TIMESCLICE);
  485. /* 如果获得线程控制块,启动这个线程 */
  486. if (tid1 != RT_NULL)
  487. rt_thread_startup(tid1);
  488. if (tid2 != RT_NULL)
  489. rt_thread_startup(tid2);
  490. return 0;
  491. }
  492. //控制台打印传感器信息
  493. void Msh_DisplaySensor(void)
  494. {
  495. rt_kprintf("温度:%d\n",tem_value);
  496. rt_kprintf("湿度:%d\n",hum_value);
  497. rt_kprintf("电压:%s\n",device_status.voltage);
  498. rt_kprintf("电流:%s\n",device_status.power);
  499. }
  500. MSH_CMD_EXPORT(Msh_DisplaySensor,Msh_DisplaySensor);
  501. MSH_CMD_EXPORT(Read_Rain_Voltage,Read_Rain_Voltage);
  502. MSH_CMD_EXPORT(Read_Light_Voltage,Read_Light_Voltage);