int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	AmbientLightV2 al;
	ambient_light_v2_create(&al, UID, &ipcon);

	// Connect to brickd
	if(ipcon_connect(&ipcon, HOST, PORT) < 0) {
		fprintf(stderr, "Could not connect\n");
		return 1;
	}
	// Don't use device before ipcon is connected

	// Register illuminance callback to function cb_illuminance
	ambient_light_v2_register_callback(&al,
	                                   AMBIENT_LIGHT_V2_CALLBACK_ILLUMINANCE,
	                                   (void *)cb_illuminance,
	                                   NULL);

	// Set period for illuminance callback to 1s (1000ms)
	// Note: The illuminance callback is only called every second
	//       if the illuminance has changed since the last call!
	ambient_light_v2_set_illuminance_callback_period(&al, 1000);

	printf("Press key to exit\n");
	getchar();
	ambient_light_v2_destroy(&al);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
TinkerforgeSensors::~TinkerforgeSensors()
{
  bool is_ipcon = false;
  // clean up tf devices
  while(!sensors.empty())
  {
    SensorDevice *dev = sensors.front();
    switch (dev->getType())
    {
      case AMBIENT_LIGHT_DEVICE_IDENTIFIER:
        ambient_light_destroy((AmbientLight*)dev->getDev());
      break;
      case AMBIENT_LIGHT_V2_DEVICE_IDENTIFIER:
        ambient_light_v2_destroy((AmbientLightV2*)dev->getDev());
      break;
      case DISTANCE_IR_DEVICE_IDENTIFIER:
        distance_ir_destroy((DistanceIR*)dev->getDev());
      break;
      case DISTANCE_US_DEVICE_IDENTIFIER:
        distance_us_destroy((DistanceUS*)dev->getDev());
      break;
      case DUAL_BUTTON_DEVICE_IDENTIFIER:
        dual_button_destroy((DualButton*)dev->getDev());
      break;
      case GPS_DEVICE_IDENTIFIER:
        gps_destroy((GPS*)dev->getDev());
      break;
      case IMU_DEVICE_IDENTIFIER:
        imu_leds_off((IMU*)dev->getDev());
        imu_destroy((IMU*)dev->getDev());
      break;
      case IMU_V2_DEVICE_IDENTIFIER:
        imu_v2_leds_off((IMUV2*)dev->getDev());
        imu_v2_destroy((IMUV2*)dev->getDev());
      break;
      case TEMPERATURE_DEVICE_IDENTIFIER:
        temperature_destroy((Temperature*)dev->getDev());
      break;
    }
    delete dev;
    sensors.pop_front();
    is_ipcon = true;
  }
  if (is_ipcon)
  {
    ipcon_destroy(&ipcon);
  }
}