Exemple #1
0
        private static void client_Received(Client sender, byte[] rawData)
        {
            // Backup demo option:
            // createPacketDemo(sender, rawData);
            string decodedString = Encoding.UTF8.GetString(rawData);
            ReturnPacket packet = DemoDeserializer.DeserializeJSON(decodedString);

            for (int k = 0; k < packet.data.Length; k++)
            {
                ReturnSensor currentdata = packet.data[k];

                // DateTime rdt = currentdata.ReadTime;
                DateTime rdt = DateTime.Now;

                // DateTime pdt = currentdata.PollTime;
                DateTime pdt = DateTime.Now;
                if (currentdata.Humidity != -1)
                {
                    helper.InsertSensorData(1, 1, currentdata.Humidity.ToString(), rdt, pdt, 5);
                    Console.WriteLine("Inserted Humidity: " + currentdata.Humidity.ToString() + " polled at: " + rdt);
                }

                if (currentdata.Pressure != -1)
                {
                    helper.InsertSensorData(1, 1, currentdata.Pressure.ToString(), rdt, pdt, 7);
                    Console.WriteLine("Inserted Pressure: " + currentdata.Pressure.ToString() + " polled at: " + rdt);
                }

                if (currentdata.Temperature != -1)
                {
                    helper.InsertSensorData(1, 1, currentdata.Temperature.ToString(), rdt, pdt, 9);
                    Console.WriteLine(
                        "Inserted Temperature: " + currentdata.Temperature.ToString() + " polled at: " + rdt);
                }

                if (currentdata.EntityCount != -1)
                {
                    helper.InsertSensorData(3, 1, currentdata.EntityCount.ToString(), rdt, pdt, 0);
                    Console.WriteLine(
                        "Inserted EntityCount: " + currentdata.Temperature.ToString() + " polled at: " + rdt);
                }

                if (packet.data[k].EntityPositions != null)
                {
                    for (int h = 0; h < currentdata.EntityPositions.Length; h++)
                    {
                        Position currentposition = currentdata.EntityPositions[h];
                        if (currentposition.X != -1 && currentposition.Y != -1 && currentposition.Depth != -1)
                        {
                            string s_pos = currentposition.X.ToString() + "," + currentposition.Y.ToString() + ","
                                                                        + currentposition.Depth.ToString();
                            helper.InsertSensorData(3, 1, s_pos, rdt, pdt, 1);
                            Console.WriteLine("Inserted Position: " + s_pos + " polled at: " + rdt);
                        }
                    }
                }

                if (currentdata.AnalogLight != -1)
                {
                    helper.InsertSensorData(1, 1, currentdata.AnalogLight.ToString(), rdt, pdt, 3);
                    Console.WriteLine("Inserted Light: " + currentdata.AnalogLight.ToString() + " polled at: " + rdt);
                }
            }
        }
Exemple #2
0
 private static void l_SocketAccepted(Socket e)
 {
     Console.WriteLine("Connection established!");
     Client client = new Client(e);
     client.Received += client_Received;
     client.Disconnected += client_Disconnected;
 }
Exemple #3
0
 private static void client_Disconnected(Client sender)
 {
 }
Exemple #4
0
        private static void createPacketDemo(Client sender, byte[] rawData)
        {
            char[] delimiter = new[] { ',' };
            string[] decodedData = Encoding.UTF8.GetString(rawData).Split(delimiter);

            if (decodedData[1] != "0" && decodedData[1] != "0.0")
            {
                DateTime dt = DateTime.Now;
                helper.InsertSensorData(1, 1, decodedData[1], dt, dt, 3);

                // 3 for LightSensor (Note: humid: 5, pressure: 7, temp: 9)
                Console.WriteLine(
                    "Message from {0}:\nAnalogLight: {1}\nPolled at: {2}\n", sender.ID, decodedData[1], dt);
            }
            else if ((decodedData[3] != "0" && decodedData[3] != "0.0")
                     || (decodedData[4] != "0" && decodedData[4] != "0.0")
                     || (decodedData[5] != "0" && decodedData[5] != "0.0"))
            {
                DateTime dt = DateTime.Now;
                helper.InsertSensorData(1, 1, decodedData[3], dt, dt, 5);
                helper.InsertSensorData(1, 1, decodedData[4], dt, dt, 7);
                helper.InsertSensorData(1, 1, decodedData[5], dt, dt, 9);
                Console.WriteLine(
                    "Message from {0}:\nHumidity: {2}\nPressure: {3}\nTemperature: {4}\nPolled at: {1}\n",
                    sender.ID,
                    dt,
                    decodedData[3],
                    decodedData[4],
                    decodedData[5]);
            }
        }