Code: Select all
python3 appname.py
Code: Select all
cherrypy.config.update({'server.socket.host' : '0.0.0.0', 'server.socket.port' : 8085,})
to allow me to do this, but no matter where I try inserting the cherrypy.update thing, or indenting it, lxterminal either reports a syntax fault, or goes on to close it down again, when the problem seems to stem from the on/off toggle def.(says he, not knowing much)
The module's code is:-
Code: Select all
import cherrypy
from ds18b20 import DS18B20
class HeaterService(object):
def __init__(self):
self.dal = DS18B20()
self.heaterState = "OFF"
@cherrypy.expose
def index(self):
temperatures = self.dal.get_temperatures([DS18B20.DEGREES_F])
btnText = "off" if self.heaterState == "ON" else "on"
return '''<html>
<meta http-equiv="refresh" content="6;url="http://index">
<script type="text/javascript">var currentTemp = {0:f};</script>
<body>
<div>Current temperature is:</div>
<div>{0:.2f}</div>
<div>degrees Fahrenheit</div>
<div>Heater state is: {1}</div>
<div><a href="toggle">Turn heater {2}</a>
</body></html>'''.format(temperatures[0], self.heaterState, btnText)
@cherrypy.expose
def toggle(self):
if self.heaterState == "OFF":
# turn the heater on here
self.heaterState = "ON"
else:
# turn the heater off here
self.heaterState = "OFF"
raise cherrypy.HTTPRedirect("/index")
if __name__ == '__main__':
cherrypy.quickstart(HeaterService())
cherrypy.config.update({ 'server.socket.host': '0.0.0.0','server.socket.port':8085,}) #this does not worki as required
UPDATE:
I have also tried using
Code: Select all
index.exposed = True
index._cp_config = {'server.socket_host' : '0.0.0.0', 'server.socket_port' : 8085,}
Now 'WORKING', if that is what 'working' meansBUT what a lousy Kludge>>>>>>
The problem was in the <meta> tag in the code. I had to comment this out, then start the app, which did change the host and the port, then edit the .py file to remove the # commenter while the app was still running, and save it. Surely there must be a 'proper' way to do this?