Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Battery Level not being refreshed #121

Closed
blairio opened this issue Nov 11, 2021 · 3 comments · Fixed by #134
Closed

Battery Level not being refreshed #121

blairio opened this issue Nov 11, 2021 · 3 comments · Fixed by #134

Comments

@blairio
Copy link

blairio commented Nov 11, 2021

Summary

Periodically we ask the device for updated information including battery level so we can accurately track and display the battery level of the device to the user. We expect this value to change over time as the device is used.

Lately, after we retrieve this value the first time on device connect or app launch it no longer seems to change on subsequent requests for the battery level. It always reports that first value.

Furthermore, the value seems to have a strange amount of precision.
Example: 0.9900000095367432

Code to reproduce

Example method we call when creating a payment intent.

  func refreshDeviceInfo() {
    if let reader = Terminal.shared.connectedReader {
      self.sendEvent(withName: self.exportedEvents["READER_DEVICE_INFO"], body: [
        "connectionStatus": Terminal.shared.connectionStatus.rawValue,
        "batteryLevel": reader.batteryLevel,
        "firmwareVersion": reader.deviceSoftwareVersion,
        "deviceType": reader.deviceType.rawValue,
        "serialNumber": reader.serialNumber
      ])
    } else {
      self.sendEvent(withName: self.exportedEvents["READER_DEVICE_INFO"], body: nil)
    }
  }

iOS version

14.8

Installation method

Cocoapods

SDK version

2.1.1 and 2.3.0

Other information

Seems to affect Chipper and Wisepad3

@jil-stripe
Copy link
Collaborator

jil-stripe commented Nov 11, 2021

Hi @blairio - thanks for writing in. Our intent is that the reader.batteryLevel property automatically updates with a new value. To save the reader's battery life, that property will update only once every ten minutes while the app is active and while the reader isn't in the middle of a transaction.

However, we've identified a bug in the SDK where the value doesn't update unless you implement the reader:didReportBatteryLevel:status:isCharging method in your SCPBluetoothReaderDelegate. implementing that method should work around this bug. As a bonus, that method will get called when the battery level or charging state has changed so you don't have to poll for that info on every payment. You can read its documentation for more.

We'll aim to have that bug fixed in the SDK in our January release.

The values will have precision just because they're floating point values - a 32-bit two's compliment float can't represent 0.99 exactly, 0.9900000095367431640625 is the closest representation available for the floating point format. In our example and internal apps, we multiply the float value by 100 and truncate to the closest integer value when displaying the reader's battery percentage.

Please let us know if the workaround makes that property behave as you'd expect! Thanks again for reporting.

@blairio
Copy link
Author

blairio commented Nov 11, 2021

Thanks I will try it out.

@blairio
Copy link
Author

blairio commented Nov 15, 2021

Seems to work, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants