Skip to content

Instantly share code, notes, and snippets.

@refugeesus
Last active February 4, 2018 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refugeesus/17ca08474c5f27da806171ecc3e8ab92 to your computer and use it in GitHub Desktop.
Save refugeesus/17ca08474c5f27da806171ecc3e8ab92 to your computer and use it in GitHub Desktop.
from helium_client import Helium
from time import sleep
import logging
import json
import pprint
logging.basicConfig(filename='/tmp/myapp.log', level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(name)s %(message)s')
logger=logging.getLogger(__name__)
helium = Helium("/dev/serial0")
helium.connect()
configs = {}
local_configs = {}
def send_new_channel():
channel = helium.create_channel(str(configs["ch2"]))
try:
channel.send("Hello Helium 2")
print("ch2 sent")
except Exception as e:
print(e)
sleep(int(local_configs["interval"]))
def poll_inv():
if config.poll_invalidate(retries=0):
print("config correct")
pass
else:
try:
configs["interval"] = config.get("channel.interval")
config.set("channel.interval", str(configs["interval"]))
print(configs["interval"])
except Exception as e:
logger.error(e)
try:
configs["2chan"] = config.get("channel.2chan")
configs.set("channel.2chan", str(configs["2chan"]))
print(configs["2chan"])
except Exception as e:
logger.error(e)
try:
configs["ch2"] = config.get("channel.ch2")
config.set("channel.ch2", str(configs["ch2"]))
print(configs["ch2"])
except Exception as e:
logger.error(e)
local_configs["ch2"] = configs["ch2"]
if __name__=='__main__':
f = open('settings.json','r')
local_configs = json.load(f)
pprint.pprint(local_configs)
configs = local_configs
f.close()
channel = helium.create_channel(str(local_configs["ch1"]))
config = channel.config()
while(1):
poll_inv()
channel.send("Hello Helium 1")
print("ch1 sent")
sleep(int(local_configs['interval']))
if configs["2chan"] == "1":
f = open('settings.json', 'w')
send_new_channel()
local_configs = configs
f.write(json.dumps(local_configs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment