2015-09-04 14:04:11 +02:00
|
|
|
/*
|
|
|
|
* Sample arduino sketch using contiki features.
|
|
|
|
* We turn the LED off
|
|
|
|
* We allow read the moisture sensor
|
|
|
|
* Unfortunately sleeping for long times in loop() isn't currently
|
|
|
|
* possible, something turns off the CPU (including PWM outputs) if a
|
|
|
|
* Proto-Thread is taking too long. We need to find out how to sleep in
|
|
|
|
* a Contiki-compatible way.
|
|
|
|
* Note that for a normal arduino sketch you won't have to include any
|
|
|
|
* of the contiki-specific files here, the sketch should just work.
|
|
|
|
*/
|
|
|
|
|
2015-09-11 15:10:28 +02:00
|
|
|
#include <Wire.h>
|
2015-09-11 21:41:24 +02:00
|
|
|
#include "Adafruit_HTU21DF.h"
|
2015-09-11 15:10:28 +02:00
|
|
|
|
2015-09-04 14:04:11 +02:00
|
|
|
extern "C" {
|
|
|
|
|
2015-09-11 21:41:24 +02:00
|
|
|
|
2015-09-04 14:04:11 +02:00
|
|
|
#include "rest-engine.h"
|
|
|
|
|
2015-09-11 21:41:24 +02:00
|
|
|
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
|
|
|
|
|
|
|
|
extern resource_t res_htu21dtemp, res_htu21dhum, res_battery;
|
|
|
|
|
|
|
|
float htu21d_hum;
|
|
|
|
float htu21d_temp;
|
2015-09-04 14:04:11 +02:00
|
|
|
|
|
|
|
#define LED_PIN 4
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup (void)
|
|
|
|
{
|
|
|
|
// switch off the led
|
|
|
|
pinMode(LED_PIN, OUTPUT);
|
|
|
|
digitalWrite(LED_PIN, HIGH);
|
2015-09-11 21:41:24 +02:00
|
|
|
// htu21d sensor
|
|
|
|
if (!htu.begin()) {
|
|
|
|
printf("Couldn't find sensor!");
|
|
|
|
}
|
2015-09-04 14:04:11 +02:00
|
|
|
// init coap resourcen
|
|
|
|
rest_init_engine ();
|
2015-09-11 21:41:24 +02:00
|
|
|
rest_activate_resource (&res_htu21dtemp, "s/temp");
|
|
|
|
rest_activate_resource (&res_htu21dhum, "s/hum");
|
2015-09-04 14:04:11 +02:00
|
|
|
rest_activate_resource (&res_battery, "s/battery");
|
|
|
|
}
|
|
|
|
|
2015-09-11 21:41:24 +02:00
|
|
|
// at project-conf.h
|
|
|
|
// LOOP_INTERVAL (10 * CLOCK_SECOND)
|
2015-09-04 14:04:11 +02:00
|
|
|
void loop (void)
|
|
|
|
{
|
2015-09-11 21:41:24 +02:00
|
|
|
htu21d_temp = htu.readTemperature();
|
|
|
|
htu21d_hum = htu.readHumidity();
|
|
|
|
printf("Temp: %f",htu21d_temp);
|
|
|
|
printf("\t\tHum: %f",htu21d_hum);
|
2015-09-04 14:04:11 +02:00
|
|
|
}
|