related to fix #148 - the thing was crashing when uploading battery level for a Bubble. Now it will show battery level as percentage and not the iphone battery level, for Bubble, MM and others that offer battey level as percentage. For Dexcom it stays : both voltage and ios device batter level are uploaded

This commit is contained in:
Johan Degraeve 2020-12-30 23:46:04 +01:00
parent f3490a4466
commit e7404d5b2e
1 changed files with 18 additions and 3 deletions

View File

@ -204,14 +204,29 @@ public class NightScoutUploadManager:NSObject {
// https://testhdsync.herokuapp.com/api-docs/#/Devicestatus/addDevicestatuses
let transmitterBatteryInfoAsKeyValue = transmitterBatteryInfo.batteryLevel
let dataToUpload = [
// not very clear here how json should look alike. For dexcom it seems to work with "battery":"the battery level off the iOS device" and "batteryVoltage":"Dexcom voltage"
// while for other devices like MM and Bubble, there's no batterVoltage but also a battery, so for this case I'm using "battery":"transmitter battery level", otherwise there's two "battery" keys which causes a crash - I'll hear if if it's not ok
// first assign dataToUpload assuming the key for transmitter battery will be "battery" (ie it's not a dexcom)
var dataToUpload = [
"uploader" : [
"name" : "transmitter",
"battery" : Int(UIDevice.current.batteryLevel * 100.0),
transmitterBatteryInfoAsKeyValue.key : transmitterBatteryInfoAsKeyValue.value
"battery" : transmitterBatteryInfoAsKeyValue.value
]
] as [String : Any]
// now check if the key for transmitter battery is not "battery" and if so reassign dataToUpload now with battery being the iOS devices battery level
if transmitterBatteryInfoAsKeyValue.key != "battery" {
dataToUpload = [
"uploader" : [
"name" : "transmitter",
"battery" : Int(UIDevice.current.batteryLevel * 100.0),
transmitterBatteryInfoAsKeyValue.key : transmitterBatteryInfoAsKeyValue.value
]
]
}
uploadData(dataToUpload: dataToUpload, traceString: "uploadTransmitterBatteryInfoToNightScout", siteURL: siteURL, path: nightScoutDeviceStatusPath, apiKey: apiKey, completionHandler: {
// sensor successfully uploaded, change value in coredata