osd-contiki/examples/osd/arduino-climate/sketch.pde

73 lines
1.9 KiB
Plaintext
Raw Permalink Normal View History

2017-09-12 16:28:05 +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.
*/
#include <Wire.h>
#include "Adafruit_HTU21DF.h"
extern "C" {
#include "arduino-process.h"
#include "rest-engine.h"
2017-09-20 11:17:46 +02:00
#include "net/netstack.h"
#include "serial-shell.h"
#include "shell-merkur.h"
2017-10-16 16:01:43 +02:00
#include "ota-update.h"
2017-09-12 16:28:05 +02:00
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
extern resource_t res_htu21dtemp, res_htu21dhum, res_battery;
float htu21d_hum;
float htu21d_temp;
char htu21d_hum_s[8];
char htu21d_temp_s[8];
#define LED_PIN 4
}
void setup (void)
{
// switch off the led
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
2017-09-20 11:17:46 +02:00
// Seriell Shell
serial_shell_init();
shell_merkur_init();
2017-09-12 16:28:05 +02:00
// htu21d sensor
if (!htu.begin()) {
printf("Couldn't find sensor!");
}
// init coap resourcen
rest_init_engine ();
2017-10-16 16:01:43 +02:00
OTA_ACTIVATE_RESOURCES();
2017-09-12 16:28:05 +02:00
#pragma GCC diagnostic ignored "-Wwrite-strings"
rest_activate_resource (&res_htu21dtemp, "s/temp");
rest_activate_resource (&res_htu21dhum, "s/hum");
rest_activate_resource (&res_battery, "s/battery");
#pragma GCC diagnostic pop
2017-09-20 14:17:26 +02:00
mcu_sleep_set(128); // Power consumtion 278uA; average over 20 minutes
2017-09-12 16:28:05 +02:00
}
// at project-conf.h
// LOOP_INTERVAL (30 * CLOCK_SECOND)
void loop (void)
{
2017-09-20 11:17:46 +02:00
2017-09-12 16:28:05 +02:00
htu21d_temp = htu.readTemperature();
htu21d_hum = htu.readHumidity();
dtostrf(htu21d_temp , 0, 2, htu21d_temp_s );
dtostrf(htu21d_hum , 0, 2, htu21d_hum_s );
// debug only
2017-09-20 11:17:46 +02:00
// printf("Temp: '%s'",htu21d_temp_s);
// printf("\t\tHum: '%s'\n",htu21d_hum_s);
2017-09-12 16:28:05 +02:00
}