About the problem that flask provides web services and links to socket separately at the same time!

< H1 > python rookies say hello to all the bosses! Ask the boss questions! < / H1 > < H1 > functions I need to implement < / H1 >

1. Using the flask framework to provide web services is simply a few keystrokes and then some indication of status! Access through the browser, you can view the status, you can change the status after logging in (such as pressing the button to control the light on and off)
2. After clicking the button, you need to communicate with the lower computer through socket,TCP connection,
3. The lower computer is a piece of STM32 as the main control, plus some peripherals, the main communication equipment is through the communication module for TCP or UDP communication, does not support the http protocol
4. Summary: tcp communication with a specific ip through web web pages.

< H1 > my current problems < / H1 >

1. How to send data to a specific ip by clicking the web interface button
2. How to accept specific ip data
3. How to run flask service while opening a separate port to provide socket service, using TCP connection (currently only needs to communicate with one lower computer)

< H1 > results I expect < / H1 >

1. Do the bosses have any relevant materials (such as flask-socketio), demo
2. Do the bosses have a better implementation plan? (do not use falsk, to use python WSGI interface to manually do it?)
3. Beg the boss for advice


1. This is the relevant information about flask-socketio. I hope you like a: http://www.os373.cn/article/99 Magazine b: http://flask-socketio.readthedocs.io/en/latest/

.

2. For information about how to accept a specific IP, it is recommended that your system be linux, and then use the os module to directly call the socekt communication mechanism of the linux system.
3. Flask-socketio itself is integrated into the flask project, so there is no need to restart a process.


you can consider using the MQTT+JSON scheme, so that you can run not only on the local area network, but also on the public network.

STM32 runs the MQTT client, and connects to the MQTT Broker,Web server to monitor the lower computer through MQTT Broker HTTP API, or get a MQTT Client to send and receive commands.


hello, have you solved your problem? I now have the same problem as you., (flask framework provides web services, provides interfaces, and receives data sent by amazon. I want to know how to send it to the lower computer. All I can think of is to build socket, but failed when I try to build tcp server (always prompting that socket is occupied). Do you have a good solution?


here is a solution for you:

problem: the flask framework does not allow the creation of a separate socket, even if the listening port number is different, it will indicate that the communication address is occupied.

solved: establish the cache file on the hard disk, and the socket communicating with the lower computer creates the python file separately, which is responsible for storing the data received by the sensor in the cache file. Then, as long as the python file of the flask is opened, the data of the cache file can be read, and the timer can be opened to check the cache file regularly. Although the performance is not high and it is not suitable to deal with big data, it is more than enough to process the sensor data of the Internet of things.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35cbd-2b73c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35cbd-2b73c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?