I am having trouble writing a python script to get my thermostat data to log temperatures. The message that I get is “Signature2 is invalid”. I believe I have a valid token. Here is the code I’m working with at the moment. Am I using the right logic for the hmac and md5 coding?
def create_signature2(payload, access_token, signing_secret):
token_secret = access_token + signing_secret
secret_digest = md5(token_secret.encode(“ascii”)).hexdigest().encode(“ascii”)
payload_string = json.dumps(payload, separators=(“,”,“:”), sort_keys=True)
print(payload_string)
hmac_digest = hmac.new(secret_digest, payload_string.encode(), md5).hexdigest()
return hmac_digest
def create_post_header(payload, access_token):
#signing_secret = “wyze_app_secret_key_132”
#app_id=‘9319141212m2ik’
#app_id=“umgm_78ae6013d158c4a5”
#app_id = “strv_e7f78e9e7738dc50”
app_id = “earp_9b66f89647d35e43” # specifically for earth service?
s = “this is how encoding works”
print(s.encode(“utf-8”))
print(s.encode(“ascii”))
print(s.encode())
signing_secret = app_id
signature2 = create_signature2(payload, access_token, signing_secret)
print(signature2)
return {
“content-type”: “application/json”,
“phoneid”: “test”,
#“user-agent”: f"wyze_ios_{APP_VERSION}“,
#“appinfo”: f"wyze_ios_{APP_VERSION}”,
#“authorization”: "Bearer " + access_token,
“Authorization”: access_token,
“appid”: app_id,
“app_ver”: “wyze_developer_api”,
“appinfo”: “wyze_web_2.3.1”,
“app_version”: “wyze_developer_api”,
“sc”: “wyze_developer_api”,
“sv”: “wyze_developer_api”,
“phone_id”: “wyze_developer_api”,
#“appversion”: APP_VERSION,
“access_token”: access_token,
“signature2”: signature2,
}
def get_thermostat2(access_token, device_mac, device_model):
keys = (
“trigger_off_val,emheat,temperature,humidity,time2temp_val,protect_time,mode_sys,heat_sp,cool_sp, current_scenario,config_scenario,temp_unit,fan_mode,iot_state,w_city_id,w_lat,w_lon,working_state, dev_hold,dev_holdtime,asw_hold,app_version,setup_state,wiring_logic_id,save_comfort_balance, kid_lock,calibrate_humidity,calibrate_temperature,fancirc_time,query_schedule”
)
payload = {
“keys”: keys,
“nonce”: int(time.time() * 1000),
“did”: device_mac,
}
headers = create_post_header(payload, access_token)
url = “https://wyze-earth-service.wyzecam.com/plugin/earth/get_iot_prop”
r = requests.post(url, json=payload, headers=headers)
print(r.text)
print(r.json())