Best way to share on/off status of webthing-python with local webserver

Im implementing a webthing-python-thing and want to host a separate Webserver on the same device.
The on/off variable will be callable from gateway.local as a thing and the webpage.local.

Is it possible to use tornado webserver for webthing and a website on the same device somehow?

Yes. Check out this example. With webthing-python, you can add arbitrary routes and handlers to the server.

You can obviously alternatively just have an additional web server instance running on a different port. That’s what is actually happening in my WebOfTXT thing (I think I had linked that to you before, it’s on my GitHub). But I also use the method @mrstegeman mentions to proxy it so it can be used from the gateway (kind of).

Thanks for the examples. I will try it and come back soon.
Have to order a new node as i bricked my device recently.

@mrstegeman I now tried to understand what your photo-cycler-webthing does and recognized that the page loaded localy displays a json string. It seams that your example of a Photocarousel is ment to be a webthing hosted on a thing device and looked at on the gateway side. Im searching for a simple example to display a webpage with a simple switch localy on top of the webthing-python. I whant to have a local webpage on the device and a webthing-gateway connection at the same time. Do you know about a simple example of how to make tornado to generate a webthing and a webpage on one device?

@freaktechnik thanks for that example but im not able to break it down to what i need. Im sure it will help me in a further stadium but for right now its to complex.

The root of a webthing will always be the web thing API JSON. However /static/index.html is intended for general viewing in the case of the photo cycler. It is also exposed to the gateway UI so you can get to it from there, but you can also just load it in a tab.

True. I did not think at that possibility. Thanks for the input.
I’m searching for a solution to make both available. A webthing and a local webpage available on request of the hostname like http://mycoffeemachine.local

I created already a working solution with two servers where i used a cherrypy webserver besides webthing-python and that worked. I was able to access the cherrypy webpage over http://mycoffeemachine.local and in the gateway the coffeemachine-thing apeard.

What i don’t understand is why I was able to make both work. My cherrypy website was listening on port 80 and webthing-python provides the json-api on port 80.
How do both work then?

And, how can I make both work on one server like the tornado?

The only way to make them both work on the same port (afaik) is to decide based on the content type the requestor accepts. I think the gateway will ask for JSON, while a browser will ask for HTML (in the Accept-Content or similar header).

The alternative is to run them on separate ports.

Im wondering how it worked as well.
Is it possible that the webthing-websocket is created on different ports than 80/443?
@mrstegeman: What does mdns negotiate here for?