borft / py-goodwe

Python lib to query Goodwe inverters
GNU General Public License v3.0
15 stars 2 forks source link

code stopped working #4

Closed wiedsee closed 1 year ago

wiedsee commented 1 year ago

Error im receiving:

Traceback (most recent call last):
  File "Solar_MQTT2.py", line 1, in <module>
    from goodwe import Goodwe,GoodweStatus
  File "/home/pi/goodwe.py", line 14
    def to_16_bit(buffer: [bytes], exp: int = -1, signed: bool = False) -> int:
                        ^
SyntaxError: invalid syntax[](URL)

script:

from goodwe import Goodwe,GoodweStatus
import paho.mqtt.client as mqtt 
from random import randrange, uniform
import time
from datetime import datetime
import sys

now = datetime.now()
current_time = now.strftime("%H:%M:%S")
ip = "192.168.68.141"
gw = Goodwe(ip=ip)
mqttBroker ="192.168.68.119" 
client = mqtt.Client("SolarRoof2")
client.connect(mqttBroker) 
print('booting...')
while True:
    current_time = now.strftime("%H:%M:%S")
    #print(current_time)
    if current_time > '06:00:00':
        if current_time < '19:00:00':
            client.connect(mqttBroker) 
            try:
                data = gw.getData()
            except Exception as e:
                print("Failed: ".format(e))
                time.sleep(300)
                exit(0)
            data['power_dc_1'] = round(data['power_dc_1'], 2)
            data['power_dc_2'] = round(data['power_dc_2'], 2)
            client.publish('yield_today2', data['yield_today'])
            power = round(data['power_dc_2']+data['power_dc_1'], 2)
            client.publish('power2', power)
            print('publisch to yield_today2', data['yield_today'])
            print('publisch to power2', power)
            print('data succesfully recived and send')
            time.sleep(30)
        else:
            print('out of time cheking again in 60sec')
            time.sleep(60)
    else:
        print('out of time cheking again in 60sec')
        time.sleep(60)

python version: Python 2.7.16 (default, Oct 10 2019, 22:02:15) [GCC 8.3.0] on linux2

wiedsee commented 1 year ago

used wrong version Python3 works fine