Django Server Development - magnus-haw/radioSensors GitHub Wiki

Overview

All sensor systems need a framework for data collection, storage and access. The modern standard for this is a computer server which stores information in a database and provides a web portal (RESTful service, web socket etc.) for data access.

The typical alternatives for sensor data are storing information in text files/spreadsheets on a hard drive. This generally leads to less organization and documentation of data but is simpler to implement.

Modern web frameworks, such as Django, provide a convenient and flexible option for data collection, storage, and access. We will use Django to develop a lightweight data system for the radio sensor network. This application will serve 2 primary functions: 1) listening and storing sensor data in a database, and 2) providing a web portal to access the data.

The construction of this app is broken down into several steps as described below.

Basic Server framework

To learn the basics of the Django web framework we will first develop a simple webpage which displays a temperature measurement without including a database. The following tutorials are provided to familiarize oneself with the Django framework.

Tutorials:

Tasks:

  • Develop python functions to acquire sensor data
  • Develop barebones Django view able to serve a webpage
  • Write python function capable of acquiring sensor data
  • Show acquired sensor data on webpage

Adding database and defining a schema

The next step is to define a data schema and save the collected measurements into a database. We will be using a SQLite database and use the Django object-relation-mapper (ORM). This ORM provides a python api for accessing the database so you don't have to use/learn SQL/SQLite in detail (so don't spend too much time on the SQL/SQLite tutorials).

Tutorials:

Tasks:

  • Come up with a database schema for arbitrary types of sensors & sensor data
  • Implement the schema using Django models

Adding a web service for data upload/extraction

The last step is adding the ability to retrieve data using url query patterns: e.g. https://locallhost:5000/?name=myexperiment&sensor=tmp1 This will create functions which can retrieve specific information from the database. This can be done with standard Django views or using the Django REST framework.

Tutorials:

Tasks:

  • Design a query interface for the database schema developed in the previous step
  • Determine what control features are of interest besides data retrieval