Took an example, worked for 12+ hours. Added just reading the light sensor and writing the value, failed after a while.
/****************************************************************************************************************************
UNO_WiFiNINA.ino
For AVR UNO WiFi Rev2 boards using WiFiNINA Shields
For AVR Mega boards using WiFiNINA Shields
Blynk_WiFiNINA_WM is a library for the Mega, Teensy, SAM DUE, nRF52, STM32, SAMD and RP2040 boards
(https://github.com/khoih-prog/Blynk_WiFiNINA_WM) to enable easy configuration/reconfiguration and
autoconnect/autoreconnect of WiFiNINA/Blynk
Modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases
Built by Khoi Hoang https://github.com/khoih-prog/Blynk_WiFiNINA_WM
Licensed under MIT license
Original Blynk Library author:
@file BlynkSimpleWiFiNINA.h
@author Volodymyr Shymanskyy
@license This project is released under the MIT License (MIT)
@copyright Copyright (c) 2018 Volodymyr Shymanskyy
@date Sep 2018
@brief
Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 07/04/2020 Initial coding
1.0.1 K Hoang 09/04/2020 Add support to SAM DUE, Teensy, STM32
1.0.2 K Hoang 15/04/2020 Fix bug. Add SAMD51 support.
1.0.3 K Hoang 05/05/2020 Add nRF52 support, MultiWiFi/Blynk, Configurable Config Portal Title,
Default Config Data and DRD. Update examples.
1.0.4 K Hoang 13/05/2020 Add support to Arduino UNO WiFi R2
1.1.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using Arduino mbed or pico core
Enable scan of WiFi networks for selection in Configuration Portal
1.1.1 K Hoang 09/06/2020 Add Blynk library Patches for **MBED RP2040-based (Nano_RP2040_Connect, etc.) boards
*****************************************************************************************************************************/
// To install WiFiNINA_Generic library (https://github.com/khoih-prog/WiFiNINA_Generic)
// and Blynk_WiFiNINA_WM (https://github.com/khoih-prog/Blynk_WiFiNINA_WM)
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
#include <BlynkSimpleWiFiNINA_UNO_WiFi.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TSL2591.h"
// Example for demonstrating the TSL2591 library - public domain!
// connect SCL to I2C Clock
// connect SDA to I2C Data
// connect Vin to 3.3-5V DC
// connect GROUND to common ground
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later)
//#define USE_LOCAL_SERVER true
#if USE_LOCAL_SERVER
char auth[] = "7z34lBX0Vwf_WN500hgKg06FkH72_Kpn";
String BlynkServer = "account.duckdns.org";
//String BlynkServer = "192.168.2.112";
#else
char auth[] = "7z34lBX0Vwf_WN500hgKg06FkH72_Kpn";
String BlynkServer = "blynk-cloud.com";
#endif
#define BLYNK_SERVER_HARDWARE_PORT 8080
// Your WiFi credentials.
char ssid[] = "W148N9872";
char pass[] = "63B6EC6B7F";
/**************************************************************************/
/*
Shows how to perform a basic read on visible, full spectrum or
infrared light (returns raw 16-bit ADC values)
*/
/**************************************************************************/
void simpleRead(void)
{
// Simple data read example. Just read the infrared, fullspecrtrum diode
// or 'visible' (difference between the two) channels.
// This can take 100-600 milliseconds! Uncomment whichever of the following you want to read
uint16_t x = tsl.getLuminosity(TSL2591_VISIBLE);
//uint16_t x = tsl.getLuminosity(TSL2591_FULLSPECTRUM);
//uint16_t x = tsl.getLuminosity(TSL2591_INFRARED);
Serial.print(F("[ ")); Serial.print(millis()); Serial.print(F(" ms ] "));
Serial.print(F("Luminosity: "));
Serial.println(x, DEC);
Blynk.virtualWrite(V20, x);
}
/**************************************************************************/
/*
Configures the gain and integration time for the TSL2591
*/
/**************************************************************************/
void configureSensor(void)
{
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
tsl.setGain(TSL2591_GAIN_LOW); // 1x gain (bright light)
//tsl.setGain(TSL2591_GAIN_MED); // 25x gain
//tsl.setGain(TSL2591_GAIN_HIGH); // 428x gain
// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
//tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS); // shortest integration time (bright light)
// tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);
tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS); // longest integration time (dim light)
/* Display the gain and integration time for reference sake */
Serial.println(F("------------------------------------"));
Serial.print (F("Gain: "));
tsl2591Gain_t gain = tsl.getGain();
switch(gain)
{
case TSL2591_GAIN_LOW:
Serial.println(F("1x (Low)"));
break;
case TSL2591_GAIN_MED:
Serial.println(F("25x (Medium)"));
break;
case TSL2591_GAIN_HIGH:
Serial.println(F("428x (High)"));
break;
case TSL2591_GAIN_MAX:
Serial.println(F("9876x (Max)"));
break;
}
Serial.print (F("Timing: "));
Serial.print((tsl.getTiming() + 1) * 100, DEC);
Serial.println(F(" ms"));
Serial.println(F("------------------------------------"));
Serial.println(F(""));
}
/**************************************************************************/
/*
Displays some basic information on this sensor from the unified
sensor API sensor_t type (see Adafruit_Sensor for more information)
*/
/**************************************************************************/
void displaySensorDetails(void)
{
sensor_t sensor;
tsl.getSensor(&sensor);
Serial.println(F("------------------------------------"));
Serial.print (F("Sensor: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F(" lux"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F(" lux"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution, 4); Serial.println(F(" lux"));
Serial.println(F("------------------------------------"));
Serial.println(F(""));
}
void heartBeatPrint(void)
{
static int num = 1;
if (Blynk.connected())
{
Serial.print("B");
}
else
{
Serial.print("F");
}
if (num == 80)
{
Serial.println();
num = 1;
}
else if (num++ % 10 == 0)
{
Serial.print(" ");
}
}
void check_status()
{
static unsigned long checkstatus_timeout = 0;
#define STATUS_CHECK_INTERVAL 15000L
// Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change.
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
{
// report status to Blynk
heartBeatPrint();
checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
}
}
BlynkTimer timer;
void myTimerEvent()
{
simpleRead();
}
void setup()
{
// Debug console
Serial.begin(9600);
while (!Serial);
//delay(1000);
Serial.println("\nStart UNO_WiFiNINA using WiFiNINA_Shield on UNO WiFi");
#if USE_LOCAL_SERVER
Blynk.begin(auth, ssid, pass, BlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT);
#else
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
Blynk.begin(auth, ssid, pass);
#endif
if (tsl.begin())
{
Serial.println(F("Found a TSL2591 sensor"));
/* Display some basic information on this sensor */
displaySensorDetails();
/* Configure the sensor */
configureSensor();
// Now we're ready to get readings ... move on to loop()!
}
timer.setInterval(500L, myTimerEvent);
}
void loop()
{
Blynk.run();
timer.run();
check_status();
}
09:26:32.838 → [ 8159549 ms ] Luminosity: 15451
09:26:32.871 → [8159552] <[14]@q[00|0B]vw[00]20[00]15451
09:26:33.349 → [ 8160050 ms ] Luminosity: 15472
09:26:33.383 → [8160053] <[14]@r[00|0B]vw[00]20[00]15472
09:26:33.824 → [ 8160549 ms ] Luminosity: 15465
09:26:33.857 → [8160560] >[00]@6[00|C8]
09:26:33.907 → [8160560] >[00]=[F7|00|C8]
09:26:33.942 → [8160574] >[86|01|00|CF|00]
09:26:33.989 → [8160604] Packet too big: 52992
09:26:34.265 → [8160991] Connecting to blynk-cloud.com:80
09:26:34.333 → [8161008] <[14]@s[00|0B]vw[00]20[00]15465
09:26:34.390 → [8161013] Cmd error
09:26:34.679 → [ 8161396 ms ] Luminosity: 15551
09:26:35.055 → [ 8161759 ms ] Luminosity: 15534
09:26:35.397 → [ 8162122 ms ] Luminosity: 15500
09:26:35.837 → [ 8162548 ms ] Luminosity: 15461