capture of error is like below
i guess two reason.
concurrency problem
trouble is happens at closure of " Dispatch.main.async"
i think when i try to save the data at structure ,
the struct golf_array maybe is not ready to save the data.
so, i think the reason, how i can initialize the struct
and do i need to use class ? rather than a struct?
Post
Replies
Boosts
Views
Activity
i find the reason
because there is a korean in the filename...
error capture
What is golfDBdata? I don't see it declared in the code you showed. I assume it's an array. How many elements does it have?
=> testDBdata is golfDBdata
What is numDB? What is its value?
numDB is initialized as 1.
The error message is telling you that the value of numDB is greater than or equal to the number of elements in golfDBdata.
Another potential problem you have is you are running the code asynchronously. You may be trying to access data before it's been fetched.
=> this may be right guess.
so, i think, "DispatchQueue.main.async " is related with this error.
=> self.golfDBdata isn't initialized yet,
someone advised me that i need to initialize golfDBdata at class initializer or at
property intializer.
=> some book says that it is not recommanded that using Array item in DispatchQueue.
var id = UUID()
@Published var output = "Disconnected"
@Published var connected = false
@Published var databasePath = String()
enum itemType : Int{
case angle = 1
case degree = 2
case grip1 = 3
case grip2 = 4
}
struct test_Array: Identifiable {
var id = UUID()
var time: String
var swingNum : Int
var dataSeqInSwing: Int
var timeStampInSeq: Double
var itemType: Int
var value: Double
}
@Published var golfDBdata = [test_Array] ()
.....
private var centralManager: CBCentralManager?
func connectCalculator() {
output = "Connecting..."
centralQueue = DispatchQueue(label: "test.discovery")
centralManager = CBCentralManager(delegate: self, queue: centralQueue)
}
....
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
.....
if characteristic.uuid == outputCharUUID, var data = characteristic.value {
.....
DispatchQueue.main.async() {
for index in tupleSets {
strItemSets = index.components(separatedBy: ",")
.......
.......
var countItem = 0
var numDB = 1
var itemN = 1
for indexStr in strItemSets {
self.golfDBdata[numDB].dataSeqInSwing = countItem. <= Error
self.golfDBdata[numDB].itemType = itemN
self.golfDBdata[numDB].value = Double(strItemSets[itemN]) ?? 0.0
he told me that i don't need to make MFi and External Accessory Framework coding
because WWDC 2019 article....
https://developer.apple.com/documentation/corebluetooth/using_core_bluetooth_classic
https://developer.apple.com/videos/play/wwdc2019/901
he said that i need to make ESP32 : GATT Server over Bluetooth classic (BR/EDR) using BTStack and
make IOS app : GATT Client over Bluetooth Classic(BR/EDR)
but he worry that ESp32 code can't communicate with android phone.
he said that he succeeded communication between ESP32 and iphone with Bluetooth class.
i appreciate your concern and answers. thank you very much. ^^
i found this site by chance,
https://www.youtube.com/shorts/DAGbr4jFME8
https://bluekitchen-gmbh.com/btstack/#quick_start/
Now i am studying article of this site
esp32 module using bluetooth_classic can find and connect with MacBook M2 Pro 2023
but iphone mini 13 can't connect with this esp32 module.
how can Macbook m2 pro 2023 find and connect with esp32 ?
just like macbook m2 pro , i want esp32 to communicate with iphone mini 13 just like macbook m2 pro.
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
bool isconnected = false;
void Bt_Status (esp_spp_cb_event_t event, esp_spp_cb_param_t *param) {
if (event == ESP_SPP_SRV_OPEN_EVT) {
Serial.println ("Bluetooth: Connected");
isconnected = true;
} else if (event == ESP_SPP_CLOSE_EVT ) {
Serial.println ("Bluetooth: Disconnected");
isconnected = false;
}
}
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.print("\n");
Serial.println("dbg> ESP32 Test program. Start ...");
SerialBT.register_callback (Bt_Status);
Serial.println("The device started, now you can pair it with bluetooth!");
if(!SerialBT.begin("ESP32")){
Serial.println("An error occurred initializing Bluetooth");
}else{
Serial.println("Bluetooth initialized. Bluetooth Started!");
Serial.println("Bluetooth device name(ESP32), Ready to pair...");
}
}
void loop() {
if (Serial.available()){
char command = Serial.read();
Serial.print("Recived command : "); Serial.print(command); Serial.print(", ");
if(command == '3'){
Serial.println("REQ#3:");
cmd_tx_result_data1(); //test1: make string & TX data: swing raw data, bluetooth
} else{
Serial.println("Wrong command(3)");
Serial.println("Usage: ");
Serial.println(" REQ#3: make string & TX data");
}
}
}
void cmd_tx_result_data1() {
String tx_data1 = "here is some format code";
if (isconnected) {
Serial.print("dbg> tx_data1 = "); Serial.println(tx_data1);
SerialBT.print(tx_data1);
} else {
Serial.println ("dbg> Bluetooth: Client Not Connected");
}
}