diff --git a/app/mifit_to_influxdb.py b/app/mifit_to_influxdb.py
--- a/app/mifit_to_influxdb.py
+++ b/app/mifit_to_influxdb.py
#
@@ -321,7 +321,7 @@ def get_band_data(auth_info, config):
#
'apptoken': auth_info['token_info']['app_token'],
#
- 'query_type': 'summary',
#
+ 'query_type': 'detail',
#
'device_type': 'android_phone',
#
'userid': auth_info['token_info']['user_id'],
#
'from_date': query_start.strftime('%Y-%m-%d'),
#
@@ -342,6 +342,10 @@ def get_band_data(auth_info, config):
#
+ if "data_hr" in daydata:
#
+ print("Extracting heart rate")
#
+ result_set = result_set + translate_heartrate_blob(daydata)
#
summary=json.loads(base64.b64decode(daydata['summary']))
#
for k,v in summary.items():
#
@@ -370,10 +374,74 @@ def get_band_data(auth_info, config):
#
print(f"Skipped {k} = {v}")
#
return result_set, serial
#
+def translate_heartrate_blob(daydata):
#
+ ''' Extract the heart rate data blob from the JSON
#
+ and convert to a list of stats
#
+ # Create a datetime object from the date specified in JSON
#
+ # this will be midnight.
#
+ nowtime = datetime.datetime.strptime(daydata['date_time'], "%Y-%m-%d")
#
+ number_blob = bytearray(base64.b64decode(daydata['data_hr']))
#
+ # Iterate through the bytestring
#
+ for byte_i in number_blob:
#
+ # iterating over leads to us fetching ints
#
+ # not bytes, so convert back
#
+ byte = byte_i.to_bytes(length=1, byteorder="big")
#
+ # Concatenate this byte onto the previous
#
+ # Move the marker to the right
#
+ # The data is a java short, so every
#
+ # 2 bytes, convert it to an integer
#
+ # Convert the bytestring to an int
#
+ # Adjust the timestamp forward 1 minute
#
+ nowtime = nowtime + datetime.timedelta(minutes=1)
#
+ # They seem to use a high initialisation
#
+ # value to indicate lack of data. If it's
#
+ # higher than 200 skip it
#
+ adjusted_vals.append({
#
+ "timestamp": int(nowtime.strftime('%s')) * 1000000000, # Convert to nanos
#
+ "heart_rate" : int(v),
#
+ "hr_measure" : "periodic"
#
+ # Reset the byte string
#
def get_blood_oxygen_data(auth_info, config):
#
''' Retrieve stress level information