Skip to content

Commit

Permalink
home Handle connection Error Exception
Browse files Browse the repository at this point in the history
added host hover
orgenized services
added webapps in separate yaml
update all cfg copies
handles hue rescheck loop on bridge not available
  • Loading branch information
wassfila committed Oct 15, 2022
1 parent c0001a9 commit 3435f75
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 51 deletions.
1 change: 1 addition & 0 deletions hosts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
10.0.0.58 tv_set.shelly
10.0.0.59 freezer.shelly
10.0.0.62 routers.shelly
10.0.0.16 hover
22 changes: 21 additions & 1 deletion py/esp32/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
from collections import OrderedDict
import datetime

from platform import system as system_name # Returns the system/OS name
from subprocess import call as system_call # Execute a shell command

def ping(host):
"""
Returns True if host (str) responds to a ping request.
Remember that a host may not respond to a ping (ICMP) request even if the host name is valid.
"""

# Ping command count option as function of OS
param = '-n' if system_name().lower()=='windows' else '-c'

# Building the command. Ex: "ping -c 1 google.com"
command = ['ping', param, '1', host]

# Pinging
return system_call(command) == 0

# -------------------- config --------------------
def get_local_json():
"""fetches the config.json file in the local directory
Expand Down Expand Up @@ -43,9 +61,11 @@ def configure_log(logger_name):
"Critical" :50
}
#if(os.path.isfile(config["logfile"])):
logfile = config["logfile"].replace("(date)",datetime.datetime.now().strftime('-%Y.%m.%d'))
log.info(f"logging in file '{logfile}'")
for handler in log.root.handlers[:]:
log.root.removeHandler(handler)
log.basicConfig( filename=config["logfile"],
log.basicConfig( filename=logfile,
level=log_level_map[config["level"]],
format='%(asctime)s %(name)s %(levelname)-8s %(message)s',
datefmt='%d %H:%M:%S'
Expand Down
4 changes: 3 additions & 1 deletion py/heating/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ def configure_log(logger_name):
"Critical" :50
}
#if(os.path.isfile(config["logfile"])):
logfile = config["logfile"].replace("(date)",datetime.datetime.now().strftime('-%Y.%m.%d'))
log.info(f"logging in file '{logfile}'")
for handler in log.root.handlers[:]:
log.root.removeHandler(handler)
log.basicConfig( filename=config["logfile"],
log.basicConfig( filename=logfile,
level=log_level_map[config["level"]],
format='%(asctime)s %(name)s %(levelname)-8s %(message)s',
datefmt='%d %H:%M:%S'
Expand Down
7 changes: 6 additions & 1 deletion py/home_status/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def mqtt_on_message(client, userdata, msg):
heater_status(name,msg.payload)
else:
log.debug(f"topic: {msg.topic} : heat")
except requests.exceptions.ConnectionError as e:
log.error("mqtt_on_message> CoonectionError Exception :%s"%e)
except Exception as e:
log.error("mqtt_on_message> Exception :%s"%e)
return
Expand All @@ -122,7 +124,10 @@ def mqtt_on_message(client, userdata, msg):
clientMQTT = mqtt_start(config,mqtt_on_message,True)



#TODO handle exception
# requests.exceptions.ConnectionError:
# HTTPConnectionPool(host='10.0.0.48', port=80): Max retries exceeded
# url: /settings/?led_power_disable=true

while(True):
sleep(0.2)
Expand Down
4 changes: 3 additions & 1 deletion py/hover/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ def configure_log(logger_name):
"Critical" :50
}
#if(os.path.isfile(config["logfile"])):
logfile = config["logfile"].replace("(date)",datetime.datetime.now().strftime('-%Y.%m.%d'))
log.info(f"logging in file '{logfile}'")
for handler in log.root.handlers[:]:
log.root.removeHandler(handler)
log.basicConfig( filename=config["logfile"],
log.basicConfig( filename=logfile,
level=log_level_map[config["level"]],
format='%(asctime)s %(name)s %(levelname)-8s %(message)s',
datefmt='%d %H:%M:%S'
Expand Down
33 changes: 19 additions & 14 deletions py/hue/hue.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,26 +359,31 @@ def mqtt_on_message(client, userdata, msg):
log.error("mqtt_on_message> Exception :%s"%e)
return

def check_bridge():
if(cfg.ping(config["bridges"]["LivingRoom"])):
file_path=config["bridges"]["username_config"]
log.info(f"Bridge Connection using config '{file_path}'")
b = Bridge(ip=config["bridges"]["LivingRoom"],config_file_path=file_path)
b.connect()
log.info("Light Objects retrieval")
lights = b.get_light_objects('name')
log.info("Hue Lights available :")
for name, light in lights.items():
log.info(name)
return True
else:
log.info("Bridge ip not responding")
return False


# -------------------- main --------------------
config = cfg.configure_log(__file__)

# -------------------- Philips Hue Client --------------------
log.info("Check Bridge Presence")

if(cfg.ping(config["bridges"]["LivingRoom"])):
file_path=config["bridges"]["username_config"]
log.info(f"Bridge Connection using config '{file_path}'")
b = Bridge(ip=config["bridges"]["LivingRoom"],config_file_path=file_path)
b.connect()
log.info("Light Objects retrieval")
lights = b.get_light_objects('name')
log.info("Hue Lights available :")
for name, light in lights.items():
log.info(name)

else:
log.info("Bridge ip not responding")

while(not check_bridge()):
sleep(10)

# -------------------- Mqtt Client --------------------
#will start a separate thread for looping
Expand Down
87 changes: 54 additions & 33 deletions services.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,54 @@
container:
- mosquitto
- influx
- grafana
- zigbee2mqtt
- homeassistant
- nginx
- zigAssMano
- zigAssLifo
- deconz
webapps:
- overview
- bed_heating
- heating
- leds_panel
- mesh_view
- zigbee_graph_view
- next-home-control
python:
- nrf_mesh
- udp2mqtt
- mqtt2influx
- bathroom_fan
- huelight_control
- home_status
nodejs:
- lapse
- lifx
- pc_power
- watch_bots
- roll
native:
- openthread
used:
python:
- heat_cut : 'py/heating' cuts a rooms heat when a room's window is open
- nrf_mesh: custom RF devices to mqtt
- influx_mqtt: 'py/influx' mqtt 2 influx
- bathroom: manages the bathroom fan and light from switch and sensors
- hue : hue light control
- home_status: entrance shelly leds for heaing 'red' and open windows 'blue'
nodejs:
- zigbee2mqtt
- pc_power
- watch_bots
- roll
native:
- influxdb
- docker
docker:
- mosquitto: eclipse-mosquitto
- nginx

available:
webapps:
- overview
- bed_heating
- heating
- leds_panel
- mesh_view
- zigbee_graph_view
- next-home-control
python:
- heat_cut : cuts a rooms heat when a room's window is open
- nrf_mesh
- influx_mqtt: mqtt 2 influx
- bathroom_fan
- hue : hue light control
- home_status
- thread_tags: udp2mqtt
nodejs:
- zigbee2mqtt
- lapse
- lifx
- pc_power
- watch_bots
- roll
native:
- influxdb
- openthread : https://www.homesmartmesh.com/docs/networks/thread/#raspberry-pi
docker:
- influxdb
- grafana
- homeassistant
- zigAssMano
- zigAssLifo
- deconz
11 changes: 11 additions & 0 deletions webapps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
used:
- overview: http://10.0.0.31/home/
- home_3d: http://10.0.0.31/3d/
- next-home-control: http://10.0.0.31/next/
- heating: http://10.0.0.31/heat/
available:
- bed_heating
- mesh_view
- zigbee_graph_view
- leds_panel: http://10.0.0.2/
- led_bar: http://10.0.0.24/

0 comments on commit 3435f75

Please sign in to comment.