Modifying file

This commit is contained in:
chabisik 2022-12-17 19:57:26 +01:00
parent c72f027362
commit 86441e051d
2 changed files with 19 additions and 11 deletions

View file

@ -39,7 +39,7 @@ void handleNotFound()
void closeCircuitViaWifi()
{
closeCircuitAndOpen();
server.send(200, "text/plain","Done");
server.send(200, "text/plain","Done\n");
}
void setup()

View file

@ -6,8 +6,7 @@ app = flask.Flask(import_name=__name__)
@app.route(rule="/")
def index():
print("Can print inside the called function")
return "Okay, got it !"
return "200 OK (working)\n"
lock = threading.Lock()
def opener(lck):
@ -17,15 +16,24 @@ def opener(lck):
@app.route(rule="/receiving", methods=["POST"])
def receiver():
#data = flask.request.get_json()
#for field in data: print(field, ":", data[field])
data = flask.request.get_data(as_text=True)
print(data)
print(flask.request.args)
if "please" in data:
op = threading.Thread(target=opener, args=(lock,))
op.start()
return flask.jsonify({"events":[{"event":"log","message":"server received sms successfully"}]})
parts = data.split("&")
data_dict = {}
for part in parts:
parameter_name, parameter_value = part.split("=")
data_dict[parameter_name] = parameter_value
print(data_dict)
#---action=incoming / message_type=sms---
if data_dict["action"]=="incoming":
if "please" in data_dict["message"].lower():
op = threading.Thread(target=opener, args=(lock,))
op.start()
return flask.jsonify({"events":[{"event":"log","message":"Server received "+data_dict["message_type"]+" from "+data_dict["from"]}]})
#---action=incoming---
#---action=incoming---
#---action=incoming---
#---action=incoming---
#---action=incoming---
if __name__=="__main__":
app.run(host="0.0.0.0", debug=True)