Esempio n. 1
0
int main() {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Humidity h;
	humidity_create(&h, UID, &ipcon); 

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

	// Set Period for humidity callback to 1s (1000ms)
	// Note: The callback is only called every second if the 
	//       humidity has changed since the last call!
	humidity_set_humidity_callback_period(&h, 1000);

	// Register humidity callback to function cb_humidity
	humidity_register_callback(&h,
	                           HUMIDITY_CALLBACK_HUMIDITY,
	                           (void *)cb_humidity,
	                           NULL);

	printf("Press key to exit\n");
	getchar();
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
}
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Humidity h;
	humidity_create(&h, 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

	// Get threshold callbacks with a debounce time of 10 seconds (10000ms)
	humidity_set_debounce_period(&h, 10000);

	// Register humidity reached callback to function cb_humidity_reached
	humidity_register_callback(&h,
	                           HUMIDITY_CALLBACK_HUMIDITY_REACHED,
	                           (void *)cb_humidity_reached,
	                           NULL);

	// Configure threshold for humidity "outside of 30 to 60 %RH"
	humidity_set_humidity_callback_threshold(&h, 'o', 30*10, 60*10);

	printf("Press key to exit\n");
	getchar();
	humidity_destroy(&h);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
Esempio n. 3
0
int main() {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	Humidity h;
	humidity_create(&h, UID, &ipcon); 

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

	// Get current humidity (unit is %RH/10)
	uint16_t humidity;
	if(humidity_get_humidity(&h, &humidity) < 0) {
		fprintf(stderr, "Could not get value, probably timeout\n");
		exit(1);
	}

	printf("Relative Humidity: %f %%RH\n", humidity/10.0);

	printf("Press key to exit\n");
	getchar();
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
}