def on_data(msg_data): global DELAY if msg_data.data_id == "Delay": DELAY = msg_data.double_data def on_update(filename): # If we get here the update process has been carried out okay behind the scenes; and we have just received a # "go" signal - in which case we need to restart ourselves... # But first we need to copy the file to overwrite this one... shutil.copy(filename, *sys.argv) python = sys.executable os.execl(python, python, *sys.argv) client = pySRUP.Client("device.cfg", "https://example.com") client.on_action(on_action) client.on_data(on_data) client.on_update(on_update) client.update_filename("update.data") client.update_fetch_auth(auth) led_setup() with client: try: while 1: GPIO.output(14, GPIO.HIGH) time.sleep(0.5) GPIO.output(14, GPIO.LOW) time.sleep(0.5)
def on_join_refused(): client.send_SRUP_human_join() logger.info("Sending Human Join Request") def on_join_failed(): logger.warning("Join Failed – Rejected by Server") def on_human_join_response(secret_key): logging.info("Secret Key recieved – {}".format(secret_key)) client = pySRUP.Client("sw2.cfg", BASE_URL, device_type="HEX") client.on_action(on_action) client.on_id_request(on_id_req) client.on_join_refused(on_join_refused) client.on_join_failed(on_join_failed) client.on_human_join_response(on_human_join_response) # client.on_data(on_data) # client.on_update(on_update) # client.update_filename("update.data") running = True with client: try: # Start by joining the server defined in the config...
# Provide a function to return a string to provide the response to the ID request... # Here we'll just return the filename & a SHA-256 hash of the program code... with open(FILENAME, 'rb') as f: data = f.read() return "{} - SHA256 {}".format(FILENAME, hashlib.sha256(data).hexdigest()) def send_data(srup): global flag x = random.uniform(20, 25) srup.send_SRUP_Data(target_id=server_id, data_id="DATA", data=x) logging.info("Sending data – DATA = {}".format(x)) flag = True client = pySRUP.Client("soft_dev.cfg", BASE_URL, device_type="simple") client.on_action(on_action) # client.on_data(on_data) # client.on_update(on_update) client.on_id_request(on_id_req) # client.update_filename("update.data") running = True with client: try: # Start by joining the server defined in the config... client.send_SRUP_simple_join() y = random.randint(5, 10) t = Timer(y, send_data, [client]) t.start()