Skip to content
This repository has been archived by the owner on Jan 21, 2023. It is now read-only.

Commit

Permalink
added dataset from lecture 2
Browse files Browse the repository at this point in the history
  • Loading branch information
joemarshall committed Oct 14, 2015
1 parent 50fa12f commit dab784d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
4 changes: 2 additions & 2 deletions customserver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# if you run this on a PI, it will output analogread 0 and analogread 1 in a webserver that can be accessed by the emulator at http:https://pi-ip-address:23456/
# can use this to put PI data straight into code running in an emulator
# can use this to put PI data straight into code running in an emulator, or to make your own sensor box just like the sensor boxes that we have in A32

import BaseHTTPServer
import time
Expand All @@ -12,7 +12,7 @@ def do_GET(self):
self.send_response(200)
self.send_header("Update-Rate","25")
self.end_headers()
self.wfile.write("timestamp,snd,light\n%d,%d,%d"%(time.time(),grovepi.analogRead(0),grovepi.analogRead(1)))
self.wfile.write("timestamp,sound,light,temperature\n%d,%d,%d,%d\n"%(time.time(),grovepi.analogRead(0),grovepi.analogRead(2),grovepi.analogRead(1)))

def log_request(self,code=None,size=None):
None
Expand Down
47 changes: 31 additions & 16 deletions plotdata.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,89 @@
# run this in the emulator to plot data from the emulated grovepi
# run this in the emulator to plot data from the emulated grovepi
# or run it standalone to get data from a remote grovepi

import wx
import collections
import threading
import sys


class DrawPanel(wx.Frame):

def __init__(self,width=600,height=512):
wx.Frame.__init__(self, None,title="Draw on Panel")
def __init__(self):
wx.Frame.__init__(self, None,title="Sensor Graphs",size=(600,540+270))
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_TIMER, self.OnTimer)
self.bufferSnd=collections.deque(maxlen=500)
self.bufferLight=collections.deque(maxlen=500)
self.bufferTemperature=collections.deque(maxlen=500)
self.xPos=0
self.addPoint(0,0)
self.addPoint(0,0,0)
self.timer=wx.Timer(self,1)
self.timer.Start(10)

def addPoint(self,snd,light):
self.bufferSnd.append((self.xPos,int(snd/4)))
self.bufferLight.append((self.xPos,int(light/4)))
def addPoint(self,snd,light,temperature):
self.bufferSnd.append((self.xPos,256-int(snd/4)))
self.bufferLight.append((self.xPos,256-int(light/4)))
self.bufferTemperature.append((self.xPos,256-int(temperature/4)))
self.lastSnd=snd
self.lastLight=light
self.lastTemp=temperature
self.xPos+=1
curWidth=self.GetClientSizeTuple()[0]
if self.bufferSnd.maxlen!=curWidth:
self.bufferSnd=collections.deque(self.bufferSnd,maxlen=curWidth)
self.bufferLight=collections.deque(self.bufferLight,maxlen=curWidth)
self.bufferTemperature=collections.deque(self.bufferTemperature,maxlen=curWidth)
self.Refresh(False)

def OnTimer(self, event=None):
if REMOTE_ADDRESS==None:
# reading from a (emulated) grovepi
# reading from an emulated grovepi
snd=grovepi.analogRead(0)
light=grovepi.analogRead(1)
self.addPoint(snd,light)
temperature=grovepi.analogRead(1)
light=grovepi.analogRead(2)
self.addPoint(snd,light,temperature)
else:
# running standalone, read from http server
resp=urllib2.urlopen(REMOTE_ADDRESS,timeout=1)
header=resp.readline().split(",")
srcvals=resp.readline().split(",")
header=resp.readline().rstrip("\n").split(",")
srcvals=resp.readline().rstrip("\n").split(",")
values={}
for key,val in zip(header,srcvals):
try:
values[key]=int(val)
except ValueError:
values[key]=float(val)
self.addPoint(values["sound"],values["light"])
self.addPoint(values["sound"],values["light"],values["temperature"])

def OnPaint(self, event=None):
dc = wx.PaintDC(self)
dc.Clear()
dc.SetPen(wx.Pen(wx.BLACK, 1))
dc.DrawLines(self.bufferSnd,xoffset=-self.bufferSnd[0][0],yoffset=0)
dc.DrawLines(self.bufferLight,xoffset=-self.bufferLight[0][0],yoffset=270)
dc.DrawText("Sound",0,0)
dc.DrawText("Light",0,270)
dc.DrawLines(self.bufferTemperature,xoffset=-self.bufferLight[0][0],yoffset=540)
dc.DrawText("Sound:%d"%self.lastSnd,0,0)
dc.DrawText("Light:%d"%self.lastLight,0,270)
dc.DrawText("Temperature:%d"%self.lastTemp,0,540)

def initPanel():
frame = DrawPanel()
frame.Show()

if threading.current_thread().name == 'MainThread':
# we're not in the emulator
import urllib2
REMOTE_ADDRESS = "http:https://www.cs.nott.ac.uk/~pszjm2/sensordata/?id=1"
if len(sys.argv)>1:
REMOTE_ADDRESS=sys.argv[1]
else:
REMOTE_ADDRESS = "http:https://www.cs.nott.ac.uk/~pszjm2/sensordata/?id=1"

app = wx.App(False)
initPanel()
app.MainLoop()
else:
# we're in the emulator
REMOTE_ADDRESS=None
import grovepi
wx.CallAfter(initPanel)
Binary file added sensors2/l7material.xlsx
Binary file not shown.

0 comments on commit dab784d

Please sign in to comment.