Example #1
0
    /// <summary>
    /// <para>Adds a Servo change of state to the database based on the room it belongs.</para>
    /// </summary>
    /// <param name="servo">Servo serialized object in JSON</param>
    /// <param name="roomName">Room where the measurement was taken.</param>
    public void persistServo(string servo, string roomName)
    //persist means adding to the database
    {
        Servo        servoObject;
        LoraReceiver lora = new LoraReceiver();

        try
        {
            servoObject = JsonSerializer.Deserialize <Servo>(servo);
            _context.Servo.Add(servoObject);
            Room r = getRoomByName(roomName);
            _context.SaveChanges();
            ServoList list = new ServoList();
            list.SERV_ID = servoObject.SERV_ID;
            list.ROOM_ID = r.RoomID;
            _context.Servos.Add(list);
            _context.SaveChanges();

            Packet packet3 = new Packet();
            packet3.cmd       = "tx";
            packet3.EUI       = "0004A30B00259F36";
            packet3.port      = 1;
            packet3.data      = "AABBCCDD";
            packet3.confirmed = false;
            lora.SendPacket(packet3);
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            throw new Exception("JSON is corrupt");
        }
    }
Example #2
0
        public static void Main(string[] args)
        {
            LoraReceiver loraReceiver = new LoraReceiver();

            CreateHostBuilder(args).Build().Run();
        }