IoT

Programming a Tessel Camera App with JavaScript

0 MIN READ • Feb 24, 2015

board_camThe Tessel board is an awesome little machine. It allows you to program hardware with JavaScript, and includes a ton of cool modules that can be implemented for a wide variety of applications.

One of those modules is the Tessel camera. This enables you to take your own board, capture images, and publish photos to a real-time picture feed (part two).

In this blog post, we'll get you started programming your Tessel camera app with JavaScript, which will allow you to take photos with your microcontroller. So let's get started!

Installing the Tessel Camera Module

First let’s get set up. Clone the contents of the pubnub-tessel directory and following the instructions written on the page.

1.txt
git clone https://github.com/pubnub/pubnub-tessel

After following the instructions from the link you should have a working Tessel board, which is connected to your WiFi. The manufacturer recommends that you only switch modules after unplugging the board. Unplug the board and attach the camera module to the “B” socket on the board.

Plug in the board to power it on. Type tessel wifi -l, to make sure the board is connected to your preferred WiFi network.

Next you need to install the package for the camera. At the time of this entry the camera is vc0706. The software can be viewed here. The source page also provides a code example of uploading the image to a directory.

Install the software using npm.

2.txt
npm install camera-vc0706

Running the Code

The next step is running the code. Navigate to /projects/streaming-camera. This is the source code. In this directory you will use the camera-server.js.

For the purposes of testing a one-time message you may want to consider removing the setInterval function. The code will work either way, this is just based on preference.

Use the camera-server.coffee file to edit.

After calling package requirements and setting the notification LED, the device is set on.

3.js
camera.on 'ready', () ->
  PUBNUB = require("pubnub").init {
    publish_key: "demo",
    subscribe_key: "demo",
    uuid: uuid
  }
  console.log("camera ready")

Sender

This is where the device functions can be called.

4.js
camera.takePicture (err, image) ->
      if err
        console.log('error taking image', err)
      else
        notificationLED.low()
        console.log "sending image"
        PUBNUB.publish
          channel: channel
          message: {
            uuid: uuid
            ts: new Date().toISOString()
            image:images/ dataurl.format({
              data: image
              mimetype: "image/jpg"
            })
          }
          callback: -> console.log "image sent"

These are the messages that tell us the server side is working.

send_img

Receiver

In a separate terminal, use the example in /examples/pubnub_debug_listen.js

5.txt
node pubnub_debug_listen.js tesseldemo

This is the message, which tells us the code is working on the client side.

msg_sent

Now if we add the setInteval back into the code, we see what happens on repeat.

send_msg

Everytime the code sends a message, you can see it received in the client-side code. If you’re interested in creating a real-time camera feed, where photos are streamed in real time, check out part two of our series!

tessel camera app

IoT
May 21, 2015

Remote Control and Monitoring for Tessel Servo | PubNub

This tutorial shows you how to remote control your Tessel Servo remotely and track the Tessel Servo movement and current position in real time.
Michael Carroll
Michael Carroll
IoT
May 21, 2015

Acting On Tessel RFID Events with Tessel RFID Module | PubNub

How to receive a Tessel RFID event and act on it, triggering an action in real time. We'll receive and interpret RFID events, & match it against code.
Michael Carroll
Michael Carroll
May 19, 2015

Sending RFID Events in Real time w/ Tessel RFID Module

In this part, we'll use the Tessel to detect a Tessel RFID module scan and send the information in real time to trigger an action.
Michael Carroll
Michael Carroll