コード例 #1
0
ファイル: LoriotWebsocket.cs プロジェクト: Raolf/Webservice
        public void SendMessage(Sensor sensor)
        {
            LoriotDTO msg = new LoriotDTO();

            msg.cmd       = "tx";
            msg.EUI       = sensor.sensorEUID;
            msg.data      = sensor.servoSetting;
            msg.port      = 3;
            msg.confirmed = false;
            clientWS.Send(JsonConvert.SerializeObject(msg));
            Console.WriteLine("Message sent");


            var log = new SensorLog();

            sensor = _context.Sensor.AsQueryable().First(s => s.sensorEUID == sensor.sensorEUID);

            log.servoSetting = sensor.servoSetting;
            log.timestamp    = DateTime.Now;

            log.sensorID = sensor.sensorID;

            slc.PostSensorLog(log).Wait();
            _context.SaveChanges();
        }
コード例 #2
0
ファイル: LoriotWebsocket.cs プロジェクト: Raolf/Webservice
        public void setupMessageRecieve(WebsocketClient client)
        {
            client.MessageReceived.Subscribe(json =>
            {
                Console.WriteLine("Message recieved.\n");
                LoriotDTO loraData = JsonConvert.DeserializeObject <LoriotDTO>(json.ToString());

                if (loraData.cmd == "rx")
                {
                    Models.Data data = HexIntoData(loraData.data);                                                                   //LoraData.data is a hex string, data is the webservices data class.
                    data.timestamp   = new DateTime(1970, 1, 1, 2, 0, 0, DateTimeKind.Local).AddSeconds((double)loraData.ts / 1000); //Could be improved.
                    Console.WriteLine("Date is: " + data.timestamp + "\n");
                    data.sensorEUID = loraData.EUI;
                    Task.Run(() => Save(data));
                }
                else
                {
                    Console.WriteLine("Command was not rx");
                }
            });
        }