I have created a program with the ESP8266 to periodically request to my flask application a integer variable to turn on and off a LED.
When I run it locally the app works as it should but when I deploy it on Heroku, the first time I change the value of the status it starts swaping from 1 to 0 randomly forever.
Here is the code of the Flask app
from flask import Flask, jsonify, render_template, redirect
import time
##########################################################
app = Flask(__name__)
ledStatus = 1
##########################################################
@app.route('/led-status')
def getStatus():
return jsonify (ledStatus = ledStatus)
@app.route('/button')
def getButton():
return render_template('button.html', ledStatus=ledStatus)
@app.route('/led-swap')
def swapStatus():
global ledStatus
if ledStatus == 1:
ledStatus = 0
else:
ledStatus = 1
time.sleep(0.5)
return redirect("/button")
##########################################################
if __name__ == "__main__":
app.run()