-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclima_exterior.ino
135 lines (95 loc) · 3.37 KB
/
clima_exterior.ino
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//Escrit íntegrament per Damià Sintes Roca a 18/01/2021.
//Llegir comentaris per Migjorn o Fornells.
//MIRAR CALIBRACiÓ PRESSiÓ ATMOSFÈRICA ABANS DE FLASHAR!!
#if defined(ESP32)
#include <WiFiMulti.h>
WiFiMulti wifiMulti;
#define DEVICE "ESP32"
#elif defined(ESP8266)
#include <ESP8266WiFiMulti.h>
ESP8266WiFiMulti wifiMulti;
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#define DEVICE "NAME _YOUR_DEVICE" //EDIT
#endif
#include <InfluxDbClient.h>
#include <InfluxDbCloud.h>
//Fornells
#define WIFI_SSID "+++YOUR_SSID+++" //EDIT
#define WIFI_PASSWORD "+++YOUR_WIFI_PASS+++" //EDIT
#define INFLUXDB_URL "http://YOUR_SERVER.com:8086" //EDIT
#define INFLUXDB_TOKEN "+++YOUR_INFLUX_TOKEN+++" //EDIT
#define INFLUXDB_ORG "+++YOUR_ORG+++" //EDIT
#define INFLUXDB_BUCKET "+++YOUR_BUCKET+++" //EDIT
#define TZ_INFO "CET-1CEST,M3.5.0,M10.5.0/3"
InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, InfluxDbCloud2CACert);
Point sensor("NAME_YOUR_SENSOR"); //EDIT
const uint8_t fingerprint[20] = {0xdf, 0xc2, 0x44, 0xa7, 0x73, 0x4c, 0x51, 0x9b, 0x8d0, 0x12, 0x55, 0xd2, 0xee, 0x19, 0xcc, 0x98, 0xf9, 0xe8, 0x26, 0xb1};
const int httpsPort = 443; //HTTPS= 443 and HTTP = 80
const char *host = "stations.windy.com";
const unsigned long eventInterval = 400000UL;
unsigned long previousTime = 0;
#include <BME280.h>
#include <EnvironmentCalculations.h>
#include <BME280I2C.h>
#include <Wire.h>
BME280I2C bme;
float pressio, temperatura, basca, hum_absoluta, humitat, rosada;
void wifi() {
// Setup wifi
WiFi.mode(WIFI_STA);
wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to wifi");
while (wifiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(100);
}
Serial.println();
// Add tags
sensor.addTag("device", DEVICE);
timeSync(TZ_INFO, "pool.ntp.org", "time.nis.gov");
if (client.validateConnection()) {
Serial.print("Connected to InfluxDB: ");
Serial.println(client.getServerUrl());
} else {
Serial.print("InfluxDB connection failed: ");
Serial.println(client.getLastErrorMessage());
}
}
void setup() {
Serial.begin(115200);
wifi();
Wire.begin();
while (!Serial) continue;
bme.begin();
}
void loop() {
float temp(NAN), hum(NAN), pres(NAN);
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_hPa);
bme.read(pres, temp, hum, tempUnit, presUnit);
EnvironmentCalculations::TempUnit envTempUnit = EnvironmentCalculations::TempUnit_Celsius;
float dewPoint = EnvironmentCalculations::DewPoint(temp, hum, envTempUnit);
float AbsoluteHumidity = EnvironmentCalculations::AbsoluteHumidity(temp, hum, envTempUnit);
float HeatIndex = EnvironmentCalculations::HeatIndex(temp, hum, envTempUnit);
pressio = pres; //Calibrar
temperatura = temp; //Calibrar
humitat = hum;
hum_absoluta = AbsoluteHumidity;
rosada = dewPoint;
basca = HeatIndex;
/*Serial.print(pressio);
Serial.print("-------");
Serial.print(temperatura);
Serial.print("-------");
Serial.print(humitat);
Serial.print("-------");
Serial.print(hum_absoluta);
Serial.print("-------");
Serial.print(rosada);
Serial.print("-------");
Serial.println(basca);*/
influxdb();
post_windy();
delay(1000);
}