Michael LassRalph
Published © GPL3+

Kitchen Information Interface

Kitchen Information Interface displays information via web interface to several user.

IntermediateWork in progress1,095
Kitchen Information Interface

Things used in this project

Hardware components

Grove Temperature sensor(thermistor)
×1
Raspberry Pi 1 Model B+
Raspberry Pi 1 Model B+
×1
display
×1

Story

Read more

Schematics

Edison

Raspberry Pi

Raspberry Pi Display

Code

app.py

Python
main flask application to receive URL posts and write to database
# We need to import request to access the details of the POST request
# and render_template, to render our templates (form and response)
# we'll use url_for to get some URLs for the app on the templates
from flask import Flask, render_template, request, url_for
import sqlite3
import os
from datetime import date, datetime
import time

# Initialize the Flask application
app = Flask(__name__)

# Define a route for the default URL, which loads the form
@app.route('/')
def form():
    return render_template('form_submit.html')

@app.route('/temp', methods = ['POST'])
def temp():
    if request.method == 'POST':
        """modify/update the information for <temperature>"""
        # you can use <user_id>, which is a str but could
        # changed to be int or whatever you want, along
        # with your lxml knowledge to make the required
        # changes
        temperature = request.args.get('temperature')
        location = request.args.get('location')
        #data =  request.form["temperature"]
       # data = request.form # a multidict containing POST data
        print temperature, " for location ", location

#        if os.path.isfile('/home/pi/environ.db'):
#           db = sqlite3.connect('/home/pi/temperature.db')
#           c = db.cursor()
#        else:
#           db = sqlite3.connect('/home/pi/temperature.db')
#           c = db.cursor()
#           c.execute('''CREATE TABLE temps (location  TEXT, temperature int, recordtime TEXT)''')

        today = datetime.today()
#         c.execute('''INSERT INTO temperature(created_at, tempF) VALUES(?,?)''', (today,t[1]))
#db.commit()
        conn = sqlite3.connect('/home/pi/temperatures.db')
        c = conn.cursor()

        c.execute('''INSERT INTO temps(location, temperature, recordtime)
             VALUES(?,?,?)''', (location, temperature, today))

        conn.commit()
        return render_template('tempform_action.html', location=location, temperature=temperature)

# Define a route for the action of the form, for example '/hello/'
# We are also defining which type of requests this route is 
# accepting: POST requests in this case
@app.route('/temp1/', methods=['POST'])
def temp1():
    name=request.form['location']
    email=request.form['temperature']
    return render_template('form_action.html', location=location, temperature=temperature)

# Run the app :)
if __name__ == '__main__':
  app.run( 
        host="0.0.0.0",
        port=int("80")
  )

showtemp.py

Python
This application runs on the kitchen appliance and once a minute displays the latest information
import urllib2
import urllib
import sqlite3
import time
import os
import sys
import pprint
import datetime
#from calendar_parser import CalendarParser
from time import sleep
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw 
from datetime import date, datetime
from subprocess import call

def main():
   while 1:
      img = Image.open("Delorean.jpg")
      draw = ImageDraw.Draw(img)
      font = ImageFont.truetype("FreeSans.ttf", 60)
      draw.text((20, 15),"Latest temperature",(252,252,252),font=font)
      yPos = 50

      conn = sqlite3.connect('/home/pi/temperatures.db')
      c = conn.cursor()
      c.execute("select recordtime, temperature from temps where recordtime in (select  max(recordtime) from temps)")
      record = c.fetchone()
      c.close()
      tempstring = str(round(float(record[1]),1))
      draw.text((20, 110), tempstring,(242,242,242),font=font)

      img.save('latest_temperature.jpg')
      img.show()
      time.sleep(60)
      call(["sudo", "pkill", "display"])

# debug, print events
main()

temp.py

Python
This program runs on the Intel Edison board. Every 10 seconds, it reads the temperature and sends it via a URL post to the kitchen appliance.
#!/usr/bin/env python

import mraa
import sys
import math
import time
import urllib2
import urllib


B = 3975
pot = mraa.Aio(0)

while 1:
   a = float(pot.read())
   resistance=(float)(1023-a)*10000/a; #get the resistance of the sensor;   
# sensor needs calibration.  The addition of 15 degrees is aproximate
   celsius=(1/(math.log(resistance/10000)/B+1/298.15)-273.15)+15; #convert to temperature
   farenheit = ((celsius * 9) / 5) + 32
#   print farenheit 
   query_args = { 'temperature':'location' }

   url = 'http://10.1.15.188/temp?temperature=' + str(farenheit) + '&location=den'

   data = urllib.urlencode(query_args)

   request = urllib2.Request(url, data)

   response = urllib2.urlopen(request).read()

   print response

   time.sleep(10)

Credits

Michael Lass

Michael Lass

1 project • 1 follower
Ralph

Ralph

1 project • 0 followers
Progrmmer, embedded electronics hacker

Comments