Python Forum
combining flask webserver and another applicaiton - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: combining flask webserver and another applicaiton (/thread-26708.html)



combining flask webserver and another applicaiton - maciejMatthias - May-10-2020

I have an application that runs a dehumidifier, through a loop in main(). I have a flask web server to provide a web interface for the dehumidifier. Currently these are separate.
How do I add my main() code into the web server application?
Alternatively how do I make the applications talk to each other?

Where would I start?

Any help would be appreciated.

Thank you
Maciej


RE: combining flask webserver and another applicaiton - experimental - May-10-2020

hard to say without seeing any code or structure.. but i belive you need to make it as a threaded app with some background tasks


RE: combining flask webserver and another applicaiton - maciejMatthias - May-10-2020

Main application (Raspberry Pi)
def main():
    # Initialize log file to empty on start up
    g_logFileName = EMPTY
    g_cntrWiFi = int(time.perf_counter())
    while(1):
        g_cntrWiFi = InternetCheck(g_cntrWiFi)
        readSwitches()
        SenseCheck()
        UpdateDisplay()                                  
        DeHumidifyLogic()
        updateLog = UpdateOutputs()
        g_logFileName = LogData(updateLog, g_logFileName)
        time.sleep(0.1)
        
    GPIO.cleanup() # cleanup all GPIO 
main()
Flask web server code snippet:
app = Flask(__name__)

if __name__ == "__main__":
    app.run(port=5000, debut=True)
As soon as app.run is executed, nothing else gets executed.


RE: combining flask webserver and another applicaiton - snippsat - May-10-2020

There is not any code in that flask server Wink
Look at this Thread so there i use APScheduler and
send value to client trough jinja.
So parse_func() could be your main function if it return anything,
or you could read the saved logged file in interval.

In this Thread do interval reading from client side with AJAX.