├── debug_custom.json
├── debug.cfg
├── README.md
├── edited_esp_lib_files
├── BLEDescriptor.h
├── BLEAdvertising.h
├── BLEDevice.h
├── BLEDevice.cpp
└── BLEAdvertising.cpp
└── Insta_BLE.ino
/debug_custom.json:
--------------------------------------------------------------------------------
1 | {
2 | "name":"Arduino on ESP32",
3 | "toolchainPrefix":"xtensa-esp32-elf",
4 | "svdFile":"esp32.svd",
5 | "request":"attach",
6 | "postAttachCommands":[
7 | "set remote hardware-watchpoint-limit 2",
8 | "monitor reset halt",
9 | "monitor gdb_sync",
10 | "thb setup",
11 | "c"
12 | ],
13 | "overrideRestartCommands":[
14 | "monitor reset halt",
15 | "monitor gdb_sync",
16 | "thb setup",
17 | "c"
18 | ]
19 | }
--------------------------------------------------------------------------------
/debug.cfg:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: GPL-2.0-or-later
2 | #
3 | # Example OpenOCD configuration file for ESP32-WROVER-KIT board.
4 | #
5 | # For example, OpenOCD can be started for ESP32 debugging on
6 | #
7 | # openocd -f board/esp32-wrover-kit-3.3v.cfg
8 | #
9 |
10 | # Source the JTAG interface configuration file
11 | source [find interface/ftdi/esp32_devkitj_v1.cfg]
12 | set ESP32_FLASH_VOLTAGE 3.3
13 | # Source the ESP32 configuration file
14 | source [find target/esp32.cfg]
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Insta360 BLE ESP32
2 |
3 | ## General Information
4 | Repository that demonstrates how Insta360 X3 and RS 1-inch can be controlled via an ESP32.
5 |
6 | ## Edited ESP32 Library Files
7 | The repository also included the edited BLEDevice source and header files that include the modified manufacturing data advertisement.
8 |
9 | ## Camera-specific Information
10 |
11 | manuf_data[14]-manuf_data[19] found in powerOnPrevConnectedCameras() are specific to cameras and can be found on any specific Insta360 camera by going to settings->Camera Info.
12 |
--------------------------------------------------------------------------------
/edited_esp_lib_files/BLEDescriptor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * BLEDescriptor.h
3 | *
4 | * Created on: Jun 22, 2017
5 | * Author: kolban
6 | */
7 |
8 | #ifndef COMPONENTS_CPP_UTILS_BLEDESCRIPTOR_H_
9 | #define COMPONENTS_CPP_UTILS_BLEDESCRIPTOR_H_
10 | #include "sdkconfig.h"
11 | #if defined(CONFIG_BLUEDROID_ENABLED)
12 | #include
13 | #include "BLEUUID.h"
14 | #include "BLECharacteristic.h"
15 | #include
16 | #include "RTOS.h"
17 |
18 | class BLEService;
19 | class BLECharacteristic;
20 | class BLEDescriptorCallbacks;
21 |
22 | /**
23 | * @brief A model of a %BLE descriptor.
24 | */
25 | class BLEDescriptor {
26 | public:
27 | BLEDescriptor(const char* uuid, uint16_t max_len = 100);
28 | BLEDescriptor(BLEUUID uuid, uint16_t max_len = 100);
29 | virtual ~BLEDescriptor();
30 |
31 | uint16_t getHandle(); // Get the handle of the descriptor.
32 | size_t getLength(); // Get the length of the value of the descriptor.
33 | BLEUUID getUUID(); // Get the UUID of the descriptor.
34 | uint8_t* getValue(); // Get a pointer to the value of the descriptor.
35 | void handleGATTServerEvent(
36 | esp_gatts_cb_event_t event,
37 | esp_gatt_if_t gatts_if,
38 | esp_ble_gatts_cb_param_t* param);
39 |
40 | void setAccessPermissions(esp_gatt_perm_t perm); // Set the permissions of the descriptor.
41 | void setCallbacks(BLEDescriptorCallbacks* pCallbacks); // Set callbacks to be invoked for the descriptor.
42 | void setValue(uint8_t* data, size_t size); // Set the value of the descriptor as a pointer to data.
43 | void setValue(std::string value); // Set the value of the descriptor as a data buffer.
44 |
45 | std::string toString(); // Convert the descriptor to a string representation.
46 |
47 | private:
48 | friend class BLEDescriptorMap;
49 | friend class BLECharacteristic;
50 | BLEUUID m_bleUUID;
51 | uint16_t m_handle;
52 | BLEDescriptorCallbacks* m_pCallback;
53 | BLECharacteristic* m_pCharacteristic;
54 | esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE;
55 | FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt");
56 | esp_attr_value_t m_value;
57 |
58 | void executeCreate(BLECharacteristic* pCharacteristic);
59 | void setHandle(uint16_t handle);
60 | }; // BLEDescriptor
61 |
62 |
63 | /**
64 | * @brief Callbacks that can be associated with a %BLE descriptors to inform of events.
65 | *
66 | * When a server application creates a %BLE descriptor, we may wish to be informed when there is either
67 | * a read or write request to the descriptors value. An application can register a
68 | * sub-classed instance of this class and will be notified when such an event happens.
69 | */
70 | class BLEDescriptorCallbacks {
71 | public:
72 | virtual ~BLEDescriptorCallbacks();
73 | virtual void onRead(BLEDescriptor* pDescriptor);
74 | virtual void onWrite(BLEDescriptor* pDescriptor);
75 | };
76 | #endif /* CONFIG_BLUEDROID_ENABLED */
77 | #endif /* COMPONENTS_CPP_UTILS_BLEDESCRIPTOR_H_ */
78 |
--------------------------------------------------------------------------------
/edited_esp_lib_files/BLEAdvertising.h:
--------------------------------------------------------------------------------
1 | /*
2 | * BLEAdvertising.h
3 | *
4 | * Created on: Jun 21, 2017
5 | * Author: kolban
6 | */
7 |
8 | #ifndef COMPONENTS_CPP_UTILS_BLEADVERTISING_H_
9 | #define COMPONENTS_CPP_UTILS_BLEADVERTISING_H_
10 | #include "sdkconfig.h"
11 | #if defined(CONFIG_BLUEDROID_ENABLED)
12 | #include
13 | #include "BLEUUID.h"
14 | #include
15 | #include "RTOS.h"
16 |
17 | /**
18 | * @brief Advertisement data set by the programmer to be published by the %BLE server.
19 | */
20 | class BLEAdvertisementData {
21 | // Only a subset of the possible BLE architected advertisement fields are currently exposed. Others will
22 | // be exposed on demand/request or as time permits.
23 | //
24 | public:
25 | void setAppearance(uint16_t appearance);
26 | void setCompleteServices(BLEUUID uuid);
27 | void setFlags(uint8_t);
28 | void setManufacturerData(std::string data);
29 | void setName(std::string name);
30 | void setPartialServices(BLEUUID uuid);
31 | void setServiceData(BLEUUID uuid, std::string data);
32 | void setShortName(std::string name);
33 | void addData(std::string data); // Add data to the payload.
34 | std::string getPayload(); // Retrieve the current advert payload.
35 |
36 | private:
37 | friend class BLEAdvertising;
38 | std::string m_payload; // The payload of the advertisement.
39 | }; // BLEAdvertisementData
40 |
41 |
42 | /**
43 | * @brief Perform and manage %BLE advertising.
44 | *
45 | * A %BLE server will want to perform advertising in order to make itself known to %BLE clients.
46 | */
47 | class BLEAdvertising {
48 | public:
49 | BLEAdvertising();
50 | void directed_advertisement(std::string stringAddress);
51 | void wake_advertisement(uint8_t *manuf_data);
52 | void addServiceUUID(BLEUUID serviceUUID);
53 | void addServiceUUID(const char* serviceUUID);
54 | void start();
55 | void stop();
56 | void setAppearance(uint16_t appearance);
57 | void setAdvertisementType(esp_ble_adv_type_t adv_type);
58 | void setAdvertisementChannelMap(esp_ble_adv_channel_t channel_map);
59 | void setMaxInterval(uint16_t maxinterval);
60 | void setMinInterval(uint16_t mininterval);
61 | void setAdvertisementData(BLEAdvertisementData& advertisementData);
62 | void setScanFilter(bool scanRequertWhitelistOnly, bool connectWhitelistOnly);
63 | void setScanResponseData(BLEAdvertisementData& advertisementData);
64 | void setPrivateAddress(esp_ble_addr_type_t type = BLE_ADDR_TYPE_RANDOM);
65 | void setDeviceAddress(esp_bd_addr_t addr, esp_ble_addr_type_t type = BLE_ADDR_TYPE_RANDOM);
66 |
67 | void handleGAPEvent(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param);
68 | void setMinPreferred(uint16_t);
69 | void setMaxPreferred(uint16_t);
70 | void setScanResponse(bool);
71 |
72 | private:
73 | esp_ble_adv_data_t m_advData;
74 | esp_ble_adv_data_t m_scanRespData; // Used for configuration of scan response data when m_scanResp is true
75 | esp_ble_adv_params_t m_advParams;
76 | std::vector m_serviceUUIDs;
77 | bool m_customAdvData = false; // Are we using custom advertising data?
78 | bool m_customScanResponseData = false; // Are we using custom scan response data?
79 | FreeRTOS::Semaphore m_semaphoreSetAdv = FreeRTOS::Semaphore("startAdvert");
80 | bool m_scanResp = true;
81 |
82 | };
83 |
84 | #ifdef CONFIG_BT_BLE_50_FEATURES_SUPPORTED
85 |
86 | class BLEMultiAdvertising
87 | {
88 | private:
89 | esp_ble_gap_ext_adv_params_t* params_arrays;
90 | esp_ble_gap_ext_adv_t* ext_adv;
91 | uint8_t count;
92 |
93 | public:
94 | BLEMultiAdvertising(uint8_t num = 1);
95 | ~BLEMultiAdvertising() {}
96 |
97 | bool setAdvertisingParams(uint8_t instance, const esp_ble_gap_ext_adv_params_t* params);
98 | bool setAdvertisingData(uint8_t instance, uint16_t length, const uint8_t* data);
99 | bool setScanRspData(uint8_t instance, uint16_t length, const uint8_t* data);
100 | bool start();
101 | bool start(uint8_t num, uint8_t from);
102 | void setDuration(uint8_t instance, int duration = 0, int max_events = 0);
103 | bool setInstanceAddress(uint8_t instance, esp_bd_addr_t rand_addr);
104 | bool stop(uint8_t num_adv, const uint8_t* ext_adv_inst);
105 | bool remove(uint8_t instance);
106 | bool clear();
107 | bool setPeriodicAdvertisingParams(uint8_t instance, const esp_ble_gap_periodic_adv_params_t* params);
108 | bool setPeriodicAdvertisingData(uint8_t instance, uint16_t length, const uint8_t* data);
109 | bool startPeriodicAdvertising(uint8_t instance);
110 | };
111 |
112 | #endif // CONFIG_BT_BLE_50_FEATURES_SUPPORTED
113 |
114 | #endif /* CONFIG_BLUEDROID_ENABLED */
115 | #endif /* COMPONENTS_CPP_UTILS_BLEADVERTISING_H_ */
116 |
--------------------------------------------------------------------------------
/edited_esp_lib_files/BLEDevice.h:
--------------------------------------------------------------------------------
1 | /*
2 | * BLEDevice.h
3 | *
4 | * Created on: Mar 16, 2017
5 | * Author: kolban
6 | */
7 |
8 | #ifndef MAIN_BLEDevice_H_
9 | #define MAIN_BLEDevice_H_
10 | #include "sdkconfig.h"
11 | #if defined(CONFIG_BLUEDROID_ENABLED)
12 | #include // ESP32 BLE
13 | #include // ESP32 BLE
14 | #include