ESP12E sensor read-out webpage

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
ilioSS
New user
Posts: 3
Joined: 25 Oct 2015, 21:26

ESP12E sensor read-out webpage

#1 Post by ilioSS » 26 Oct 2015, 15:12

Hi all,
Recently I am bussy with a tsl2591 on a Landid&Gyr kWh meter power use read-out. This is working on a arduino.
The next step is to read out and have the reading on internet.
To do so I bought a esp12E and up-loaded this with the arduino script. Working.( local wi-fi )
Now I would like to have the light and kWh reading on the webpage as wel. (outside local wi-fi )
I like to use the graph already in the script.
As internet is still a bid fuzzy ( do I need realy an website? for a PHP script????)
BTW download and install. of the php script writing program fails two times the file msvcr110.dll is missing?? what to do.
Also apache fails to install.

In fact I have three questions looks like.
Like to hear.
Kind regards,
ilioSS

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TSL2591.h"
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591);
const char *ssid = "xxxxxxxxx";
const char *password = "yyyyyyyyyyy";
MDNSResponder mdns;

ESP8266WebServer server ( 80 );

const int led = 13;

void handleRoot() {
digitalWrite ( led, 1 );
char temp[400];
int sec = millis() / 1000;
int min = sec / 60;
int hr = min / 60;

snprintf ( temp, 400,

"<html>\
<head>\
<meta http-equiv='refresh' content='5'/>\
<title>ESP8266 kWh Demo</title>\
<style>\
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
<h1>Hello from ESP8266 kWh opnemer # 1 </h1>\
<p>Uptime: %02d:%02d:%02d</p>\
<img src=\"/test.svg\" />\
</body>\
</html>",

hr, min % 60, sec % 60
);
server.send ( 200, "text/html", temp );
digitalWrite ( led, 0 );
}

void handleNotFound() {
digitalWrite ( led, 1 );
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += ( server.method() == HTTP_GET ) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";

for ( uint8_t i = 0; i < server.args(); i++ ) {
message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n";
}

server.send ( 404, "text/plain", message );
digitalWrite ( led, 0 );
}

void displaySensorDetails(void)
{
sensor_t sensor;
tsl.getSensor(&sensor);
Serial.println("------------------------------------");
Serial.print ("Sensor: "); Serial.println(sensor.name);
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" lux");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" lux");
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" lux");
Serial.println("------------------------------------");
Serial.println("");
delay(500);
}

void configureSensor(void)
{

tsl.setGain(TSL2591_GAIN_MAX); // 9876x extremely low light


tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS); // longest integration time (dim light)

/* Display the gain and integration time for reference sake */
Serial.println("------------------------------------");
Serial.print ("Gain: ");
tsl2591Gain_t gain = tsl.getGain();
switch(gain)
{

case TSL2591_GAIN_MAX:
Serial.println("9876x (Max)");
break;
}

}


void setup ( void ) {

pinMode(BUILTIN_LED, OUTPUT);


pinMode ( led, OUTPUT );
digitalWrite ( led, 0 );
Serial.begin ( 115200 );
WiFi.begin ( ssid, password );
Serial.println ( "" );

// Wait for connection
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}

Serial.println ( "" );
Serial.print ( "Connected to " );
Serial.println ( ssid );
Serial.print ( "IP address: " );
Serial.println ( WiFi.localIP() );

if ( mdns.begin ( "esp8266", WiFi.localIP() ) ) {
Serial.println ( "MDNS responder started" );
}

server.on ( "/", handleRoot );
server.on ( "/test.svg", drawGraph );
server.on ( "/inline", []() {
server.send ( 200, "text/plain", "this works as well" );
} );
server.onNotFound ( handleNotFound );
server.begin();
Serial.println ( "HTTP server started" );

Serial.println("Starting Adafruit TSL2591 Test!");


/* Display some basic information on this sensor */
displaySensorDetails();

/* Configure the sensor */
configureSensor();

}

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 q = tsl.getLuminosity(TSL2591_FULLSPECTRUM);
//uint16_t x = tsl.getLuminosity(TSL2591_INFRARED);

Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");
Serial.print("Luminosity: ");
Serial.println(q, DEC);

if ( q >2456 ){
digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level
} // but actually the LED is on; this is because
if ( q <2900){ // it is acive low on the ESP-01)
// delay(1000); // Wait for a second
digitalWrite(BUILTIN_LED, HIGH);} // Turn the LED off by making the voltage HIGH
// delay(2000);

}




// end of set-up


void loop ( void ) {
mdns.update();
server.handleClient();
simpleRead();
}

void drawGraph() {
String out = "";
char temp[100];
out += "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"400\" height=\"150\">\n";
out += "<rect width=\"400\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"1\" stroke=\"rgb(0, 0, 0)\" />\n";
out += "<g stroke=\"black\">\n";
int y = rand() % 130;
for (int x = 10; x < 390; x+= 10) {
int y2 = rand() % 130;
sprintf(temp, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"1\" />\n", x, 140 - y, x + 10, 140 - y2);
out += temp;
y = y2;
}
out += "</g>\n</svg>\n";

server.send ( 200, "image/svg+xml", out);
}

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 48 guests