Let's Get Physical

with Django

Physical Computing

Building stuff that interacts with the real world.

 

Internet of Things (IoT)

 

Sensors + Smarts + Connectivity

"Something, Something, Something, Dark side"

Picamera

# -*- coding: utf-8 -*-
import io
import time
import picamera

def capture_image():
    data = io.BytesIO()
    with picamera.PiCamera(resolution=(800, 600), framerate=10) as camera:
        time.sleep(1)  # Camera warm-up time
        camera.rotation = 270
        camera.capture(data, 'jpeg')
    data.seek(0)
    return data

REST API

# -*- coding: utf-8 -*-
import base64

from rest_framework import views
from rest_framework.response import Response
from .. import camera


class ImageAPIView(views.APIView):
    http_method_names = ['get']

    def get(self, request, *args, **kwargs):
        data = camera.capture_image()
        return Response({
            'img': "data:image/png;base64,{}".format(
                base64.b64encode(data.getvalue())
            )
        })

Potential?

Why Use Django?

For

  • Secure & reliable
  • Excellent range of packages
  • Prior experience

 

 

Against

  • Fairly heavy weight
  • HTTP vs Real-time
  • Needs a full OS*
  • Cost

* sort of

Resin.io

  • DevOps for Devices
  • Is like Heroku or Elastic Beanstalk for physical devices
  • Supports:
    • Raspberry Pi (1+2)
    • BeagleBone Black
    • Intel Edison
    • ... and others
  • Git push to build and deploy to multiple devices
  • Monitoring

How it works

Image Credits

Further Reading

Let's get Physical

By Jonathan Moss

Let's get Physical

A quick intro to Physical Computing with Django and a Raspberry Pi

  • 540