Thoughts on WebControl/WebMCP Port Assignments

One user has run into a problem running WebControl concurrently with some other applications on their RPI. WebControl uses port 5000, which is the default port for flask (webcontrol’s webserver) and other programs sometimes also use the default port. I can change the webcontrol port to something else and/or make it configurable. Changing it isn’t hard, it just would require everyone to start going to some different port… but then what happens if that new port conflicts with something… Making it configurable is better, but a bit more challenging.

If I make the port setting for WebControl a standard setting of webcontrol.json and a user is experiencing a conflict and is unable to start webcontrol, they have to manually edit the webcontrol.json file. I can make it a setting of WebMCP, but what if you have a conflict with WebMCP and you can’t bring it up either.

My thinking is that manually editing the webcontrol.json or webmcp.json files is probably a bad thing… one little mistake or mistyped punctuation mark and the whole thing craps out. So, I thought about doing something like the RPI does with SSH access. I could have each WebMCP and WebControl look for the presence of a file in the .WebControl directory. If the file is there, then it parses the filename for the port assignment and sets the setting for the user. That way, all a user with an issue would have to do is to enter SSH or terminal and issue a simple touch command:

touch webcontrol-5080.port

The program would look for files starting with webcontrol and an extension of port and then parse the port number from it (5080 in the above example). Same with webmcp-5081.port. Once the program updates the settings in webcontrol.json and webmcp.json, it then deletes those files. After that, the user can change the port assignments in the future using the browser.

I don’t believe there will be an issue with the use of the .WebControl directory because either program (WebMCP or WebControl) will create the directory if it doesn’t exist when its run even if it is unable to bind to a network port. So once the user tries to run either and gets a port-conflict message, the directory will have already been created and the user can then touch a file inside that directory.

Is there a better ways of doing this?

I’m not 100% sure but I would think you could set it up to take a command line argument at startup. No matter what port you choose you have to possibility of conflict. There is simply no standard so it’s like the wild west. First program to launch and take it wins!

I will peck around. I played with Flask a bit a few years back.

look over here:

hope that helps

Thank you

In retrospect you should be able to set up an external file name to look for to pass the port config if not found use the default. Something like newport.txt?

Thank you

I went ahead and implemented this and it seems to work well. If you put a file with name:


in the .WebControl directory, it will use 5080 as the port, update the settings, and delete the file.


I like that. Good Work!

1 Like

One question as I really don’t know much about Docker yet. How would I get to that folder within the Docker container to generate the file? I know my way around the Linux FS reasonably well, but once you’re inside the container I can’t seem to find a way to do file level maintenance.

Good question. That folder is not inside the docker. Its in the home directory of the user (typically home/pi). It gets created on the first run of either webmcp or webcontrol.

But, if you are pretty familiar with linux, try running the new releases instead of the docker. I’m going to be moving over to pyinstaller based releases and away from docker.

This is talking about the version that doesn’t use docker

David Lang

This is applicable to the docker build as well.

Sweet! Thanks! I have to say I’ve used Webcontrol a few times now running from a Pi 3B+ and I absolutely love it. Have been patiently waiting for holey calibration to arrive so I could try that but I believe it has done so now. Will try it as soon as I drag the beast back out. Have other projects using that space right now. You’d think with 3000 square feet to play in I’d have room for all the toys!

Thanks again for all your work on this!

Yes, holey calibration is in. Note, if you are not using the docker system (it’s baked in there), you have to manually update the firmware in the controller (i.e., use arduinio ide). I’m still working on a good system to generate and embed the firmware.