手动配置组网

1. 配置组网 ID 号: AT+NETID666666666666 (12个数字)
2. 配置模块广播名: AT+NAME012
3. 配置短地址: AT+MADDR01 (短地址必须唯一)
4. 判断组网是否成功
AAFBFFFF313233 (16进制)
成功 都会接收到 123

程序配置组网

主机

    if(time_500ms == 1)                                        //每500ms给从机发送一次阈值
    {
        time_500ms = 0;
        u1_printf("%c%c%c%c", 0xAA, 0xFB, 0x00, 0x02);                                //向从机1发送温度、湿度和光照阈值
        u1_printf("%c%c%c%c%c%c", temp_yu/10,temp_yu%10, humi_yu/10, humi_yu%10 , light_yu/10,light_yu%10);
    HAL_Delay(50);
        u1_printf("%c%c%c%c", 0xAA, 0xFB, 0x00, 0x03);                                //向从机2发送烟雾和燃气阈值
        u1_printf("%c%c%c%c", smog_yu/10,smog_yu%10,gas_yu/10,gas_yu%10);
    }
  
    if(uart1_rx_flag == 1)                                //接收从机发送的温湿度、光照强度、烟雾和燃气
  {
    uart1_rx_flag = 0;    
        if(uart1_buf[0] == 0xAA && uart1_buf[1] == 0x02 && uart1_buf[2] == 0x06)
        {
            temp = uart1_buf[3]*10 + uart1_buf[4];
            humi = uart1_buf[5]*10 + uart1_buf[6];
            light = uart1_buf[7]*10 + uart1_buf[8];
        }
        if(uart1_buf[0] == 0xAA && uart1_buf[1] == 0x03 && uart1_buf[2] == 0x05)
        {
            smog = uart1_buf[3]*10 + uart1_buf[4];
            gas = uart1_buf[5]*10 + uart1_buf[6];
      beep_fire = uart1_buf[7];
        }
  }



//while前
 u1_printf("AT+NETID666666666666\r\n");//设置蓝牙组网ID
    HAL_Delay(500);
    u1_printf("AT+NAME012\r\n");//设置广播名
    HAL_Delay(500);
    u1_printf("AT+MADDR10\r\n");//设置短地址
    HAL_Delay(500);
    u1_printf("AT+MADDR01\r\n");//设置短地址
    HAL_Delay(500);
    u1_printf("AT+RESET\r\n");//重启模块
从机1

     u1_printf("%c%c%c%c", 0xAA, 0xFB, 0x00, 0x01); //给主机发送数据
    u1_printf("%c%c%c%c%c%c", temp/10,temp%10, humi/10,humi%10,light/10,light%10);

    if(uart1_rx_flag == 1)                                //接收主机发送的温湿度、光照强度阈值
  {
    uart1_rx_flag = 0;    

        if(uart1_buf[0] == 0xAA && uart1_buf[1] == 0x01 && uart1_buf[2] == 0x06)
        {
      temp_yu = uart1_buf[3]*10+uart1_buf[4];
      humi_yu = uart1_buf[5]*10+uart1_buf[6];
      light_yu = uart1_buf[7]*10+uart1_buf[8];
    }
  }


//while前
    u1_printf("AT+NETID666666666666\r\n");//设置组网ID
    HAL_Delay(500);
    u1_printf("AT+NAME012\r\n");//设置广播名
    HAL_Delay(500);
    u1_printf("AT+MADDR10\r\n");//设置短地址
    HAL_Delay(500);
    u1_printf("AT+MADDR02\r\n");//设置短地址
    HAL_Delay(500);
    u1_printf("AT+RESET\r\n");//重启模块
从机2

    u1_printf("%c%c%c%c", 0xAA, 0xFB, 0x00, 0x01); //给主机发送数据
        u1_printf("%c%c%c%c%c", smog/10,smog%10, gas/10, gas%10, beep_fire);


    if(uart1_rx_flag == 1)                                //接收主机发送的温湿度、土壤湿度、CO2和光照强度
  {
    uart1_rx_flag = 0;    
        if(uart1_buf[0] == 0xAA && uart1_buf[1] == 0x01 && uart1_buf[2] == 0x04)
        {
      smog_yu = uart1_buf[3]*10+uart1_buf[4];
      gas_yu = uart1_buf[5]*10+uart1_buf[6];
    }
    
  }


//while前
    u1_printf("AT+NETID666666666666\r\n");//设置组网ID
    HAL_Delay(500);
    u1_printf("AT+NAME012\r\n");//设置广播名
    HAL_Delay(500);
    u1_printf("AT+MADDR10\r\n");//设置短地址
    HAL_Delay(500);
    u1_printf("AT+MADDR03\r\n");//设置短地址
    HAL_Delay(500);
    u1_printf("AT+RESET\r\n");//重启模块

 

主题授权提示:请在后台主题设置-主题授权-激活主题的正版授权,授权购买:RiTheme官网

发表回复

后才能评论