1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #include <ESP8266WiFi.h>
- #include <Wire.h>
- #include "config.h"
- #include "Adafruit_TSL2591.h"
- // ----------- DEFINES ---------------
- #define LUX_ID 0x39 // I2C-Id of the lux-sensor
- // ----------- GLOBALS ---------------
- WiFiClient espClient;
- Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later)
- void connectWifi() {
- WiFi.disconnect(false);
- Serial.printf("Wi-Fi mode set to WIFI_STA: %s\n", WiFi.mode(WIFI_STA) ? "Ok" : "Failed!");
- WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
- Serial.print("Connecting to ");Serial.println(WIFI_SSID);
-
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- Serial.print(WiFi.status());
- Serial.print(".\r\n");
- //WiFi.printDiag(Serial);
- }
-
- Serial.println("");
- Serial.print("Connected with IP: "),
- Serial.println(WiFi.localIP());
- Serial.printf("\n");
- }
- void setup() {
- Serial.begin(38400); //Opens USB-Serial connection for terminal
- delay(1000);
- Serial.println("Init of WiFi-Lux-sensor project");
- connectWifi();
- Wire.begin(4, 5); // sda on pin D2, scl on pin D1
- tsl.begin();
- }
- void loop() {
- // put your main code here, to run repeatedly:
- byte error, address;
-
- Serial.print("WiFi heartbeat - ms since boot: ");
- Serial.print(millis());
- Serial.println();
- Wire.beginTransmission(LUX_ID);
- error = Wire.endTransmission();
- if (error == 0) {
- Serial.println("I2C-Lux device found");
- }
- else if (error==4) {
- Serial.println("--Unknown error.");
- }
- Serial.println("done\n");
-
- delay(1000);
-
- }
|