3

(coco) #1
FORGE

explanation is included with the complete sketch
at hsmag.cc/lDAiDE.


void watchForMessage() {
WiFiClient client = myserver.available();
if (client) {
while (client.connected()) {
if (client.available()) {
String req = client.readStringUntil(‘\r’);
client.flush()
if (req.indexOf(messageTag) != -1) {
value = 100.0/dashFSD *
dashCollectValue();


// using the coordinates create the web
page
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
......
}
}
}
}
}
The standard setup function calls the specific setup
functions for the serial monitor, the I^2 C interface,
the WiFi connection, the web server, and finally the
solar sensor.


void setup()
{
Serial.begin(115200); // used for testing
delay(10);
Wire.begin(SDA,SCL); // set up I2
startWIFI();
setupWebServer(); // start the web server
setup_solarirradiance(); //start solar sensor
}

The main control loop is very simple, just continually
calling the function watching for a request from a client
over the WiFi.


void loop()
{
watchForMessage();
}

The sketch, IOT-solarWeb.ino, contains additional
comments to aid understanding, and can be
downloaded from hsmag.cc/VmLxHn.


PUT ON THE SUNGLASSES
As the TLS2561 is designed for indoor use, it can be
overloaded in bright sunshine and a filter is required to


reduce the light falling on the sensor. PTFE is a good
filter material, as it reduces the light across all relevant
wavelengths uniformly. A cheap source of PTFE is the
tape used for sealing threaded joints by plumbers. This
tape is non-conducting, so it can be wrapped around
the module. The thickness of the tape is not always the
same, so it is difficult to be precise about how many
layers are required.
Set up the device and run the IOT-solarWeb.ino
sketch detailed above, as you add layers of tape. The
Serial Monitor in the Arduino IDE will display the raw
counts, while a client accesses the solar web server.
The maximum count returned is 65 535 and is returned
when the device is overloaded. Wrap layers round the
sensor to reduce the count in bright sunshine to less
than 32 000.
With the sensor mounted in its final configuration,
note the maximum count, Cmax, when it points directly
at the sun in a clear sky, around midday. The solar
irradiance under these conditions will be approximately
1000 W/m^2 , Imax. This value and the maximum reading
provide the calibration:
Imax / Cmax
This is used in the sketch so that output will be
in W/m2 and should be the value assigned to the
constant solcalib.
To see the solar dashboard, on a device connected to
the same WiFi network, type:
192.168.0.186/ESPsolar

...into the address box of a web browser. You should
now see the dashboard. The display will update
every second.

Above
A sensor mounted
outside, protected
by a glass cover
Free download pdf