예제 #1
0
        //Simulate DEVICE feed
        public static string SendDevicesToCloudNonAsync(int timeout = -1)
        {
            DeviceTelemetry deviceDataChunk = new DeviceTelemetry();

            while (timeout < 0)
            {
                outputItems++;
                //Arbitrary simulations
                deviceDataChunk.setDeviceTelemetry(
                    rand.NextDouble() * 5 + 15,
                    rand.NextDouble() * 5,
                    Math.Round(rand.NextDouble() * 25000),
                    Math.Round(rand.NextDouble() * 15000),
                    rand.NextDouble() * 0.015
                    );
                // Create JSON message
                var messageStringFromNestedClass = JsonConvert.SerializeObject(deviceDataChunk, Formatting.Indented);
                Console.WriteLine("{0} > Sending message: {1}", DateTime.Now, messageStringFromNestedClass);
                //Insert(Upsert) into database
                if (couchbaseConnectionInitialised)
                {
                    Console.WriteLine("Upsert: {0}", UpsertNoSQL(deviceDataChunk.dID.ToString(), deviceDataChunk));
                }
                //Just some fancy screen stuff
                //if (outputItems % 10 == 0)
                //    Console.Clear();
                //This was for async version
                //await Task.Delay(1000);
                // Sleep for x seconds
                System.Threading.Thread.Sleep(SimulationSpeed);
            }
            return(JsonConvert.SerializeObject(deviceDataChunk, Formatting.Indented));
        }