mirror of
https://github.com/daniviga/bite.git
synced 2024-12-24 17:21:25 +01:00
Daniele Viganò
a7cebefbf5
* Add MQTT support on Arduino * Add MQTT simulator * Use a single python simulator * Minor improvements to dockerfiles * Add transport internal field to telemetry * Add PubSubClient
25 lines
781 B
Python
25 lines
781 B
Python
from django.db import models
|
|
from django.core.validators import MinValueValidator
|
|
from django.contrib.postgres.fields import JSONField
|
|
|
|
from api.models import Device
|
|
|
|
|
|
class Telemetry(models.Model):
|
|
device = models.ForeignKey(Device, on_delete=models.CASCADE)
|
|
time = models.DateTimeField(primary_key=True, auto_now_add=True)
|
|
transport = models.CharField(max_length=4,
|
|
choices=[('http', 'http'), ('mqtt', 'mqtt')],
|
|
default='http')
|
|
clock = models.IntegerField(
|
|
validators=[MinValueValidator(0)],
|
|
null=True)
|
|
payload = JSONField()
|
|
|
|
class Meta:
|
|
ordering = ['-time', 'device']
|
|
verbose_name_plural = "Telemetry"
|
|
|
|
def __str__(self):
|
|
return str(self.time)
|