-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbh1750.ino
67 lines (52 loc) · 1.64 KB
/
bh1750.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
#include <WiFiNINA.h>
#include <BH1750.h>
#include <Wire.h>
char ssid[] = "M30s"; // Replace with your Wi-Fi SSID
char pass[] = "vcvw3532"; // Replace with your Wi-Fi password
WiFiClient client;
BH1750 lightMeter;
char HOST_NAME[] = "maker.ifttt.com";
String PATH_NAME = "/trigger/light/json/with/key/ofHfOy24U8Z572xy8SHdtZm97CE8nfjBDo4YKZq9o4J";
void setup() {
Serial.begin(9600);
while (!Serial);
WiFi.begin(ssid, pass);
Wire.begin();
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
lightMeter.begin();
}
void loop() {
float lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
if (lux > 100 ) {
String queryString = "?value1=" + String(lux);
// Get the current timestamp in the desired format
String timestamp = "October 1, 2023 at 12:06 AM";
//Make an HTTP request to the IFTTT webhook:
if (client.connect(HOST_NAME, 80)) {
// Send HTTP header
client.println("GET " + PATH_NAME + queryString + " HTTP/1.1");
client.println("Host: " + String(HOST_NAME));
client.println("Connection: close");
client.println(); // End HTTP header
while (client.connected()) {
if (client.available()) {
// Read an incoming byte from the server and print it to the Serial Monitor:
char c = client.read();
Serial.print(c);
}
}
// The server's disconnected, stop the client:
client.stop();
Serial.println();
Serial.println("Disconnected");
}
}
delay(3000);
}