I have trouble understanding how to implement a temperature sensor as webthing-python.
I have read the blog and the doc’s but i still do not see how…
this is my temperature, its stored as number to a file.
def getTemperature():
temp = open('/tmp/sensors/temperature.1.temperature','r')
print temp
print temp.read()
it gets printed like this:
root@espresso:/IoT/espresso# python coffeemachine-single.py
<open file '/tmp/sensors/temperature.1.temperature', mode 'r' at 0x900f38>
25.23
2019-04-24 19:17:38,069 coffeemachine-single.py:56 INFO starting the server
2019-04-24 19:17:41,551 web.py:2162 INFO 200 GET / (192.168.178.56) 26.22ms
2019-04-24 19:17:41,612 web.py:2162 INFO 200 GET /properties/on (192.168.178.56) 12.09ms
2019-04-24 19:17:41,639 web.py:2162 INFO 200 GET /properties/TemperatureC (192.168.178.56) 12.55ms
2019-04-24 19:17:41,689 web.py:2162 INFO 101 GET / (192.168.178.56) 33.37ms
my code has another property:
def coffeemachine():
thing = Thing('Coffeemachine',
['OnOffSwitch','Temperature'],
'A web connected coffeemachine'
)
thing.add_property(
Property(thing,
'on',
Value(True),
metadata={
'@type': 'OnOffProperty',
'title': 'On/Off',
'type': 'boolean',
'description': 'Whether the coffeemachine is turned on',
}
)
)
thing.add_property(
Property(thing,
'TemperatureC',
Value(getTemperature()),
metadata={
'@type': 'TemperatureProperty',
'title': 'Temperature',
'type': 'number',
'description': 'The temperature of the heater (in Celsius) inside the coffeemachine.',
'minimum': -20,
'maximum': 100,
'unit': 'celsius',
'readOnly': True,
}
)
)
return thing
and i call the server as:
def run_server():
thing = coffeemachine()
# If adding more than one thing, use MultipleThings() with a name.
# In the single thing case, the thing's name will be broadcast.
server = WebThingServer(SingleThing(thing), port=8888)
try:
logging.info('starting the server')
server.start()
except KeyboardInterrupt:
logging.info('stopping the server')
server.stop()
logging.info('done')
if __name__ == '__main__':
logging.basicConfig(
level=10,
format="%(asctime)s %(filename)s:%(lineno)s %(levelname)s %(message)s"
)
run_server()
I do not see the value on my gateway when looking at the coffeemachine thing.
the full file is viewable here.