From 53f0e0d58d9daffd3b217b1c6840ef9f53683749 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 8 Oct 2018 12:31:52 +0530 Subject: save details of the connected board --- sbhs/models.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sbhs/models.py b/sbhs/models.py index 34fdb7e..20c1158 100644 --- a/sbhs/models.py +++ b/sbhs/models.py @@ -32,6 +32,22 @@ class Board(models.Model): mid = models.IntegerField(unique=True) online = models.BooleanField(default=False) + usb_path = models.URLField(max_length=200, default="/dev/ttyUSB0") + raspi_path = models.URLField(max_length=200, default="localhost:8000") + + def save_board_details(self, raspi_ip, usb_mac_map): + for devices in usb_mac_map: + board = Board.objects.filter(mid=devices["sbhs_mac_id"]) + if board.exists(): + board = board.first() + else: + board = self + board.mid = devices["sbhs_mac_id"] + board.raspi_path = raspi_ip + board.usb_path = "/dev/ttyUSB{}".format(devices["usb_id"]) + board.online = True + board.save() + class Meta: ordering = ['mid',] -- cgit