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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
| #include <InfluxDb.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#elif defined(ESP32)
#include <WiFi.h>
#include <WiFiMulti.h>
#endif
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
const char* ssid = "draadlozewifissid";
const char* password = "haha nee echt niet dit paswoord hoor";
DeviceAddress tempDeviceAddress;
void setup(void)
{
Serial.begin(38400);
sensors.begin();
WiFi.begin(ssid, password); // Connect to the network
Serial.print("Connecting to ");
Serial.print(ssid); Serial.println(" ...");
int i = 0;
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
delay(1500);
Serial.print(++i); Serial.print(' ');
}
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP());
#define INFLUXDB_URL "http://10.10.10.10:8087"
#define INFLUXDB_DB_NAME "test_esp"
}
void loop()
{
int serialno;
float sensor_corrections[30] = { -0.15, -0.21, 0.02, -0.16, 0.16, -0.07, -0.30, -0.11, 0.02, 0.48, 0.29, 0.42, 0.06, -0.52, -0.24, 0.30, 0.23, 0.05, -0.11, -0.85, -0.21, 0.25, 0.46, -0.31, -0.08, 0.40, 0.04, -0.03, 0.05, -0.12};
float sensor_corrected_value[30] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Serial.print(" Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperature readings
Serial.println("Correcting Sensors ...");
for (int i = 0; i < sizeof sensor_corrections / sizeof sensor_corrections[0]; i++) {
sensor_corrected_value[i] = sensors.getTempCByIndex(i) - sensor_corrections[i];
delay(1);
}
InfluxDBClient client(INFLUXDB_URL, INFLUXDB_DB_NAME);
// Define data point with measurement name 'device_status`
Point pointDevice("Temperaturen_collector_vloerverwarming");
// Set tags
pointDevice.addTag("device", "ESP8266");
// Add data
pointDevice.addField("Aanvoer hoofdleiding", sensor_corrected_value[28]);
pointDevice.addField("Afvoer hoofdleiding", sensor_corrected_value[28]);
pointDevice.addField("Aanvoer Living 1", sensor_corrected_value[0]);
pointDevice.addField("Aanvoer Living 2", sensor_corrected_value[1]);
pointDevice.addField("Aanvoer Living 3", sensor_corrected_value[2]);
pointDevice.addField("Aanvoer Living 4", sensor_corrected_value[3]);
pointDevice.addField("Aanvoer Living 5", sensor_corrected_value[4]);
pointDevice.addField("Aanvoer Living 6", sensor_corrected_value[5]);
pointDevice.addField("Aanvoer Living 7", sensor_corrected_value[6]);
pointDevice.addField("Aanvoer Berging", sensor_corrected_value[7]);
pointDevice.addField("Aanvoer Traphal", sensor_corrected_value[8]);
pointDevice.addField("Aanvoer Man-cave 1", sensor_corrected_value[9]);
pointDevice.addField("Aanvoer Man-cave 2", sensor_corrected_value[10]);
pointDevice.addField("Aanvoer Gang-toilet", sensor_corrected_value[11]);
pointDevice.addField("Aanvoer Badkamer 1", sensor_corrected_value[12]);
pointDevice.addField("Aanvoer Badkamer 2", sensor_corrected_value[13]);
pointDevice.addField("Afvoer Living 1", sensor_corrected_value[14]);
pointDevice.addField("Afvoer Living 2", sensor_corrected_value[15]);
pointDevice.addField("Afvoer Living 3", sensor_corrected_value[16]);
pointDevice.addField("Afvoer Living 4", sensor_corrected_value[17]);
pointDevice.addField("Afvoer Living 5", sensor_corrected_value[18]);
pointDevice.addField("Afvoer Living 6", sensor_corrected_value[19]);
pointDevice.addField("Afvoer Living 7", sensor_corrected_value[20]);
pointDevice.addField("Afvoer Berging", sensor_corrected_value[21]);
pointDevice.addField("Afvoer Traphal", sensor_corrected_value[22]);
pointDevice.addField("Afvoer Man-cave 1", sensor_corrected_value[23]);
pointDevice.addField("Afvoer Man-cave 2", sensor_corrected_value[24]);
pointDevice.addField("Afvoer Gang-toilet", sensor_corrected_value[25]);
pointDevice.addField("Afvoer Badkamer 1", sensor_corrected_value[26]);
pointDevice.addField("Afvoer Badkamer 2", sensor_corrected_value[27]);
Serial.println("Committing data to database");
client.writePoint(pointDevice);
} |