// data output using the web server in the form of graphs
// author A. Konovalov 2015
// # include <UIPEthernet.h>
#include <Ethernet.h>
#include <SPI.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip (192,168,26,15);
// Initialize the Ethernet server library
// with the IP address and port
// (port 80 is default for HTTP):
EthernetServer server (80);
const char str1 [] PROGMEM = "<! DOCTYPE html> <script src =";
const char str2 [] PROGMEM = "\"
www.google.com/jsapi?autoload= {'modules': [{'name': ";
const char str3 [] PROGMEM = "'visualization', 'version': '1', 'packages': ['corechart']}]} \"> ";
const char str4 [] PROGMEM = "";
const char str12 [] PROGMEM = "";
const char * const string_table [] PROGMEM = {str1, str2, str3, str4, str5, str6, str7};
const char * const string_table2 [] PROGMEM = {str8, str9, str10, str11, str12};
char myChar;
char buffer [80];
unsigned long previousMillis1 = 0; // last time point
unsigned long previousMillis2 = 1; // last moment of time
unsigned long previousMillis3 = 1; // last moment of time
long OnTime2 = 60000; // minute
long OnTime3 = 600000; // half an hour
int In_sec = 0; // countdown per second
int In_min = 0; // countdown per minute
int In_half = 0; // countdown for half an hour
long Sum_min = 0; // amount per minute
long Sum_half = 0; // amount for half an hour
float Sum_base_min = 0;
float Sum_base_half = 0;
int i, j, k = 0;
void setup ()
{
// start the Ethernet connection and the server:
Ethernet.begin (mac, ip);
server.begin ();
}
// unsigned long begMillis = millis (); // flowed in ms
void loop ()
{
unsigned long currentMillis = millis (); // flowed in ms
In_sec = analogRead (0);
Sum_min = Sum_min + (currentMillis - previousMillis1) * In_sec;
In_min = (Sum_min + Sum_base_min) / (OnTime2 * i + currentMillis - previousMillis2);
Sum_half = Sum_half + (currentMillis - previousMillis1) * In_sec;
In_half = (Sum_half + Sum_base_half) / (OnTime3 * j + currentMillis - previousMillis3);
previousMillis1 = currentMillis; // remember the moment of time
if (currentMillis - previousMillis2> = OnTime2)
{i = 1;
Sum_base_min = Sum_min;
previousMillis2 = currentMillis; // remember the moment of time
Sum_min = 0;
}
if (currentMillis - previousMillis3> = OnTime3)
{j = 1;
Sum_base_half = Sum_half;
previousMillis3 = currentMillis; // remember the moment of time
Sum_half = 0;
}
/ *
In_sec = 990;
In_min = 500;
In_half = 90;
* /
// listen for incoming clients
EthernetClient client = server.available ();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected ()) {
if (client.available ()) {
char c = client.read ();
if (c == '\ n' && currentLineIsBlank) {
for (int i = 0; i <7; i ++)
{
strcpy_P (buffer, (char *) pgm_read_word (& (string_table [i]))); // Necessary casts and dereferencing, just copy.
client.print (buffer);
delay (500);
}
client.print ("['Now',");
client.print (660);
client.print (",");
client.print (1120);
client.print ("],]);");
for (int i = 0; i <5; i ++)
{
strcpy_P (buffer, (char *) pgm_read_word (& (string_table2 [i]))); // Necessary casts and dereferencing, just copy.
client.print (buffer);
delay (500);
}
break;
}
if (c == '\ n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c! = '\ r') {
// you gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the data browser
delay (1);
// close the connection:
client.stop ();
}
}