summaryrefslogtreecommitdiffstats
path: root/src/main.cpp
blob: d8122a67e9fa840fd7079fbfd060798253420c76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <Arduino.h>
#include <Wire.h>
#include <DallasTemperature.h>
#include <DHT.h>
#include <stdlib.h>

// Pin setup
const int oneWirePin = 7;
const int dhtPin = 2;
#define DHTTYPE DHT22

#define BUFSIZE 32

OneWire oneWire(oneWirePin);
DallasTemperature sensors(&oneWire);
DHT dht(dhtPin, DHTTYPE);

void setup () {
	Serial.begin(9600);
	dht.begin();
}

void loop () {
	sensors.requestTemperatures();

	float t1 = sensors.getTempCByIndex(0);

	float t2 = dht.readTemperature();
	float h1 = dht.readHumidity();

	char temp[BUFSIZE];

	// format: <timestamp|0> t:1=<temp> t:2=<temp> h:1=<humidity>
	String line = "";
	line += 0;

	line += " t:1=";
	dtostrf(t1, 5, 2, temp);
	line += temp;

	line += " t:2=";
	dtostrf(t2, 5, 2, temp);
	line += temp;

	line += " h:1=";
	dtostrf(h1, 5, 2, temp);
	line += temp;


	Serial.println(line);
	delay(10000);
}