public void InitHardware() { Console.WriteLine("Creating output ports..."); sensor = new TMP102(Device.CreateI2cBus()); sensor.Updated += Sensor_Updated; }
public async void Run(IBackgroundTaskInstance taskInstance) { // // TODO: Insert code to start one or more asynchronous methods // BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); this.tmp102 = new TMP102(); // set and open the IoT client if (this.iotClient == null) { //this.iotClient = new IoTClient("raspberrypi2", Guid.NewGuid().ToString(), this.connectionString, this.eventHubEntity); this.iotClient = new IoTClientConnectTheDots("raspberrypi2", Guid.NewGuid().ToString(), this.connectionString, this.eventHubEntity); } if (!this.iotClient.IsOpen) { this.iotClient.Open(); } bool isOpened = await this.tmp102.OpenAsync(); IDictionary bag = new Dictionary <SensorType, float>(); while (true) { float temperature = tmp102.Temperature(); SensorType sensorType = SensorType.Temperature; if (!bag.Contains(sensorType)) { bag.Add(sensorType, temperature); } else { bag[sensorType] = temperature; } if ((this.iotClient != null) && (this.iotClient.IsOpen)) { this.iotClient.SendAsync(bag); } await Task.Delay(5000); } deferral.Complete(); }
public static void Main() { Debug.Print("TMP102 Polling Sample"); var tmp102 = new TMP102(updateInterval: 0); // // Read the TMP102 every second and display the temperature. // while (true) { tmp102.Update(); Debug.Print("Temperature: " + tmp102.Temperature.ToString("f2")); Thread.Sleep(1000); } }
public MainPage() { this.InitializeComponent(); this.tmp102 = new TMP102(); // set and open the IoT client if (this.iotClient == null) { //this.iotClient = new IoTClient("raspberrypi2", Guid.NewGuid().ToString(), this.connectionString, this.eventHubEntity); this.iotClient = new IoTClientConnectTheDots("raspberrypi2", Guid.NewGuid().ToString(), this.connectionString, this.eventHubEntity); } if (!this.iotClient.IsOpen) { this.iotClient.Open(); } // just to start without UI :-) this.btnStart_Click(null, null); }
public static void Main() { Debug.Print("TMP102 Interrupt Sample"); // // Create a new TMP102 object, check the temperature every // 1s and report any changes grater than +/- 0.1C. // var tmp102 = new TMP102(updateInterval: 1000, temperatureChangeNotificationThreshold: 0.1F); // // Hook up the interrupt handler. // tmp102.TemperatureChanged += (s, e) => { Debug.Print("Temperature: " + e.CurrentValue.ToString("f2")); }; // // Now put the main program to sleep as the interrupt handler // above deals with processing the sensor data. // Thread.Sleep(Timeout.Infinite); }
public async void Run(IBackgroundTaskInstance taskInstance) { var deferral = taskInstance.GetDeferral(); try { TMP102 temp = new TMP102(A0AddressSelect.GND); Task init = temp.OpenAsync(); init.Wait(); while (true) { float degree = temp.Temperature(); Debug.WriteLine(degree); await Task.Delay(500); } } finally { deferral.Complete(); } }