Solano Todeschini
Solano Todeschini

Reputation: 1

How to decode bytes to string in Swift?

I wanted to know if somebody would help me with a technical challange: reading the Freestyle Libre sensor data in Swift. The glucose sensor for diabetic patients uses ISO 15693 protocol for communicating with other devices by vicinity.

For now, I have already established connection with the sensor using the NFC core NFCTagReaderSession class. Also, I have pulled data successfully using ReadSingleBlock function. The device sends back 8 bytes in a Data object and is not UTF8 encoded... so I am having problems to decode those response bytes.

I've seen some people decoding sensor data in C (arduino language) and Java, but conversion to Swift seems not to be straightforward.

I would really appreciate if someone could help me :)

For now, the reading function looks like this:

            case .iso15693(let tag):
            // Read one block of data
            tag.readSingleBlock(requestFlags: .highDataRate, blockNumber: 0, resultHandler: { result in
                switch result {
                case .success(let str):
                    print(str)
                case .failure(let error):
                    print(error)
                }
                })

And response from sensor looks like this:

Response from sensor (reading single block)

Upvotes: 0

Views: 380

Answers (0)

Related Questions