开发者

Django data logging front end - phidgets

What would the best method be to use Django for creating an application similar to say OpenNMS or any comparable network management tool?

The Django app needs to be constantly polling 1 or more devices, with each device having 1 or more analog and digital inputs.

Basically, how do you integrate the necessary polling functions into a django app, so that when the device(s) sensor(s) are polled, the resulting value is stored in the Django ORM so that the user can then pull up graphs, charts, etc of the data it is logging?

Is Django not the right base for something like this? The embedded devices I am polling has python APIs to set events handlers or just poll the objects current reading if needed. (http://www.phidgets.com)

The end goal is that this Django site resides on the PhidgetSBC and can then be easily accessed and controlled via the network. The polling and storing of the sensor values needs to be running 24/7, unless specifically disabled by the web user via a "device admin area" on the Django site for instance.

I am not worried about charting, controlling devices on the output pins, etc at this time as getting the data into the database reliably is top priority. I don't think the current python package I created开发者_运维技巧 is going to port over to Django well, so I would rather start from scratch and start it right.

Thanks


How you handle data logging really depends on how you want to present the data. However, unless you are only interested in a real time display (i.e. no charting), whatever code which is responsible for the logging will have to run outside the HTTP request/response cycle, and therefore outside of Django.

Probably the most straightforward approach would be to write a separate python script that would run in the background, which would periodically poll the phidget API and dump the data into the DB. A potential major problem with this approach is that the sensor configuration is essentially hard-coded - if you wish to add or remove a sensor, you'll have to change the python script. This may or may not be important to your application.

In order to better integrate the data retrieved by the script into Django, you might create a few models like this:

class Device(models.Model):
    """A sensor"""
    name = models.CharField(max_length=20)
    ...

class DataPoint(models.Model):
    value = models.DecimalField(decimal_places=2, max_digits=10) # whatever is appropriate
    timestamp = models.DateTimeField()
    device = models.ForiegnKey(Device)

When you run syncdb, you can see the table names that will be created. It should be something like:

appname_device
appname_data_point

Your background script would then create records in the appname_data_point table, which would then be accessible via the Django ORM.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜