Created
May 6, 2021 02:23
-
-
Save techman83/7a4da3a7997a3f3cac201ab241c3e31b to your computer and use it in GitHub Desktop.
Fronius5000 Offline Time Update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import requests | |
import time | |
USERNAME = os.getenv('INTERTER_USER') | |
PASSWORD = os.getenv('INVERTER_PASS') | |
INVERTER_IP = os.getenv('INVERTER_IP') | |
URL = f'http://{INVERTER_IP}/config/date/?method=save' | |
class FroniusDigest(requests.auth.HTTPDigestAuth): | |
def handle_401(self, r, **kwargs): | |
r.headers['WWW-Authenticate'] = r.headers.get('X-WWW-Authenticate') | |
r.headers['algorithm'] = 'MD5' | |
super().handle_401(r, **kwargs) | |
count = 0 | |
while count < 4: | |
success = False | |
try: | |
# It always returns an unauthorized message, but if it connects, it works... | |
requests.post(URL, auth=FroniusDigest(USERNAME, PASSWORD), json={"date":{"time": int(time.time()),"timezone":"Australia/Perth","timesync":False}}) | |
success = True | |
except requests.exceptions.ConnectionError: | |
pass | |
if success: | |
break | |
time.sleep(1) | |
count += 1 | |
else: | |
print('Failed to update invertor time') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment