2017-01-24 22:44:30 -07:00
|
|
|
#include <Wire.h>
|
|
|
|
#include <LiquidCrystal_I2C.h>
|
|
|
|
#include <max6675.h>
|
|
|
|
#include "Adafruit_MCP23017.h"
|
|
|
|
|
2017-02-11 14:09:15 -07:00
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
#include <WiFiClient.h>
|
|
|
|
#include <ESP8266WebServer.h>
|
|
|
|
|
|
|
|
///// USER SETTINGS /////
|
|
|
|
|
|
|
|
// WiFi Settings
|
|
|
|
const char *ssid = "ESPap";
|
|
|
|
const char *password = "thereisnospoon";
|
|
|
|
|
|
|
|
// Temperature Offsets
|
|
|
|
int t1off = 0;
|
|
|
|
int t2off = 0;
|
|
|
|
int t3off = 0;
|
|
|
|
|
|
|
|
// Pinout
|
2017-01-24 22:44:30 -07:00
|
|
|
int CLK0 = 13;
|
2017-02-11 14:09:15 -07:00
|
|
|
int MISO0 = 12;
|
|
|
|
int CS1 = 16;
|
|
|
|
int CS2 = 14;
|
|
|
|
int CS3 = 15;
|
2017-01-24 22:44:30 -07:00
|
|
|
|
2017-02-11 14:09:15 -07:00
|
|
|
///// END USER SETTINGS /////
|
|
|
|
|
|
|
|
// Thermocouple stuff
|
|
|
|
MAX6675 t1(CLK0, CS1, MISO0);
|
|
|
|
MAX6675 t2(CLK0, CS2, MISO0);
|
|
|
|
MAX6675 t3(CLK0, CS3, MISO0);
|
|
|
|
int temp1, temp2, temp3;
|
|
|
|
|
|
|
|
// Output Stuff
|
2017-02-10 23:57:49 -07:00
|
|
|
LiquidCrystal_I2C lcd(0x3f, 20, 4);
|
2017-01-24 22:44:30 -07:00
|
|
|
Adafruit_MCP23017 mcp;
|
|
|
|
|
2017-02-11 14:09:15 -07:00
|
|
|
// WiFi Stuff
|
|
|
|
ESP8266WebServer server(80);
|
|
|
|
|
|
|
|
// Control Stuff
|
|
|
|
int onTemp = 70;
|
|
|
|
int offTemp = 80;
|
|
|
|
|
|
|
|
///// WEB SERVER /////
|
|
|
|
void handleRoot() {
|
2017-02-11 15:26:22 -07:00
|
|
|
server.send(200, "text/html",
|
2017-02-11 14:09:15 -07:00
|
|
|
"<h1>Kiln Controller V1</h1>"
|
2017-02-11 15:26:22 -07:00
|
|
|
"<a href=\"/temps\">Real Time Temperature Readout</a><br>"
|
|
|
|
"<a href=\"/settings\">Temperature Setpoints</a><br>"
|
|
|
|
"<a href=\"/config\">Configuration</a><br>"
|
|
|
|
);
|
2017-02-11 14:09:15 -07:00
|
|
|
}
|
|
|
|
|
2017-02-11 15:26:22 -07:00
|
|
|
void handleTemps() {
|
|
|
|
server.send(200, "text/html",
|
|
|
|
"<h1>Temperature Readout</h1>"
|
2017-02-11 14:09:15 -07:00
|
|
|
"<a href=\"/\">Home</a>"
|
2017-02-11 15:26:22 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleSettings() {
|
|
|
|
server.send(200, "text/html",
|
|
|
|
"<h1>Settings</h1>"
|
|
|
|
"<a href=\"/\">Home</a>"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleConfig() {
|
|
|
|
server.send(200, "text/html",
|
|
|
|
"<h1>Configuration</h1>"
|
|
|
|
"<a href=\"/\">Home</a>"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleNotFound() {
|
|
|
|
String temp = "File Not Found\n\n";
|
|
|
|
temp += "URI: ";
|
|
|
|
temp += server.uri();
|
|
|
|
temp += "\nMethod: ";
|
|
|
|
temp += ( server.method() == HTTP_GET ) ? "GET" : "POST";
|
|
|
|
temp += "\nArguments: ";
|
|
|
|
temp += server.args();
|
|
|
|
temp += "\n";
|
|
|
|
|
|
|
|
for ( uint8_t i = 0; i < server.args(); i++ ) {
|
|
|
|
temp += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
server.send ( 404, "text/plain", temp );
|
2017-02-11 14:09:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
///// SETUP /////
|
2017-01-24 22:44:30 -07:00
|
|
|
void setup() {
|
2017-02-10 23:54:45 -07:00
|
|
|
// Onboard LED
|
2017-02-11 14:09:15 -07:00
|
|
|
pinMode(2, OUTPUT);
|
2017-02-10 23:54:45 -07:00
|
|
|
|
2017-01-24 23:05:59 -07:00
|
|
|
// I2C
|
|
|
|
Wire.pins(4, 5);
|
|
|
|
|
2017-01-24 22:44:30 -07:00
|
|
|
// LCD
|
|
|
|
lcd.init();
|
|
|
|
lcd.init();
|
|
|
|
lcd.backlight();
|
2017-01-24 23:05:59 -07:00
|
|
|
lcd.setCursor(0, 0);
|
2017-01-24 22:44:30 -07:00
|
|
|
lcd.print("Initializing... ");
|
|
|
|
|
|
|
|
// MCP23017 GPIO expander
|
|
|
|
mcp.begin();
|
2017-02-10 23:54:45 -07:00
|
|
|
mcp.pinMode(0, OUTPUT);
|
|
|
|
mcp.pinMode(1, OUTPUT);
|
|
|
|
mcp.pinMode(2, OUTPUT);
|
|
|
|
mcp.pinMode(3, OUTPUT);
|
|
|
|
mcp.pinMode(4, OUTPUT);
|
|
|
|
mcp.digitalWrite(0, HIGH);
|
|
|
|
mcp.digitalWrite(1, HIGH);
|
|
|
|
mcp.digitalWrite(2, HIGH);
|
|
|
|
mcp.digitalWrite(3, HIGH);
|
2017-01-24 22:44:30 -07:00
|
|
|
delay(100);
|
2017-02-10 23:54:45 -07:00
|
|
|
mcp.digitalWrite(0, LOW);
|
|
|
|
mcp.digitalWrite(1, LOW);
|
|
|
|
mcp.digitalWrite(2, LOW);
|
|
|
|
mcp.digitalWrite(3, LOW);
|
2017-01-24 22:44:30 -07:00
|
|
|
|
2017-02-11 14:09:15 -07:00
|
|
|
// Temperature Inital Values
|
|
|
|
temp1 = t1.readFahrenheit();
|
|
|
|
temp2 = t2.readFahrenheit();
|
|
|
|
temp3 = t3.readFahrenheit();
|
|
|
|
|
|
|
|
// Access Point Setup
|
|
|
|
WiFi.softAP(ssid, password);
|
|
|
|
IPAddress myIP = WiFi.softAPIP();
|
|
|
|
server.on("/", handleRoot);
|
2017-02-11 15:26:22 -07:00
|
|
|
server.on("/temps", handleTemps);
|
|
|
|
server.on("/settings", handleSettings);
|
|
|
|
server.on("/config", handleConfig);
|
|
|
|
server.on ("/test.svg", tempGraph);
|
|
|
|
server.onNotFound(handleNotFound);
|
2017-02-11 14:09:15 -07:00
|
|
|
server.begin();
|
|
|
|
lcd.clear();
|
|
|
|
lcd.setCursor(0, 0); lcd.print("SSID: "); lcd.print(ssid);
|
|
|
|
lcd.setCursor(0, 1); lcd.print("PSWD: "); lcd.print(password);
|
|
|
|
lcd.setCursor(0, 2); lcd.print("IP : "); lcd.print(myIP);
|
2017-02-11 15:26:22 -07:00
|
|
|
delay(2000);
|
2017-02-11 14:09:15 -07:00
|
|
|
|
2017-01-24 22:44:30 -07:00
|
|
|
// Clear LCD
|
2017-01-24 23:05:59 -07:00
|
|
|
lcd.setCursor(0, 0);
|
|
|
|
lcd.clear();
|
2017-01-24 22:44:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2017-02-11 14:09:15 -07:00
|
|
|
server.handleClient();
|
|
|
|
|
|
|
|
// Get values
|
|
|
|
temp1 = t1.readFahrenheit() + t1off;
|
|
|
|
temp2 = t2.readFahrenheit() + t2off;
|
|
|
|
temp3 = t3.readFahrenheit() + t3off;
|
|
|
|
|
|
|
|
// Write to LCD
|
|
|
|
lcd.clear();
|
2017-01-24 23:05:59 -07:00
|
|
|
lcd.setCursor(0, 0);
|
2017-02-11 14:09:15 -07:00
|
|
|
lcd.print("1: ");
|
|
|
|
lcd.print(temp1);
|
|
|
|
lcd.print(" F");
|
|
|
|
lcd.setCursor(0, 1);
|
|
|
|
lcd.print("2: ");
|
|
|
|
lcd.print(temp2);
|
|
|
|
lcd.print(" F");
|
|
|
|
lcd.setCursor(0, 2);
|
|
|
|
lcd.print("3: ");
|
|
|
|
lcd.print(temp3);
|
|
|
|
lcd.print(" F");
|
2017-02-10 23:54:45 -07:00
|
|
|
|
2017-02-11 14:09:15 -07:00
|
|
|
// Heartbeat LED
|
2017-02-11 15:26:22 -07:00
|
|
|
if (WiFi.softAPgetStationNum() == 0) {
|
|
|
|
digitalWrite(2, LOW);
|
|
|
|
delay(100);
|
|
|
|
digitalWrite(2, HIGH);
|
|
|
|
delay(900);
|
|
|
|
} else {
|
|
|
|
digitalWrite(2, LOW);
|
|
|
|
delay(50);
|
|
|
|
digitalWrite(2, HIGH);
|
|
|
|
delay(100);
|
|
|
|
digitalWrite(2, LOW);
|
|
|
|
delay(50);
|
|
|
|
digitalWrite(2, HIGH);
|
|
|
|
delay(800);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawGraph(int xvalues[], int yvalues[], int width, int height, int r, int g, int b) {
|
|
|
|
String out = "";
|
|
|
|
char temp[100];
|
|
|
|
|
|
|
|
sprintf(temp, "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"%d\" height=\"%d\">\n", width, height);
|
|
|
|
out += temp;
|
|
|
|
|
|
|
|
sprintf(temp, "<rect width=\"%d\" height=\"%d\" fill=\"rgb(%d,%d,%d)\" stroke-width=\"1\" stroke=\"rgb(0, 0, 0)\" />\n", width, height, r, g, b);
|
|
|
|
out += temp;
|
|
|
|
|
|
|
|
out += "<g stroke=\"black\">\n";
|
|
|
|
int y = rand() % 130;
|
|
|
|
// for (int i = 0; i < size(times); i ++) {
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tempGraph() {
|
|
|
|
int times[] = {1, 2, 3, 4, 5, 6};
|
|
|
|
int temps[] = {1, 2, 3, 1, 5, 3};
|
|
|
|
drawGraph(times, temps, 400, 150, 232, 240, 255);
|
2017-01-24 22:44:30 -07:00
|
|
|
}
|