71 lines
1.6 KiB
C++
71 lines
1.6 KiB
C++
#include <WiFi.h>
|
|
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
|
|
#include <hp_BH1750.h> // Library for the light sensor
|
|
|
|
const int configbutton = D9; // Input for config button
|
|
const int led = D10; // Output for status LED
|
|
int configbuttonStatus = digitalRead(configbutton);
|
|
bool ready = 0;
|
|
int counter = 0;
|
|
hp_BH1750 BH1750;
|
|
|
|
int status = WL_IDLE_STATUS;
|
|
|
|
void setup()
|
|
{
|
|
pinMode(led, OUTPUT);
|
|
pinMode(configbutton, INPUT_PULLUP);
|
|
|
|
Serial.println("reset button: ");
|
|
Serial.println(configbuttonStatus);
|
|
|
|
|
|
// check for the presence of the shield:
|
|
if (WiFi.status() == WL_NO_SHIELD) {
|
|
Serial.println("WiFi shield not present");
|
|
while(true); // don't continue
|
|
}
|
|
|
|
WiFiManager wifiManager;
|
|
wifiManager.autoConnect("ESP32-LS");
|
|
|
|
while(WiFi.status() != WL_CONNECTED) {
|
|
digitalWrite(led, HIGH);
|
|
delay(1000);
|
|
digitalWrite(led, LOW);
|
|
delay(1000);
|
|
}
|
|
|
|
if(WiFi.status() == WL_CONNECTED){
|
|
digitalWrite(led, HIGH);
|
|
}
|
|
|
|
|
|
bool avail = BH1750.begin(BH1750_TO_GROUND);
|
|
if (!avail) {
|
|
Serial.println("No BH1750 sensor found!");
|
|
while (true) {};
|
|
}
|
|
}
|
|
|
|
|
|
void loop () {
|
|
while(WiFi.status() != WL_CONNECTED) {
|
|
digitalWrite(led, HIGH);
|
|
delay(1000);
|
|
digitalWrite(led, LOW);
|
|
delay(1000);
|
|
}
|
|
|
|
|
|
if ( configbuttonStatus != digitalRead(configbutton) ) {
|
|
WiFiManager wifiManager;
|
|
wifiManager.startConfigPortal("ESP32-LS");
|
|
Serial.println("connected...yeey :)");
|
|
}
|
|
|
|
BH1750.start();
|
|
float lux=BH1750.getLux();
|
|
Serial.println(lux);
|
|
delay(5000);
|
|
} |