diff --git a/app_template/cs.py b/app_template/cs.py index c5e5ed17..9359ed03 100644 --- a/app_template/cs.py +++ b/app_template/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" diff --git a/common/cs.py b/common/cs.py index b83a98d0..9359ed03 100644 --- a/common/cs.py +++ b/common/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request.""" diff --git a/email/cs.py b/email/cs.py index b83a98d0..9359ed03 100644 --- a/email/cs.py +++ b/email/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request.""" diff --git a/ftp_client/cs.py b/ftp_client/cs.py index b83a98d0..9359ed03 100644 --- a/ftp_client/cs.py +++ b/ftp_client/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request.""" diff --git a/ftp_server/cs.py b/ftp_server/cs.py index b83a98d0..9359ed03 100644 --- a/ftp_server/cs.py +++ b/ftp_server/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request.""" diff --git a/gps_localhost/cs.py b/gps_localhost/cs.py index b83a98d0..9359ed03 100644 --- a/gps_localhost/cs.py +++ b/gps_localhost/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request.""" diff --git a/gps_probe/cs.py b/gps_probe/cs.py index b83a98d0..9359ed03 100644 --- a/gps_probe/cs.py +++ b/gps_probe/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request.""" diff --git a/hello_world/cs.py b/hello_world/cs.py index b83a98d0..9359ed03 100644 --- a/hello_world/cs.py +++ b/hello_world/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request.""" diff --git a/hspt/cs.py b/hspt/cs.py index b83a98d0..9359ed03 100644 --- a/hspt/cs.py +++ b/hspt/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request.""" diff --git a/list_serial_ports/cs.py b/list_serial_ports/cs.py index b83a98d0..9359ed03 100644 --- a/list_serial_ports/cs.py +++ b/list_serial_ports/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request.""" diff --git a/loglevel/cs.py b/loglevel/cs.py index b83a98d0..9359ed03 100644 --- a/loglevel/cs.py +++ b/loglevel/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request.""" diff --git a/modbus_poll/cs.py b/modbus_poll/cs.py index b83a98d0..9359ed03 100644 --- a/modbus_poll/cs.py +++ b/modbus_poll/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request.""" diff --git a/ping/cs.py b/ping/cs.py index b83a98d0..9359ed03 100644 --- a/ping/cs.py +++ b/ping/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request.""" diff --git a/power_gpio/cs.py b/power_gpio/cs.py index b83a98d0..9359ed03 100644 --- a/power_gpio/cs.py +++ b/power_gpio/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request.""" diff --git a/send_alert/cs.py b/send_alert/cs.py index b83a98d0..9359ed03 100644 --- a/send_alert/cs.py +++ b/send_alert/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request.""" diff --git a/serial_echo/cs.py b/serial_echo/cs.py index b83a98d0..9359ed03 100644 --- a/serial_echo/cs.py +++ b/serial_echo/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request.""" diff --git a/simple_web_server/cs.py b/simple_web_server/cs.py index b83a98d0..9359ed03 100644 --- a/simple_web_server/cs.py +++ b/simple_web_server/cs.py @@ -109,7 +109,7 @@ def get(self, base, query='', tree=0): print("Timeout: router at {} did not respond.".format(router_ip)) return None - return json.loads(response.text)['data'] + return json.loads(response.text) def put(self, base, value='', query='', tree=0): """Send a put request.""" @@ -137,13 +137,27 @@ def put(self, base, value='', query='', tree=0): def append(self, base, value='', query=''): """Send an append request.""" + value = json.dumps(value).replace(' ', '') if sys.platform == 'linux2': - value = json.dumps(value).replace(' ', '') cmd = "post\n{}\n{}\n{}\n".format(base, query, value) return self._dispatch(cmd) else: - print('Append is only available when running the app in the router.') - raise NotImplementedError + # Running in a computer so use http to send the post to the router. + import requests + router_ip, router_username, router_password = self._get_router_access_info() + router_api = 'http://{}/api/{}/{}'.format(router_ip, base, query) + + try: + response = requests.post(router_api, + headers={"Content-Type": "application/x-www-form-urlencoded"}, + auth=requests.auth.HTTPDigestAuth(router_username, router_password), + data={"data": '{}'.format(value)}) + except (requests.exceptions.Timeout, + requests.exceptions.ConnectionError): + print("Timeout: router at {} did not respond.".format(router_ip)) + return None + + return response.text def delete(self, base, query=''): """Send a delete request."""