import urllib import json ip_address = IP ADDRESS port = PORT lastGet = -1000 lastSend = -1000 def getData(): global lastGet # Only fetch new data once per second, even if main tab code # tries to fetch it more frequently. This is called "throttling" fetchedData = False serverDataList = [] if millis() > lastGet + 1000: fetchedData = True lastGet = millis() response = urllib.urlopen("http://"+ip_address+":"+port+"/get") j = json.load(response) print(j) c = [] for c in j: c["x"] = int(c["x"]) c["y"] = int(c["y"]) c["color"] = unhex(c["color"]) c["size"] = int(c["size"]) serverDataList.append(c) return (fetchedData,serverDataList) def sendData(myCreature): global lastSend # Also throttle this request to only SEND once per second if millis() > lastSend + 1000: lastSend = millis() variableString = "name=" + myCreature["name"] variableString += "&x=" + str(myCreature["x"]) variableString += "&y=" + str(myCreature["y"]) variableString += "&color=" + hex(myCreature["color"]) variableString += "&size=" + str(myCreature["size"]) returnValue = loadStrings("http://"+ip_address+":"+port+"/move?" + variableString)