#if (IOT_ENABLE)
-#if (1)
const char* device_name = "PXN-W GTL";
const char* http_url = "http://192.168.66.85:8080";//"http://107.23.202.137:8080";//"http://192.168.66.80:8080";//http://107.23.202.137:8080
const char* http_token = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImJhZWRiZjUyLTUzMDgtNDRlOS04MWI3LTE1MmU4NGYwYzk5ZCJ9.fyxIGmmYD-pKd7VQ02DrL6FwBKVkqXoIu4iKSVMOUj8WubDvuSdbX6j8YzQw8K_t6UTRVZsRDTlO5me2KKhs7A";//"eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjRhNjBlZDdiLTExMDUtNDU5Ny1iNDBhLTg5ZDRiMzMzNTIyYSJ9.CUxkgU2F6BoxzE3HHVdXAin2OEDD1-D_iI0zh7VWTnlNsjsHHulvZVMq2hQLXF4cAQIJpLWwiMZJQO6Bvy9vwg";
const uint16_t mcu_vid = 0x36E6;
const uint16_t mcu_pid = 0xA00B;
-#endif
+
#endif
void Main_Loop_Task(void *pvParameters)
ESP_LOGI(MAIN_TAG, "1 second periodic timer started");
#if (IOT_ENABLE)
- if(common_storage.net_info.wifi_info_flag == 1 && common_storage.net_info.serial_number_flag == 1 && common_storage.net_info.device_id_flag == 1 && common_storage.ssl_cert[0].length != 0 && common_storage.ssl_cert[1].length != 0 && common_storage.ssl_cert[2].length != 0)
+ if(common_storage.net_info.wifi_info_flag == 1 && common_storage.net_info.serial_number_flag == 1 && common_storage.ssl_cert[0].length != 0 && common_storage.ssl_cert[1].length != 0 && common_storage.ssl_cert[2].length != 0)
{
Wifi_Queue_Send(0, 0x03, 0);
}
+ common_setting.mcu_info.vid = mcu_vid;
+ common_setting.mcu_info.pid = mcu_pid;
+ common_setting.mcu_info.fw_version = 0x0001;
+ common_setting.mcu_info.build_version = 0x0001;
+ memcpy(common_setting.mcu_info.product_name, device_name, strlen(device_name));
+ common_setting.mcu_info.product_name_len = strlen(device_name);
+ common_setting.mcu_info_got_flag = 1;
#if (USER_TEST_ENABLE)
// BLE Test
common_setting.mcu_info.vid = mcu_vid;
memcpy(common_setting.mcu_info.product_name, device_name, strlen(device_name));
common_setting.mcu_info.product_name_len = strlen(device_name);
common_setting.mcu_info_got_flag = 1;
+ common_setting.net_pairing_info.serial_number_flag =1;//等同于device_id
// Ble_Queue_Send(0xFF, 0x01);
- xEventGroupSetBits(ble_event_group, BLE_ON_BIT);
+ // xEventGroupSetBits(ble_event_group, BLE_ON_BIT);
memset(common_setting.net_pairing_info.http_url, 0x00, sizeof(common_setting.net_pairing_info.http_url));
memset(common_setting.net_pairing_info.http_token, 0x00, sizeof(common_setting.net_pairing_info.http_token));
memcpy(common_setting.wifi_status.cur_pwd, wifi_pwd, strlen(wifi_pwd));
common_setting.wifi_status.cur_ssid_len = strlen(wifi_ssid);
common_setting.wifi_status.cur_pwd_len = strlen(wifi_pwd);
- Wifi_Queue_Send(0, 0x02, 0);
+ // Wifi_Queue_Send(0, 0x02, 0);
#endif
#endif
for(;;)
{
if(common_setting.mcu_info_got_flag)
{
- if(common_storage.net_info.device_id_flag == 0 && common_storage.net_info.wifi_info_flag == 0 && common_setting.ble_status.ble_state == 0)
+ if(common_storage.net_info.serial_number_flag == 0 && common_storage.net_info.wifi_info_flag == 0 && common_setting.ble_status.ble_state == 0)
{
// Ble_Queue_Send(0xFF, 0x01);
xEventGroupSetBits(ble_event_group, BLE_ON_BIT);
ESP_LOGI(BLE_TAG, "[APP] Free memory device_id_flag1 on: %" PRIu32 " bytes", esp_get_free_heap_size());
}
- else if(common_storage.net_info.device_id_flag && common_storage.net_info.wifi_info_flag && common_setting.ble_status.ble_state != 0)
+ else if(common_storage.net_info.serial_number_flag && common_storage.net_info.wifi_info_flag && common_setting.ble_status.ble_state != 0)
{
// Ble_Queue_Send(0xFF, 0xFF);
xEventGroupSetBits(ble_event_group, BLE_OFF_BIT);
/* Private variables */
static uint8_t own_addr_type = 0;
static uint8_t addr_val[6] = {0};
-uint8_t adv_vendor_data[29] = {0xFF, 0xFF, 0xE6, 0x36, 0x0B, 0xA0, 'P', 'X', 'N', '-', 'W', ' ', 'G', 'T', 'L'};
-uint8_t adv_vendor_len = 15;
+uint8_t adv_vendor_data[31] = {0};
+uint8_t adv_vendor_len = 0;
/* Private functions */
inline static void format_addr(char *addr_str, uint8_t addr[]) {
struct ble_hs_adv_fields adv_fields = {0};
struct ble_hs_adv_fields rsp_fields = {0};
struct ble_gap_adv_params adv_params = {0};
-
+ memset(&adv_fields, 0, sizeof(adv_fields));
+ memset(&rsp_fields, 0, sizeof(rsp_fields));
+ memset(&adv_params, 0, sizeof(adv_params));
/* Set advertising flags */
adv_fields.flags = BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP;
-
+ adv_vendor_len=0;
*(uint16_t*)&adv_vendor_data[0] = 0xFFFF; // BLE默认厂商字段前2字节为蓝牙联盟成员厂商ID,因此固定2个字节0xFFFF
+ adv_vendor_len+=2;
*(uint16_t*)&adv_vendor_data[2] = common_setting.mcu_info.vid;
+ adv_vendor_len+=2;
*(uint16_t*)&adv_vendor_data[4] = common_setting.mcu_info.pid;
+ adv_vendor_len=adv_vendor_len+common_setting.mcu_info.product_name_len;
memcpy(&adv_vendor_data[6], common_setting.mcu_info.product_name, common_setting.mcu_info.product_name_len);
adv_fields.mfg_data = adv_vendor_data;
+ ESP_LOGE(GAP_TAG, "advertising data,len: %d", adv_vendor_len);
+ if(adv_vendor_len > 31)
+ {
+ adv_vendor_len=31;
+ }
adv_fields.mfg_data_len = adv_vendor_len;
/* Set device name */
printf("%02x ", ctxt->om->om_data[i]);
}
printf("\n");
-
- memset(&ble_notify,0x00,sizeof(BLE_MESSAGE_T));
- if(ctxt->om->om_len <= sizeof(ble_notify.data))
+ static BLE_MESSAGE_T ble_message_temp = {0};
+ memset(&ble_message_temp,0x00,sizeof(BLE_MESSAGE_T));
+ if(ctxt->om->om_len <= sizeof(ble_message_temp.data))
{
- ble_notify.length = ctxt->om->om_len;
- memcpy(ble_notify.data, ctxt->om->om_data, ctxt->om->om_len);
+ ble_message_temp.length = ctxt->om->om_len;
+ memcpy(ble_message_temp.data, ctxt->om->om_data, ctxt->om->om_len);
// xQueueSend(ble_notify_queue_handle, &ble_message_temp, 0); // 回传测试
- xQueueSend(ble_write_queue_handle, &ble_notify, 0);
+ xQueueSend(ble_write_queue_handle, &ble_message_temp, 0);
}
+ // memset(&ble_notify,0x00,sizeof(BLE_MESSAGE_T));
+ // if(ctxt->om->om_len <= sizeof(ble_notify.data))
+ // {
+ // ble_notify.length = ctxt->om->om_len;
+ // memcpy(ble_notify.data, ctxt->om->om_data, ctxt->om->om_len);
+ // // xQueueSend(ble_notify_queue_handle, &ble_message_temp, 0); // 回传测试
+ // xQueueSend(ble_write_queue_handle, &ble_notify, 0);
+ // }
return rc;
}
goto unknown;
common_setting.net_pairing_info.serial_number[serial_number_len] = '\0';
common_setting.net_pairing_info.serial_number_length = serial_number_len;
common_setting.net_pairing_info.serial_number_flag = 1;
-
+
//真正需要存储的flash数据
memset(common_storage.net_info.serial_number, 0x00, SERIAL_NUMBER_MAX_LEN+1);
memccpy(common_storage.net_info.serial_number, str_serialNumber, 0, serial_number_len);
memset(common_storage.net_info.wifi_pwd,0,64);
memcpy(common_storage.net_info.wifi_pwd, wifi_pwd, wifi_pwd_len);
common_storage.net_info.wifi_pwd_len=wifi_pwd_len;
+ common_storage.net_info.wifi_info_flag=1;
ESP_LOG_BUFFER_CHAR(COMMON_TAG, common_setting.wifi_status.cur_ssid, wifi_ssid_len);
#define FW_HEADER_CODE_SIZE 12
#define FW_HEADER_CODE "WGTL_ESP32C2"
#define IOT_ENABLE 1
-#define USER_TEST_ENABLE 1
+#define USER_TEST_ENABLE 0
#define BLE_TEST_WIFI_CONNECT_ENABLE 1//BLE下发wifixin不需要做htttp token user_id校验
#define IS_CLOSE_BLE 0 //是否关闭蓝牙广播暂时测试不关闭 一直广播
printf("%s read common_storage failed\n",__func__);
common_storage.net_info.wifi_info_flag = 0;
common_storage.net_info.device_id_flag = 0;
+ common_storage.net_info.serial_number_flag=0;
}else{
printf("%s read serialNumber %s\n",__func__,common_storage.net_info.serial_number);