used localhost ip on linux
This commit is contained in:
parent
1b617a1794
commit
a888e774ef
@ -4,7 +4,7 @@ import os
|
|||||||
import requests
|
import requests
|
||||||
from paho.mqtt import client as mqtt
|
from paho.mqtt import client as mqtt
|
||||||
|
|
||||||
from constants import solaredge_api_key, solaredge_monitoring_api_url, mqtt_username, mqtt_password, mqtt_broker_ip
|
from constants import solaredge_api_key, solaredge_monitoring_api_url, mqtt_username, mqtt_password, mqtt_broker_ip, mqtt_broker_ip_linux
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
@ -57,10 +57,11 @@ def get_energy_totals(time_unit, start_date, end_date):
|
|||||||
def connect_mqtt():
|
def connect_mqtt():
|
||||||
c = mqtt.Client()
|
c = mqtt.Client()
|
||||||
c.username_pw_set(mqtt_username, mqtt_password)
|
c.username_pw_set(mqtt_username, mqtt_password)
|
||||||
|
mqtt_ip = mqtt_broker_ip if os.name == 'nt' else mqtt_broker_ip_linux
|
||||||
try:
|
try:
|
||||||
# Stel in: probeer elke 1 tot 120 seconden opnieuw te verbinden
|
# Stel in: probeer elke 1 tot 120 seconden opnieuw te verbinden
|
||||||
c.reconnect_delay_set(min_delay=1, max_delay=120)
|
c.reconnect_delay_set(min_delay=1, max_delay=120)
|
||||||
c.connect(mqtt_broker_ip, 1883, 60)
|
c.connect(mqtt_ip, 1883, 60)
|
||||||
c.loop_start() # Draait op de achtergrond en regelt de automatische reconnect
|
c.loop_start() # Draait op de achtergrond en regelt de automatische reconnect
|
||||||
return c
|
return c
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user