先新建文件 src - iotToCloud.c inc - iotToCloud.h
Main.c
27 #include "iotToCloud.h"
72 int adc_value,light;
100-101 nbiot_config();
link_server();
107 HAL_ADC_Start(&hadc);
HAL_ADC_PollForConversion(&hadc,100);
adc_value=HAL_ADC_GetValue(&hadc);
light=(float)adc_value/4096*100;
printf("light:%d",light);
send_data_to_cloud(light);
HAL_Delay(2000);
Usart.c
31
int fputc(int ch,FILE *f)
{
HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,0xffff);
return ch;
}
void USART2_SendData(uint8_t Data)
{
HAL_UART_Transmit(&huart2,(uint8_t *)&Data,1,0xffff);
}
void USART2_SendStr(uint8_t *Data)
{
for(int i=0;Data[i]!=' ';i++){
USART2_SendData(Data[i]);
}
}
Usart.h
28-29 #include "stdio.h"
#include "string.h"
42 void USART2_SendData(uint8_t Data);
void USART2_SendStr(uint8_t *Data);
iotToCloud.c
#include "iotToCloud.h"
void nb_rest()
{
for(int i=0;i<3;i++)
{
USART2_SendStr((uint8_t *)"AT+NRB");
printf("AT+NRB");
HAL_Delay(1500);
}
}
void nbiot_config()
{
for(int i=0;i<3;i++)