Latest revision as of 20:47, 22 October 2013

Contents

Introduction

The goal here is to add a web-based graphical display to your sensor. In exercises/realtime you will find examples of a node.js server that displays realtime data from the beagle.

boneServer.js

This is the server that works with the following clients.

ioPlot.js, ioPlot.html

This is an example that reads a gpio port and analog in and plots the output in a web browser. It also has buttons to control the built-in USR LEDS.

buttonBox.js, buttonBox.html

This is an example that reads a gpio port, analog in and and i2c device and plots the output in a web browser. It also has buttons to control the built-in USR LEDS and a slider to control a PWD controlled LED.

Running the code

Then point a browser to 192.168.7.2:8080. (The default port is 8080, but you can change it if you like just by editing boneServer.js.)

i2c

My buttonBox.js uses a very crude approach to i2c. I just call i2cget every time I want a value. There is lots of overhead in running i2cget each time. If you are using an i2c device, modify myi2cget.c (in exercises/i2c) to return the current value from your device every time the user hits return. Use this with your version of buttonBox.js to read your i2c device.

How it works

In my code the browser does a pull at a fixed time interval. That is, the function updateTop() sends the messages ain and gpio to the server and then sets a timer (setTimeout()) to send them again later. When the server receives a message, say ain, it reads the correct I/O and sends the data back via the ain message. When the browser receives the message it stores the value in the correct place in an array and tells the plotting routine to plot it.

Now, read the above paragraph with buttonBox.html (for the browser) and buttonBox.js (for the server) in front of you. Find the functions noted above and see what you can figure out.

Here's the challenge: Modify the code to do a push. That is, have the server set a timer and at a fixed interval send the data over to the browser.

Grading

If your solution uses my 'pull' code you will get at most 7 or 8 out of 10. If you are able to modify the code to do a 'push' you can get full credit.

If you are doing i2c the way I did it, you can get 7 or 8 out of 10, but if you made the change I request above, you can get full credit (without having to do the 'push').

In either case I suggest you get the easy case working first, then do the challenge.