Skip to content

Commit

Permalink
optimized settings transmission (lowered the length of transmitted data)
Browse files Browse the repository at this point in the history
  • Loading branch information
ftylitak committed Oct 9, 2023
1 parent 97b058c commit 69be20b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
18 changes: 16 additions & 2 deletions insighioNode/web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,26 @@ def get(self, data):
return {"raw": raw_val}, 200

class Config:
def convert_params_to_string(self, data):
queryString = ""
try:
for key in data["queryParams"].keys():
if key in data["encodedParams"]:
queryString += "{}={}&".format(key, data["encodedParams"][key])
else:
queryString += "{}={}&".format(key, data["queryParams"][key])
if queryString != "":
queryString = queryString[0: -1]
except Exception as e:
logging.exception(e, "convert_params_to_string")
return queryString

def post(self, data):
print("received config data: {}".format(data))
logging.debug("about to save queryString: " + data["queryString"])

import utils
utils.writeToFile("/configLog", data["queryString"])
logging.debug("about to save queryParams: {}".format(data["queryParams"]))
utils.writeToFile("/configLog", self.convert_params_to_string(data))

try:
from utils import configuration_handler
Expand Down
1 change: 1 addition & 0 deletions insighioNode/www/step-5-4-measurement-naming.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
}
catch (e) {
console.log("failed parsing: ", storedMapping)
storedMapping = {}
}

if (storedMapping) {
Expand Down
15 changes: 7 additions & 8 deletions insighioNode/www/step-8-apply.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,23 @@

function apply() {
var config = Cookies.get()
var configString = ""
var encodedParams = {}
var isConfigValid = false

for (let key in config) {
if (config.hasOwnProperty(key)) {
configString += (key + "=" + config[key] + "&")
isConfigValid = true
if(key === 'wifi-ssid' || key === 'wifi-pass' || key === 'meas-name-mapping' || key === 'meas-keyvalue') {
encodedParams[key] = config[key]
config[key] = decodeURIComponent(config[key]).replaceAll("\\", "\\\\").replaceAll("'", "\\'")
}
}
}

if (configString !== "")
configString = configString.slice(0, -1)
console.log("queryParams: ", config)
const objToSend = { queryParams: config, encodedParams }

console.log("configString: ", configString)
const objToSend = { queryParams: config, queryString: configString }

if (configString == "") {
if (!isConfigValid) {
startOver()
return
}
Expand Down

0 comments on commit 69be20b

Please sign in to comment.