Hi,
I am a bit stuck,There are plenty of tutorials and forum replies for one DS18B20 sensors but I cannot find any for multiple sensors that dont use esp826 or something else. My code (below) displays the temperature of 11 senrors in the console, but I am stuck with display more than one on a web page. i have seperated my code into different modules to keep things clean and so I can import them as I need, The first is nested dictionaries with the 11 sensors
Paul
I am a bit stuck,There are plenty of tutorials and forum replies for one DS18B20 sensors but I cannot find any for multiple sensors that dont use esp826 or something else. My code (below) displays the temperature of 11 senrors in the console, but I am stuck with display more than one on a web page. i have seperated my code into different modules to keep things clean and so I can import them as I need, The first is nested dictionaries with the 11 sensors
sensorsID = { 1 : {'name':'top Cylinder','ID': '28-020f92456b1b'}, 2 : {'name':'Middle Cylinder','ID': '28-000398430420'}, 3 : {'name':'Bottom Cylinder','ID': '28-03170017b5ff'}, 4 : {'name':'Boiler output','ID': '28-0212924519b0'}, 5 : {'name':'Boiler Input','ID': '28-000798430de0'}, 6 : {'name':'Kitchen Output','ID': '28-0202924581e6'}, 7 : {'name':'kitchen Return','ID': '28-02169245238b'}, 8 : {'name':'Back Area Output','ID': '28-0317000e43ff'}, 9 : {'name':'Back Area Return','ID': '28-0317003f1cff'}, 10 : {'name':'House Output','ID': '28-0416c4a3a0ff'}, 11 : {'name':'House Return','ID': '28-021692451c79'} }the next is the code to read these sensors,
def read_sensor(sensorID): tempfile = open("/sys/bus/w1/devices/"+ sensorID +"/w1_slave") thetext = tempfile.read() tempfile.close() tempdata = thetext.split("\n") [1].split(" ")[9] temperature = float(tempdata[2:]) temp_sensor = temperature / 1000 return (temp_sensor)the next is the code that works in terminal
from mySensorModule import read_sensor from mySensors import sensorsID import time for sensor in sensorsID: print("The temperatue of ",sensorsID[sensor]['name'], " is ",read_sensor(sensorsID[sensor]['ID']))But the problem arises when i try to display this in a webpage, I can display one sensor but not all, Here is the code I have tried but I get an error; sensors.py
from flask import ( Blueprint, flash, g, redirect, render_template, request, url_for ) from werkzeug.exceptions import abort from mySensorModule import read_sensor from homeHeating.auth import login_required from homeHeating.db import get_db from mySensorModule import read_sensor from mySensors import sensorsID import time @bp.route('/sensors') @login_required def sensors(): for sensor in sensorsID: name=sensorsID[sensor]['name'], temp=read_sensor(sensorsID[sensor]['ID'] templateData = { 'name' : name, 'ID' : ID } return render_template('sensors/sensors.html', **templateData)
Error:File "/home/pi/heating/homeHeating/sensors.py", line 20
templateData = {
^
SyntaxError: invalid syntax
this code is an adaptation of matt richardsons tutorial the html script looks like this;{% extends 'base.html' %} {% block header %} <h1>{% block title %}Sensors{% endblock %}</h1> <a class="action" href="{{ url_for('sensors.addsensor') }}">New Sensor</a> {% endblock %}{% block devises %} {% for sensor in sensorsID %} <p>The {{ name }} the temperature of {{ name }} is {{ temp }} </p> {% endfor %} {% endblock %}if I use the origional code with this template no sensors are displayed, I hope you are able to follow this! Any help is needed.
Paul