first commit

This commit is contained in:
Jérôme Delacotte
2025-03-06 11:15:32 +01:00
commit 7b30d6e298
5276 changed files with 2108927 additions and 0 deletions

131
ESP8266_DOMOTICZ_ECRAN/Cube.cpp Executable file
View File

@@ -0,0 +1,131 @@
#include "Cube.h"
Cube::Cube(Ecran * _ecran)
{
ecran = _ecran;
}
void Cube::QuickSort(int deb, int fin)
{
int i = deb;
int j = fin;
double milieu = 256 * zface[tri[(deb + fin) / 2]];
int temp;
while (i <= j)
{
while (256 * zface[tri[i]] > milieu) i++;
while (256 * zface[tri[j]] < milieu) j--;
if (i <= j)
{
temp = tri[i];
tri[i] = tri[j];
tri[j] = temp;
i++; j--;
}
}
if (i < fin) QuickSort(i, fin);
if (deb < j) QuickSort(deb, j);
// draw();
}
void Cube::draw()
{
int nb = 0;
while (nb < 200)
{
ecran->LcdClear();
a = a - 0.05;
b = b + 0.05;
for (int n = 0; n < 8; n++) {
lxn[n] = lx[n] * cos(b)
+ ly[n] * sin(a) * sin(b)
+ lz[n] * cos(a) * sin(b);
lyn[n] = ly[n] * cos(a)
- lz[n] * sin(a);
lzn[n] = -lx[n] * sin(b)
+ ly[n] * sin(a) * cos(b)
+ lz[n] * cos(a) * cos(b)
+ 5;
xd[n] = (LCD_X / 2)
+ (LCD_X * lxn[n] * c) / (2 * lzn[n]) * 2;
yd[n] = (LCD_Y / 2)
+ (LCD_Y * lyn[n] * c) / (2 * lzn[n]) * 2;
}
int facev = 0;
for (int m = 0; m < 6; m++) {
znm = (xd[face[m][2]] - xd[face[m][1]]) * (yd[face[m][1]] - yd[face[m][3]]) - (yd[face[m][2]] - yd[face[m][1]]) * (xd[face[m][1]] - xd[face[m][3]]);
//znm=2; only zsorting
if (znm > 0) {
zface[m] = lzn[face[m][0]] + lzn[face[m][1]] + lzn[face[m][2]] + lzn[face[m][3]] + lzn[face[m][4]];
tri[facev] = m;
facev++;
}
}
QuickSort(0, facev - 1);
for (int mb = 0; mb < facev; mb++) {
int color = WHITE;
switch (tri[mb]) {
case 0:
color = WHITE;
break;
case 1:
color = RED;
break;
case 2:
color = BLUE;
break;
case 3:
color = YELLOW;
break;
case 4:
color = GREEN;
break;
case 5:
color = CYAN;
break;
default:
break;
}
points[0].x = xd[face[tri[mb]][0]];
points[0].y = yd[face[tri[mb]][0]];
points[1].x = xd[face[tri[mb]][1]];
points[1].y = yd[face[tri[mb]][1]];
points[2].x = xd[face[tri[mb]][2]];
points[2].y = yd[face[tri[mb]][2]];
points[3].x = xd[face[tri[mb]][3]];
points[3].y = yd[face[tri[mb]][3]];
// FACE 1
ecran->drawFace(
points[0].x, points[0].y,
points[1].x, points[1].y,
points[2].x, points[2].y);
ecran->drawFace(
points[0].x, points[0].y,
points[2].x, points[2].y,
points[3].x, points[3].y);
// ecran->u8g2->drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
// ecran->u8g2->drawLine(points[1].x, points[1].y, points[2].x, points[2].y);
// ecran->u8g2->drawLine(points[2].x, points[2].y, points[0].x, points[0].y);
//
// ecran->u8g2->drawLine(points[0].x, points[0].y, points[2].x, points[2].y);
// ecran->u8g2->drawLine(points[2].x, points[2].y, points[3].x, points[3].y);
// ecran->u8g2->drawLine(points[3].x, points[3].y, points[0].x, points[0].y);
}
ecran->u8g2->sendBuffer();
delay(50);
nb++;
}
}

57
ESP8266_DOMOTICZ_ECRAN/Cube.h Executable file
View File

@@ -0,0 +1,57 @@
#ifndef Cube_h
#define Cube_h
#include <Arduino.h>
#include "Ecran.h"
typedef struct
{
int x, y;
} point;
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
class Cube {
public :
Cube(Ecran * ecran);
void draw();
private:
void QuickSort(int deb, int fin);
public :
float x, y;
private:
Ecran * ecran;
int key;
float a = 0.0, b = 0.0;
//float ax,ay,az;
short lx[8] = {1, 1, 1, 1, -1, -1, -1, -1};
short ly[8] = {1, 1, -1, -1, 1, 1, -1, -1};
short lz[8] = {1, -1, 1, -1, 1, -1, 1, -1};
float lxn[8], lyn[8], lzn[8];
float xd[8], yd[8];
float c = 1.0;
float xt, yt, zt;
float mr[3][3];
float znm;
int face[6][4] = {{4, 0, 1, 5}, {1, 0, 2, 3}, {5, 1, 3, 7}, {4, 5, 7, 6}, {0, 4, 6, 2}, {3, 2, 6, 7}};
int facec[6] = {10, 20, 30, 20, 30, 10};
point points[10];
// Quick sort
int tri[12];
int zface[12];
};
#endif

View File

@@ -0,0 +1,279 @@
#include "Domoticz.h"
Domoticz::Domoticz(String domoticz, String port, const char* ssid, const char* pass)
{
_domoticz = domoticz;
_port = port;
_ssid = ssid;
_pass = pass;
// // Domo
// _domoc[_domoticz.length() + 1];
// _domoticz.toCharArray(_domoc, _domoticz.length() + 1);
//
// // Port
// char portc[_port.length() + 1];
// _port.toCharArray(portc, _port.length() + 1);
// _iport = atoi(portc);
}
boolean Domoticz::connect()
{
// Domo
char _domoc[_domoticz.length() + 1];
_domoticz.toCharArray(_domoc, _domoticz.length() + 1);
// Port
char portc[_port.length() + 1];
_port.toCharArray(portc, _port.length() + 1);
int _iport = atoi(portc);
boolean connected = _client.connect(_domoc, _iport);
Serial.print(_domoc);
Serial.print(" ");
Serial.print(_iport);
Serial.print(" ");
Serial.print(" connected ");
Serial.print(connected);
Serial.print(" ");
Serial.println(WiFi.localIP());
return connected;
}
void Domoticz::close()
{
}
void Domoticz::initWifi()
{
WiFi.mode(WIFI_AP);
WiFi.begin(_ssid, _pass); //Connect to local Wifi
Serial.println();
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.println("WiFi Connected!");
Serial.print("Connexion au reseau ");
Serial.println(WiFi.localIP());
}
String Domoticz::generateKey()
{
// WiFi.mode(WIFI_AP);
// Do a little work to get a unique-ish name. Append the
// last two bytes of the MAC (HEX'd) to "Thing-":
uint8_t mac[WL_MAC_ADDR_LENGTH];
WiFi.softAPmacAddress(mac);
String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) + String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
macID.toUpperCase();
String AP_NameString = "ESP8266 Thing " + macID;
char AP_NameChar[AP_NameString.length() + 1];
memset(AP_NameChar, 0, AP_NameString.length() + 1);
for (int i = 0; i < AP_NameString.length(); i++)
{
AP_NameChar[i] = AP_NameString.charAt(i);
}
// WiFi.softAP(AP_NameChar, WiFiAPPSK);
Serial.println("macID=" + macID);
_macID = macID;
return macID;
}
void Domoticz::executeJson(String json, String svalue, String nvalue)
{
// Domo
char _domoc[_domoticz.length() + 1];
_domoticz.toCharArray(_domoc, _domoticz.length() + 1);
// Port
char portc[_port.length() + 1];
_port.toCharArray(portc, _port.length() + 1);
int _iport = atoi(portc);
_client.print("GET " + json); //"GET /json.htm?type=command&param=getuservariables");
if (svalue != "") {
_client.print("&svalue=" + svalue);
}
if (nvalue != "") {
_client.print("&nvalue=" + nvalue);
}
_client.println(" HTTP/1.1");
_client.print("Host: ");
_client.print(_domoc);
_client.print(":");
_client.println(_iport);
_client.println("User-Agent: Arduino-ethernet");
_client.println("Connection: close");
_client.println();
Serial.println("json=" + json);
}
//--------------------------------------------------------------------------------------------------
// Read current supply voltage
//--------------------------------------------------------------------------------------------------
String Domoticz::readVcc() {
// most exact output
uint16_t v = ESP.getVcc();
float_t v_cal = ((float) v / 1024.0f);
char v_str[10];
dtostrf(v_cal, 5, 3, v_str);
sprintf(v_str, "%s", v_str);
Serial.print("Tension lue ");
Serial.println(String(v_str));
return String(v_str); //ESP.getVcc() / 1024.0f; // Vcc in millivolts
}
String Domoticz::getIndexOfString(String data, String separator, int index)
{
int found = 0;
int strIndex[] = { 0, -1 };
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator.charAt(0) || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i + 1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
String Domoticz::readLine()
{
return _client.readStringUntil('\n');
}
void Domoticz::readTempDayValues(String idx)
{
String json = "/json.htm?type=graph&sensor=temp&idx=" + idx + "&range=day";
int nb = 0;
int nbVal = 0;
data = "";
labels = "";
String label = "";
Serial.println("readTempDayValues " + idx);
connect();
executeJson(json, "", "");
while (1)
{
// Avoid WDT reset during long process
yield();
String line = readLine();
if (line == "") {
break;
}
if (line.indexOf("\"d\"") != -1) {
//Serial.println(line + " ");
label = line.substring(line.indexOf(":") + 2, line.length());
}
if (line.indexOf("\"te\"") != -1) {
// Serial.println(line + " ");
nbVal++;
if (nbVal % 10) {
String val = line.substring(line.indexOf(":") + 2, line.indexOf(".") + 2);
if (val != NULL) {
//Serial.println(val);
if (data == "") {
data += val;
labels = "\"0\"";
} else {
char charBuf[50];
// val.toCharArray(charBuf, 50);
data += "," + val; //printf("%2.1f", atof(charBuf));
// data += "," + val;
// Serial.println(printf("%2.1f", atof(charBuf)));
labels = labels + label;
}
if (data.length() > 500) {
data = data.substring(data.indexOf(",") + 1);
labels = labels.substring(labels.indexOf(",") + 1);
}
}
}
}
nb++;
}
// Avoid WDT reset during long process
yield();
// Serial.println(data);
// Serial.println(labels);
yield();
Serial.print("Nombre de lignes ");
Serial.println(nb);
close();
}
void Domoticz::getIdFromDomoticz(String macID, Params * params)
{
String separator = ",";
int nb = 0;
Serial.println("Dans getIdFromDomoticz " + macID);
// -------------------
// LECTURE PARAM
// -------------------
if (params->esp8266_id == "") {
boolean connected = connect();
if (connected) {
Serial.println("Connected to domoticz");
executeJson("/json.htm?type=command&param=getuservariables", "", "");
// Read the first line of the request
while (1) {
String req = readLine();
if (req.indexOf(macID) != -1) {
Serial.println(req);
req = readLine();
req = readLine();
String val = req.substring(req.indexOf(":") + 2, req.length() - 1);
Serial.println(val);
val.replace("\"", "");
params->esp8266_id = getIndexOfString(val, separator, 0);
String tmp = getIndexOfString(val, separator, 1);
char tmpc[tmp.length() + 1];
tmp.toCharArray(tmpc, tmp.length() + 1);
params->sleepTime = atoi(tmpc);
if (params->sleepTime <= 0) {
params->sleepTime = 60;
}
params->esp8266_id_Vcc = getIndexOfString(val, separator, 2);
Serial.println("esp8266_id=" + params->esp8266_id);
Serial.println("sleepTime=" + tmp);
Serial.println("esp8266_id_Vcc=" + params->esp8266_id_Vcc);
break;
}
if (req == "" || nb > 500) {
break;
}
nb++;
}
_client.stop();
delay(100);
}
}
}

View File

@@ -0,0 +1,38 @@
#ifndef Domoticz_h
#define Domoticz_h
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "Params.h"
class Domoticz
{
public:
Domoticz(String domoticz, String port, const char* ssid, const char* pass);
boolean connect();
void close();
void initWifi();
void executeJson(String json, String svalue, String nvalue);
//String getIdFromDomoticz();
String generateKey();
String readLine();
String readVcc();
void readTempDayValues(String idx);
void getIdFromDomoticz(String macID, Params * params);
static String getIndexOfString(String data, String separator, int index);
private:
const char* _pass;
public:
const char* _ssid;
WiFiClient _client;
char _domoc[];
int _iport;
String _domoticz;
String _port;
String _macID;
String data = "";
String labels = "";
};
#endif

View File

@@ -0,0 +1,250 @@
//extern "C" {
//#include "user_interface.h"
//}
// Need for getVcc
ADC_MODE(ADC_VCC);
/////////////////////
// Domoticz Classe
/////////////////////
#include "Domoticz.h"
Domoticz domo("192.168.1.3", "81", "Livebox-37cc", "8A6060920A8A86896F770F2C47");
#include "Modules.h"
Modules modules;
Params * params;
#include "Ecran.h"
Ecran * ecran;
#include "Cube.h"
#include "Graph.h"
#include "Point.h"
#include "ServeurWeb.h"
ServeurWeb * serveurWeb;
WiFiServer server(80);
#include "Octoprint.h"
Octoprint octoprint("192.168.1.3", "5000", "B5746ACFF37140D0B5F6FEAAC4413B5C");
// Convert image to char array http://www.digole.com/tools/PicturetoC_Hex_converter.php
// Hex values that represent Bitcoin logo
char bitcoin[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0x60, 0x70,
0x18, 0x18, 0x18, 0x0C, 0x0C, 0x06, 0x06, 0x06, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x06, 0x06,
0x06, 0x0C, 0x0C, 0x18, 0x18, 0x18, 0x70, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0x38, 0x1E, 0x07, 0x03,
0x01, 0x80, 0xC0, 0xF0, 0xF8, 0xF8, 0x3E, 0x3E, 0x3E, 0x3F, 0x3F, 0x03, 0x03, 0x03, 0x3F, 0x03,
0x03, 0x03, 0x3F, 0x3F, 0x7F, 0x7E, 0xFE, 0xFE, 0xF8, 0xF8, 0xF0, 0xC0, 0x80, 0x01, 0x03, 0x07,
0x1E, 0x38, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFC, 0x1F, 0x03,
0x00, 0x00, 0x00, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3E, 0x3E, 0x3E, 0x3E, 0x1C, 0x00, 0x00, 0x00, 0x40, 0xE1, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x03, 0x1F, 0xFC, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x3F, 0xFC, 0xC0, 0x00, 0x00, 0x00, 0x07, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x3F,
0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x3F, 0x3F, 0x3F, 0x3E, 0x1E, 0x00, 0x00, 0x00, 0x00,
0xC1, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x07, 0x00, 0x00, 0x00, 0xC0, 0xFC, 0x3F, 0x03, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x1E, 0x3C, 0x60, 0xE0, 0x80, 0x80, 0x03, 0x07,
0x0F, 0x1F, 0x3E, 0x3E, 0x7E, 0x7E, 0x7E, 0x60, 0xE0, 0xE0, 0xFE, 0xE0, 0xE0, 0xE0, 0x7E, 0x7E,
0x7E, 0x7F, 0x3F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x80, 0x80, 0xE0, 0x60, 0x3C, 0x1E, 0x03, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x03, 0x06, 0x06, 0x0C, 0x0C, 0x18, 0x18, 0x18, 0x30, 0x30, 0x30, 0x20, 0x60, 0x60, 0x60,
0x60, 0x20, 0x30, 0x30, 0x30, 0x18, 0x18, 0x18, 0x0C, 0x0C, 0x06, 0x06, 0x03, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
char puma[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x1c,0x00,0x00
,0x00,0x00,0x1f,0xf8,0x00,0x00,0x00,0x00,0x7e,0x00,0x00
,0x00,0x00,0x3f,0xfe,0x00,0x00,0x00,0x00,0xfc,0x00,0x00
,0x00,0x00,0x3f,0xff,0x80,0x00,0x00,0x01,0xf8,0x00,0x00
,0x00,0x00,0x3f,0xff,0xe0,0x00,0x00,0x03,0xc0,0x00,0x00
,0x00,0x00,0x1f,0xff,0xf0,0x00,0x00,0x03,0x80,0x00,0x00
,0x00,0x00,0x01,0xff,0xfc,0x00,0x00,0x07,0x00,0x00,0x00
,0x00,0x00,0x00,0xff,0xfe,0x00,0x00,0x06,0x00,0x00,0x00
,0x00,0x00,0x7f,0xff,0xff,0x80,0x00,0x0c,0x00,0x00,0x00
,0x00,0x00,0x7f,0xff,0xff,0xc0,0x00,0x08,0x00,0x00,0x00
,0x00,0x00,0x77,0xff,0xff,0xf0,0x00,0x18,0x00,0x00,0x00
,0x00,0x00,0x00,0xf9,0xff,0xf8,0x00,0x30,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x7f,0xfe,0x00,0x70,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x3f,0xff,0xc1,0xe0,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0xff,0xff,0xc0,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x03,0xff,0xff,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x80,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x80,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xc0,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xc0,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xc0,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xc0,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xc0,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xc0,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xc0,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xe0,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xf0,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1c,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1c,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1c,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1c,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1c,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
Params p;
Ecran e;
ServeurWeb sw;
// domoticz
String macID = "";
unsigned long milli;
void setup()
{
Serial.begin(9600);
/* sda scl */
Wire.pins(SDA, SCL);
Wire.begin(SDA, SCL);
// Conversion d'objet en pointeur
params = &p;
ecran = &e;
serveurWeb = &sw;
serveurWeb->domoticz = &domo;
serveurWeb->modules = &modules;
serveurWeb->server = &server;
serveurWeb->server->begin();
ecran->LcdBitmap(LCD_X, LCD_Y, bitcoin); // display Bitcoin Logo LCD_X
delay(500);
domo.initWifi();
macID = domo.generateKey();
ecran->LcdString(0, 0, domo._domoticz);
ecran->LcdChar(0, 10, "ID : ");
ecran->LcdString(40, 10, macID);
ecran->u8g2->sendBuffer();
domo.getIdFromDomoticz(macID, params);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH);
octoprint.connect();
octoprint.executeJson("/api/printer", "", "");
octoprint.executeJsonPost("/api/printer/command", "{\"command\": \"M503\"}");
milli = millis();
// for (int i = 0; i <= 100; i+=10) {
// ecran->LcdClear();
// ecran->drawRect(1, 1, LCD_X -1, LCD_Y -1);
// ecran->drawJauge(10, 24, LCD_X -10, 34, i, "Jauge");
// ecran->u8g2->sendBuffer();
// delay(100);
// }
// Cube cube(ecran);
// cube.draw();
// ecran->LcdClear();
// //g.drawGraph();
// ecran->u8g2->sendBuffer();
// ecran->intro();
// delay(2000);
}
void loop()
{
serveurWeb->loop();
if (milli + params->sleepTime * 1000 <= millis() ) {
// Avoid WDT reset during long process
yield();
milli = millis();
ecran->LcdClear();
modules.barometre();
modules.readTemp();
printInfo();
ecran->LcdClear();
// Test Json
domo.readTempDayValues(params->esp8266_id);
ecran->LcdClear();
Graph g (ecran, 0, 0, 84, 48) ;
g.title = "Graph";
g.axe_x = "x";
g.axe_y = "y";
g.drawGraph();
}
}
void printInfo()
{
boolean connected = domo.connect();
Serial.println("Dans printInfo " + connected + ' ' + params->esp8266_id);
// Domoticz format /json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT
if (connected && params->esp8266_id != "") {
Serial.println("Dans set temperature");
//domo.executeJson();
String svalue = String(modules.temp) + ";" + String(modules.humidity) + ";0";
ecran->LcdString(0,5, "T :" + String(modules.temp));
Serial.println(svalue);
domo.executeJson("/json.htm?type=command&param=udevice&idx=" + params->esp8266_id, svalue, "0");
domo._client.stop();
delay(200);
}
connected = domo.connect();
if (connected && params->esp8266_id_Vcc != "") {
Serial.print(" Envoi tension ");
Serial.print(params->esp8266_id_Vcc);
Serial.print(" ");
String vcc = domo.readVcc();
Serial.println(vcc);
ecran->LcdString(0, 10, "Vcc:" + vcc);
// domo._client.print("GET /json.htm?type=command&param=udevice&idx=");
domo.executeJson("/json.htm?type=command&param=udevice&idx=" + params->esp8266_id_Vcc, vcc, "0");
domo._client.stop();
}
}

View File

@@ -0,0 +1,202 @@
#include "Ecran.h"
Ecran::Ecran()
{
Serial.println("--------------------------------------");
Serial.println("Init Ecran");
// ECRAN
LcdInitialise();
// LcdClear();
// LcdChar(0, 0, "Starting");
//
// FIN ECRAN
}
// ECRAN Methodes
void Ecran::LcdCharacter(char character)
{
LcdWrite(LCD_D, 0x00);
for (int index = 0; index < 5; index++)
{
LcdWrite(LCD_D, ASCII[character - 0x20][index]);
}
LcdWrite(LCD_D, 0x00);
}
void Ecran::LcdClear(void)
{
u8g2->clearBuffer();
// for (int index = 0; index < LCD_X * LCD_Y / 8; index++)
// {
// LcdWrite(LCD_D, 0x00);
// }
}
void Ecran::LcdInitialise(void)
{
static U8G2_PCD8544_84X48_F_4W_SW_SPI u(U8G2_R0,
/* clock=*/ PIN_SCLK,
/* data=*/ PIN_SDIN,
/* cs=*/ PIN_SCE,
/* dc=*/ PIN_DC,
/* reset=*/ PIN_RESET); // Nokia 5110 Display
u8g2 = &u;
u8g2->begin();
u8g2->setFont(u8g2_font_6x10_tf);
u8g2->setFontRefHeightExtendedText();
u8g2->setDrawColor(1);
u8g2->setFontPosTop();
u8g2->setFontDirection(0);
setContrast(contrast);
}
void Ecran::LcdChar(int x, int y, char *characters)
{
u8g2->drawStr(x, y, characters);
}
void Ecran::LcdString(int x, int y, String s)
{
char cs[s.length() + 1];
s.toCharArray(cs, s.length() + 1);
LcdChar(x, y, cs);
}
void Ecran::LcdWrite(byte dc, byte data)
{
digitalWrite(PIN_DC, dc);
digitalWrite(PIN_SCE, LOW);
shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
digitalWrite(PIN_SCE, HIGH);
}
void Ecran::setContrast(byte contrast)
{
//analogWrite(PIN_LCD, contrast);
}
//This takes a large array of bits and sends them to the LCD
void Ecran::LcdBitmap(int x, int y, char my_array[])
{
for (int index = 0 ; index < (x * y / 8) ; index++)
{
LcdWrite(LCD_DATA, my_array[index]);
}
}
//void Ecran::printInfos()
//{
// // ECRAN
// LcdClear();
// float fractionC;
//
// fractionC = temperature - ((int)temperature);
//
// gotoXY(0,0);
// LcdString("TEMP ");
// itoa(temperature,strBuffer,10);
// LcdString(strBuffer);
// itoa(fractionC,strBuffer,10);
// LcdString(".");
// LcdString(strBuffer);
// LcdString("C ");
//
// fractionC = pression - ((int) pression);
//
// gotoXY(0,10);
// LcdString("Pres ");
// itoa(pression,strBuffer,10);
// LcdString(strBuffer);
// itoa(fractionC,strBuffer,10);
// LcdString(".");
// LcdString(strBuffer);
// LcdString("hp");
//
// fractionC = lux - ((int) lux);
//
// gotoXY(0,20);
// LcdString("Lum ");
// itoa(lux,strBuffer,10);
// LcdString(strBuffer);
// itoa(fractionC,strBuffer,10);
// LcdString(".");
// LcdString(strBuffer);
// LcdString("Lux ");
// // FIN ECRAN
//}
void Ecran::intro()
{
int a = 0;
u8g2->clearBuffer();
u8g2->setFontDirection(0);
LcdChar(0, 0, "Starting");
u8g2->drawStr(30+a,31, " 0");
u8g2->setFontDirection(1);
u8g2->drawStr(30,31+a, " 90");
u8g2->setFontDirection(2);
u8g2->drawStr(30-a,31, " 180");
u8g2->setFontDirection(3);
u8g2->drawStr(30,31-a, " 270");
u8g2->sendBuffer();
delay(2000);
const uint8_t frame_size = 24;
u8g2->clearBuffer();
u8g2->drawBox(0, frame_size * 0.5, frame_size * 5, frame_size);
u8g2->drawStr(frame_size * 0.5, 50, "Black");
u8g2->drawStr(frame_size * 2, 50, "White");
u8g2->drawStr(frame_size * 3.5, 50, "XOR");
u8g2->setBitmapMode(false /* solid */);
u8g2->drawStr(0, 0, "Solid bitmap");
u8g2->sendBuffer();
delay(2000);
u8g2->clearBuffer();
u8g2->setDrawColor(0);// Black
u8g2->drawXBMP(frame_size * 0.5, 24, cross_width, cross_height, cross_bits);
u8g2->setDrawColor(1); // White
u8g2->drawXBMP(frame_size * 2, 24, cross_width, cross_height, cross_bits);
u8g2->setDrawColor(2); // XOR
u8g2->drawXBMP(frame_size * 3.5, 24, cross_width, cross_height, cross_bits);
u8g2->sendBuffer();
delay(2000);
}
void Ecran::drawRect(int x0, int y0, int x1, int y1)
{
u8g2->drawLine(x0, y0, x1, y0);
u8g2->drawLine(x1, y0, x1, y1);
u8g2->drawLine(x1, y1, x0, y1);
u8g2->drawLine(x0, y1, x0, y0);
// u8g2->drawLine(LCD_X / 2, 1, LCD_X / 2, LCD_Y -1);
}
void Ecran::drawJauge(int x0, int y0, int x1, int y1, int val, String text)
{
drawRect(x0, y0, x1, y1);
if (val > 100) {
val = x1;
}
u8g2->drawBox(x0, y0, ((x1 - x0) * val) / 100, y1 - y0);
if (text != "") {
LcdString(x0, y0, text);
}
// u8g2->drawLine(LCD_X / 2, 1, LCD_X / 2, LCD_Y -1);
}
void Ecran::drawFace(int x0, int y0, int x1, int y1, int x2, int y2)
{
u8g2->drawLine(x0, y0, x1, y1);
u8g2->drawLine(x1, y1, x2, y2);
u8g2->drawLine(x2, y2, x0, y0);
}

160
ESP8266_DOMOTICZ_ECRAN/Ecran.h Executable file
View File

@@ -0,0 +1,160 @@
#ifndef Ecran_h
#define Ecran_h
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
#include "Pins.h"
#define LCD_C LOW
#define LCD_D HIGH
#define LCD_COMMAND 0
#define LCD_X 84
#define LCD_Y 48
//The DC pin tells the LCD if we are sending a command or data
#define LCD_COMMAND 0
#define LCD_DATA 1
static const byte ASCII[][5] =
{
{0x00, 0x00, 0x00, 0x00, 0x00} // 20
,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #
,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $
,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %
,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &
,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '
,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (
,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )
,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *
,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +
,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,
,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -
,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .
,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f backslash
,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0
,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1
,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2
,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3
,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4
,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5
,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6
,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7
,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8
,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9
,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :
,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;
,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <
,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =
,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >
,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?
,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @
,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A
,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B
,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C
,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D
,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E
,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F
,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G
,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H
,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I
,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J
,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K
,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L
,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M
,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N
,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O
,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P
,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q
,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R
,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S
,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T
,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U
,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V
,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W
,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X
,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y
,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z
,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c ¥
,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^
,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _
,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 `
,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a
,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b
,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c
,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d
,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e
,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f
,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g
,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h
,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i
,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j
,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k
,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l
,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m
,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n
,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o
,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p
,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q
,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r
,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s
,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t
,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u
,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v
,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w
,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x
,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y
,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z
,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b {
,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c |
,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d }
,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ←
,{0x78, 0x46, 0x41, 0x46, 0x78} // 7f →
};
// DEMO
#define cross_width 24
#define cross_height 24
static const unsigned char cross_bits[] U8X8_PROGMEM = {
0x00, 0x18, 0x00, 0x00, 0x24, 0x00, 0x00, 0x24, 0x00, 0x00, 0x42, 0x00,
0x00, 0x42, 0x00, 0x00, 0x42, 0x00, 0x00, 0x81, 0x00, 0x00, 0x81, 0x00,
0xC0, 0x00, 0x03, 0x38, 0x3C, 0x1C, 0x06, 0x42, 0x60, 0x01, 0x42, 0x80,
0x01, 0x42, 0x80, 0x06, 0x42, 0x60, 0x38, 0x3C, 0x1C, 0xC0, 0x00, 0x03,
0x00, 0x81, 0x00, 0x00, 0x81, 0x00, 0x00, 0x42, 0x00, 0x00, 0x42, 0x00,
0x00, 0x42, 0x00, 0x00, 0x24, 0x00, 0x00, 0x24, 0x00, 0x00, 0x18, 0x00, };
class Ecran
{
public:
Ecran();
void drawFace(int x0, int y0, int x1, int y1, int x2, int y2);
void drawRect(int x0, int y0, int x1, int y1);
void drawJauge(int x0, int y0, int x1, int y1, int val, String text);
void intro();
void LcdWrite(byte dc, byte data);
void LcdChar(int x, int y, char *characters);
void LcdString(int x, int y, String s);
void LcdInitialise(void);
void LcdClear(void);
void LcdBitmap(int x, int y,char my_array[]);
void LcdCharacter(char character);
void setContrast(byte contrast);
private:
public:
long contrast = 200;
U8G2_PCD8544_84X48_F_4W_SW_SPI * u8g2;
};
#endif

View File

@@ -0,0 +1,39 @@
#include "Graph.h"
Graph::Graph(Ecran * _ecran, int _x0, int _y0 ,int _x1, int _y1)
{
Serial.println("--------------------------------------");
Serial.println("Init Graph");
x0 = _x0;
x1 = _x1;
y0 = _y0;
y1 = _y1;
ecran = _ecran;
}
void Graph::drawAxes()
{
ecran->LcdString(0, 0, axe_x);
ecran->LcdString(x1-10, y1-10, axe_y);
ecran->u8g2->drawLine(x0 + 5, y1 - 1, x1, y1 -1);
ecran->u8g2->drawLine(x0 + 5, y0 + 5, x0 + 5, y1);
}
void Graph::drawTitle()
{
if (title != "") {
ecran->LcdString(x0 + 20, y0, title);
}
}
void Graph::drawDatas()
{
}
void Graph::drawGraph()
{
drawAxes();
drawTitle();
// drawDatas();
ecran->u8g2->sendBuffer();
}

21
ESP8266_DOMOTICZ_ECRAN/Graph.h Executable file
View File

@@ -0,0 +1,21 @@
#ifndef Graph_h
#define Graph_h
#include <Arduino.h>
#include "Ecran.h"
#include "Point.h"
class Graph {
public :
Graph(Ecran * ecran, int x0, int y0 ,int x1, int y1);
void drawAxes();
void drawTitle();
void drawDatas();
void drawGraph();
public :
Ecran * ecran;
int x0, y0,x1, y1;
String title, axe_x, axe_y;
Point datas[];
};
#endif

View File

@@ -0,0 +1,122 @@
#include "Modules.h"
// int status = WL_IDLE_STATUS; // the Wifi radio's status
//WiFiClient client;
// Dallas
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
Modules::Modules()
{
Serial.println("--------------------------------------");
Serial.println("Init Module");
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW);
pinMode(RELAY_PIN_02, OUTPUT);
digitalWrite(RELAY_PIN_02, LOW);
pinMode(RELAY_PIN_03, OUTPUT);
digitalWrite(RELAY_PIN_03, LOW);
pinMode(RELAY_PIN_03, OUTPUT);
digitalWrite(RELAY_PIN_03, LOW);
}
bool Modules::readTemp()
{
//DS18B20.begin();
Serial.println("--------------------------------------");
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
Serial.print("Température Dallas =");
Serial.println(temp);
if (temp > 0 && temp < 70) {
return true;
}
return false;
}
void Modules::barometre() {
/* See Example: TypeA_WithDIPSwitches */
delay(500);
Serial.print("Barometre: ");
Serial.println(bmp.begin());
// BMP
if (bmp.begin()) {
delay(1000);
temp = bmp.readTemperature();
pressure = bmp.readPressure() / 100.0;
pression = pressure / 101.325;
pression = pression * 0.760 * 100;
// http://en.wikipedia.org/wiki/Atmospheric_pressure#Mean_sea_level_pressure
// Serial.print("Presiure la nivelul marii (calculata) = ");
presiune = bmp.readSealevelPressure(ALTITUDE) / 101.325;
presiune = presiune * 0.760;
Serial.print("Temperature="); Serial.println(temp);
Serial.print("pressure="); Serial.println(pressure);
Serial.print("pression="); Serial.println(pression);
}
else {
Serial.print("Pas de barometre détecté");
}
}
void Modules::sleep(int sleepTime)
{
Serial.print("Go to sleep ");
Serial.println(sleepTime);
delay(20);
ESP.deepSleep(sleepTime * 1000000L); // Infini
//sleepWifi();
delay(200);
}
void Modules::readDht()
{
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
humidity = dht.readHumidity();
// Read temperature as Celsius
temp = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temp) || isnan(f)) {
// Serial.println("Failed to read from DHT sensor!");
return;
} else {
// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, humidity);
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temp);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hi);
Serial.println(" *F");
}
}
void Modules::relay(int pin, int value)
{
delay(100);
digitalWrite(pin, value);
delay(100);
}

View File

@@ -0,0 +1,36 @@
#ifndef Modules_h
#define Modules_h
#include <Arduino.h>
#include <Adafruit_BMP085.h>
#include <DallasTemperature.h>
#include "DHT.h"
#include "Pins.h"
// ################# Barometre ####
#define ALTITUDE 19.0 // Altitude of SparkFun's HQ in Boulder, CO. in meters
#define DHTTYPE DHT11 // DHT 11
//SFE_BMP180 pressure;
// #####################
class Modules
{
public:
Modules();
bool readTemp();
void barometre();
void readDht();
void sleep(int sleepTime);
void relay(int pin, int value);
private:
public:
Adafruit_BMP085 bmp;
double humidity = 0;
double temp = 0;
double pression = 0;
double pressure = 0;
double presiune = 0;
int end_filament = 0;
};
#endif

View File

@@ -0,0 +1,178 @@
#include "Octoprint.h"
Octoprint::Octoprint(String octoprint, String port, String API)
{
_octoprint = octoprint;
_port = port;
_API = API;
}
boolean Octoprint::connect()
{
// Domo
char _octo[_octoprint.length() + 1];
_octoprint.toCharArray(_octo, _octoprint.length() + 1);
// Port
char portc[_port.length() + 1];
_port.toCharArray(portc, _port.length() + 1);
int _iport = atoi(portc);
boolean connected = _client.connect(_octo, _iport);
Serial.print(_octo);
Serial.print(" ");
Serial.print(_iport);
Serial.print(" ");
Serial.print(" connected ");
Serial.print(connected);
Serial.print(" ");
Serial.println(WiFi.localIP());
return connected;
}
void Octoprint::close()
{
}
void Octoprint::executeJson(String json, String svalue, String nvalue)
{
// Domo
char _octo[_octoprint.length() + 1];
_octoprint.toCharArray(_octo, _octoprint.length() + 1);
// Port
char portc[_port.length() + 1];
_port.toCharArray(portc, _port.length() + 1);
int _iport = atoi(portc);
_client.print("GET " + json); //"GET /json.htm?type=command&param=getuservariables");
if (svalue != "") {
_client.print("&svalue=" + svalue);
}
if (nvalue != "") {
_client.print("&nvalue=" + nvalue);
}
_client.println(" HTTP/1.1");
_client.print("Host: ");
_client.print(_octo);
_client.print(":");
_client.println(_iport);
_client.println("User-Agent: Arduino-ethernet");
_client.println("X-Api-Key:" + _API);
_client.println("Connection: close");
_client.println();
Serial.println("json=" + json);
long interval = 2000;
unsigned long currentMillis = millis(), previousMillis = millis();
while(!_client.available()){
if( (currentMillis - previousMillis) > interval ){
Serial.println("Timeout");
_client.stop();
return;
}
currentMillis = millis();
}
// while (_client.connected())
// {
// if ( _client.available() )
// {
// char str=_client.read();
// Serial.print(str);
// }
// }
while (1)
{
// Avoid WDT reset during long process
yield();
String line = readLine();
if (line == "") {
break;
}
Serial.println(line);
}
}
void Octoprint::executeJsonPost(String json, String postData)
{
if (connect()) {
_client.println("POST " +json + " HTTP/1.1");
_client.println("Host: " + _octoprint + ":" + _port);
_client.println("Cache-Control: no-cache");
_client.println("X-Api-Key:" + _API);
_client.println("Content-Type: application/json");
_client.print("Content-Length: ");
_client.println(postData.length());
_client.println();
_client.println(postData);
long interval = 2000;
unsigned long currentMillis = millis(), previousMillis = millis();
while(!_client.available()){
if( (currentMillis - previousMillis) > interval ){
Serial.println("Timeout");
_client.stop();
return;
}
currentMillis = millis();
}
// while (_client.connected())
// {
// if ( _client.available() )
// {
// char str=_client.read();
// Serial.print(str);
// }
// }
while (1)
{
// Avoid WDT reset during long process
yield();
String line = readLine();
if (line == "") {
break;
}
Serial.println(line);
}
}
}
String Octoprint::getIndexOfString(String data, String separator, int index)
{
int found = 0;
int strIndex[] = { 0, -1 };
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator.charAt(0) || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i + 1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
String Octoprint::readLine()
{
return _client.readStringUntil('\n');
}

View File

@@ -0,0 +1,33 @@
#ifndef Octoprint_h
#define Octoprint_h
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "Params.h"
class Octoprint
{
public:
Octoprint(String octoprint, String port, String API);
boolean connect();
void close();
void executeJson(String json, String svalue, String nvalue);
void executeJsonPost(String json, String postData);
//String getIdFromOctoprint();
String readLine();
static String getIndexOfString(String data, String separator, int index);
private:
const char* _pass;
public:
const char* _ssid;
WiFiClient _client;
char _octo[];
int _iport;
String _octoprint;
String _port;
String _API;
};
#endif

View File

@@ -0,0 +1,7 @@
#include "Params.h"
Params::Params()
{
}

15
ESP8266_DOMOTICZ_ECRAN/Params.h Executable file
View File

@@ -0,0 +1,15 @@
#ifndef Params_h
#define Params_h
#include <Arduino.h>
class Params {
public :
Params();
public :
String esp8266_id;
String esp8266_id_Vcc;
int sleepTime;
};
#endif

26
ESP8266_DOMOTICZ_ECRAN/Pins.h Executable file
View File

@@ -0,0 +1,26 @@
#ifndef Pins_h
#define Pins_h
#include <Arduino.h>
#define SDA D1
#define SCL D2
#define ONE_WIRE_BUS 5 // DS18B20 pin
#define DHTPIN 11 // what pin we're connected to
#define RELAY_PIN D0
#define RELAY_PIN_02 D1
#define RELAY_PIN_03 D2
#define RELAY_PIN_04 D6
#define BUTTON_PIN 0
// Ecran
#define PIN_RESET D3
#define PIN_SCE D4
#define PIN_DC D8
#define PIN_SDIN D7
#define PIN_SCLK D5
//#define PIN_LCD D6 // backlight
//#define PIN_FADER 1 // analog
//#define PIN_TMP 0 // analog
#endif

View File

@@ -0,0 +1,12 @@
#include "Point.h"
Point::Point()
{
x = 0;
y = 0;
}
Point::Point(int _x, int _y)
{
x = _x;
y = _y;
}

View File

@@ -0,0 +1,16 @@
#ifndef Point_h
#define Point_h
#include <Arduino.h>
class Point {
public :
Point();
Point(int _x, int _y);
public :
float x, y;
};
#endif

View File

@@ -0,0 +1,791 @@
#include "ServeurWeb.h"
#include <ESP8266WiFi.h>
#include "Pins.h"
ServeurWeb::ServeurWeb()
{
Serial.println("--------------------------------------");
Serial.println("Init ServeurWeb");
//domoticz = _domoticz;
// WifiServer server(80);
//server->begin();
}
void ServeurWeb::loop()
{
//Serial.println("--------------------------------------");
//Serial.println("Loop ServeurWeb");
// read the state of the end button value:
modules->end_filament = digitalRead(BUTTON_PIN);
//Serial.println('fin de filament ' + modules->end_filament);
if ((bcl % (refresh * 60)) == 0) { //DELAI_LECTURE == 0) {
// infos();
nbData += 1;
nbData = nbData % 256;
}
// Check if a client has connected
client = server->available();
if (!client) {
// infos();
// delay(1000);
bcl++;
return;
}
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
// client.flush();
// Match the request
int val = -1; // We'll use 'val' to keep track of both the
// request type (read/set) and value if set.
if (req.indexOf("/admin") != -1) {
val = -3;
//int end = readPage(START_ADDRESS);
//pageAdmin();
pageMenu(PAGE_ADMIN);
} else if (req.indexOf("/graph") != -1) {
pageMenu(PAGE_GRAPH);
} else if (req.indexOf("/reset") != -1) {
client.println("Reset done. SSID, PASS, Domoticz, port & id cleaned.");
delay(100);
// } else if (req.indexOf("/ident") != -1) {
//
// ident(req);
} else if (req.indexOf("/status") != -1) {
//printWifiStatus();
pageMenu(PAGE_STATUS);
} else if (req.indexOf("/infos") != -1) {
pageMenu(PAGE_INFOS);
} else if (req.indexOf("/relay_01") != -1) {
client.print("relay_01=");
client.print(val0); //digitalRead(0));
delay(100);
} else if (req.indexOf("/relay_02") != -1) {
client.print("relay_02=");
client.print(val2); //digitalRead(2));
delay(100);
} else if (req.indexOf("/action") != -1) {
// Affectation des variables aux sorties correspondantes
if (req.indexOf("relay_01=false") != -1)
{
val0 = HIGH;
modules->relay(RELAY_PIN, val0);
}
if (req.indexOf("relay_01=true") != -1)
{
val0 = LOW;
modules->relay(RELAY_PIN, val0);
}
if (req.indexOf("relay_02=false") != -1)
{
val2 = HIGH;
digitalWrite(RELAY_PIN_02, val2);
}
if (req.indexOf("relay_02=true") != -1)
{
val2 = LOW;
digitalWrite(RELAY_PIN_02, val2);
}
if (req.indexOf("relay_03=false") != -1)
{
val3 = HIGH;
digitalWrite(RELAY_PIN_03, val3);
}
if (req.indexOf("relay_03=true") != -1)
{
val3 = LOW;
digitalWrite(RELAY_PIN_03, val3);
}
if (req.indexOf("relay_04=false") != -1)
{
val4 = HIGH;
digitalWrite(RELAY_PIN_04, val4);
}
if (req.indexOf("relay_04=true") != -1)
{
val4 = LOW;
digitalWrite(RELAY_PIN_04, val4);
}
Serial.println("Val0=" + String(val0) + " Val2=" + String(val2));
pageMenu(PAGE_MENU);
} else if (req.indexOf("/menu") != -1) {
//pageMenu();
pageMenu(PAGE_MENU);
} else {
pageMenu(PAGE_MENU);
}
//client.stop();
// The client will actually be disconnected
// when the function returns and 'client' object is detroyed
}
String ServeurWeb::getValueFrom(String request, int deb, int fin) {
int bufLength = ((fin) - (deb + 5)); //the 5 is for the "name=" string
String tmp = request.substring((deb + 5), (fin - 1));
return tmp;
}
char* ServeurWeb::convertToChar(String s, char* buf) {
char c[s.length() + 1];
s.toCharArray(c, s.length() + 1);
return c;
}
void ServeurWeb::infos()
{
int nb = 0;
//WiFiClient client2; // = domoticz->_client;
// Domoticz format /json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT
// Type
// 0 = Integer, e.g. -1, 1, 0, 2, 10
//1 = Float, e.g. -1.1, 1.2, 3.1
//2 = String
//3 = Date in format DD/MM/YYYY
//4 = Time in 24 hr format HH:MM
//5 = DateTime (but the format is not checked)
// SAve variable "json.htm?type=command&param=saveuservariable&vname=" + domoticz->_macID + "uservariablename&vtype=2&vvalue=uservariablevalue"
// GEt Variables
// http://192.168.0.10:8080/json.htm?type=command&param=getuservariables&idx=4
// // Domo
// char domoticz->_domoc[domoticz.length() + 1];
// domoticz.toCharArray(domoticz->_domoc, domoticz.length() + 1);
// // Port
// char portc[port.length() + 1];
// port.toCharArray(portc, port.length() + 1);
// int domoticz->_iport = atoi(portc);
Serial.print(domoticz->_domoticz);
Serial.print(" ");
Serial.println(domoticz->_port);
Serial.print(" radiateur=");
Serial.print(radiateur);
Serial.print(" temperature=");
Serial.print(temp);
Serial.print(" consigne=");
Serial.print(cons);
Serial.println("");
// Avoid WDT reset during long process
yield();
// -------------------
// LECTURE PARAM
// -------------------
if (radiateur == "") {
Serial.println("Lecture parametre dans domoticz");
if (domoticz->connect()) {
Serial.println("Connected to domoticz");
domoticz->executeJson("/json.htm?type=command&param=getuservariables", "", "");
// Read the first line of the request
while (1) {
// Avoid WDT reset during long process
yield();
String req = domoticz->readLine();
// Serial.println(req);
if (req.indexOf(domoticz->_macID) != -1) {
Serial.println(req);
// Serial.println(req);
req = domoticz->readLine();
req = domoticz->readLine();
String val = req.substring(req.indexOf(":") + 2, req.length() - 1);
Serial.println(val);
val.replace("\"", "");
radiateur = domoticz->getIndexOfString(val, separator, 0);
temp = domoticz->getIndexOfString(val, separator, 1);
cons = domoticz->getIndexOfString(val, separator, 2);
refresh = domoticz->getIndexOfString(val, separator, 3).toInt();
nom = domoticz->getIndexOfString(val, separator, 4);
for (int cpt = 0; cpt < 5; cpt++ ) {
Serial.print(domoticz->getIndexOfString(val, separator, cpt));
}
Serial.println("");
Serial.println("radiateur=" + radiateur);
Serial.println("temp=" + temp);
Serial.println("cons=" + cons);
break;
}
if (req == "" || nb > 500) {
break;
}
nb++;
}
//client2.stop();
delay(100);
}
}
if (radiateur != "") {
if (domoticz->connect()) {
Serial.println("Connected to domoticz lecteur statut radiateur" );
domoticz->executeJson("/json.htm?type=devices&rid=" + radiateur, "", "");
// Read the first line of the request
while (1) {
// Avoid WDT reset during long process
yield();
String req = domoticz->readLine();
if (req.indexOf("\"Status\"") != -1) {
Serial.println(req.substring(req.indexOf(":") + 2));
break;
}
if (req == "" || nb > 500) {
break;
}
nb++;
}
//client2.stop();
delay(100);
}
if (domoticz->connect()) {
Serial.println("Connected to domoticz lecture donnée température" );
domoticz->executeJson("/json.htm?type=devices&rid=723", "","");
// Read the first line of the request
while (1) {
// Avoid WDT reset during long process
yield();
String req = domoticz->readLine();
Serial.println(req);
if (req.indexOf("\"Temp\"") != -1) {
String tmp = req.substring(req.indexOf(":") + 2);
tmp = tmp.substring(0, tmp.indexOf(".") + 2);
Serial.println(tmp);
if (data == "") {
data += tmp;
labels = "\"0\"";
} else {
data += "," + tmp;
if (nbData % 10 == 0) {
labels = labels + "," + "\"" + nbData + "\"";
} else {
labels = labels + "," + "\"" + "\"";
}
}
if (data.length() > 500) {
data = data.substring(data.indexOf(",") + 1);
labels = labels.substring(labels.indexOf(",") + 1);
}
Serial.println(data);
Serial.println(labels);
break;
}
if (req == "" || nb > 500) {
break;
}
nb++;
}
//client2.stop();
delay(100);
}
if (domoticz->connect()) {
Serial.println("Connected to domoticz lecteur consigne" );
domoticz->executeJson("/json.htm?type=devices&rid=" + cons, "", "");
// Read the first line of the request
while (1) {
// Avoid WDT reset during long process
yield();
String req = domoticz->readLine();
if (req.indexOf("\"SetPoint\"") != -1) {
String value = req.substring(req.indexOf(":") + 2);
//value = .substring(req.indexOf(":") + 1);
value.trim();
Serial.println(value);
break;
}
if (req == "" || nb > 500) {
break;
}
nb++;
}
//client2.stop();
delay(100);
}
}
// Avoid WDT reset during long process
yield();
Serial.println("Fin infos");
// Avoid WDT reset during long process
yield();
}
void ServeurWeb::printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
// PAge
client.println("<p>Connected to ");
client.println(WiFi.SSID());
client.println("</p><p>Ip: ");
client.println(ip);
client.println("</p><p>Force du signal:");
client.println(rssi);
client.println(" dBm</p>");
client.println("<p>Domoticz:");
client.println(domoticz->_domoticz);
client.println(":");
client.println(domoticz->_port);
client.println("</p>");
//
// client.println("<div class='c100 p25 dark orange'>");
// client.println(" <span>25%</span>");
// client.println(" <div class='slice'>");
// client.println(" <div class='bar'></div>");
// client.println(" <div class='fill'></div>");
// client.println(" </div>");
// client.println("</div>");
client.println("<button class='boutonTemp' onclick='click()'>" + temp + "</button>");
client.println("<button class='boutonCons' onclick='click()'>" + cons + "</button>");
}
////////////////////////////////////////////
////// PAGE MENU
////////////////////////////////////////////
void ServeurWeb::pageMenu(int page) {
client.println("<html>");
client.println("<head>");
client.println("<link rel=\"shortcut icon\" href=\"http://" + domoticz->_domoticz + ":" + domoticz->_port + "/favicon.ico\">");
if (page == PAGE_GRAPH) {
client.println("<meta http-equiv=\"refresh\" content=\"60\" >");
}
if (page == PAGE_MENU) {
// // Look des champs de saisis
// client.println("<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"http://" + domoticz->_domoticz + "/ESP8266/css/styles.css\">");
// // Look Bouton toggle
// client.println("<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"http://" + domoticz->_domoticz + "/ESP8266/css/toggles-soft.css\">");
}
menuStyle(page);
client.println("</head>");
menuBody(page);
client.println("</html>\n\r");
}
void ServeurWeb::menuBody(int page) {
client.println("<body>");
client.println("<header role='banner'>");
client.println("<div class='wrapper'>");
client.print("<h1> ");
client.print(nom + " " + domoticz->_macID);
client.println("</h1>");
client.println("<nav id='nav' role='navigation'>");
client.println("<div class='show_menu_btn' data-target='#nav ul' data-shown-text='Hide menu' data-hidden-text='Show menu' >Show menu</div>");
client.println("<ul>");
client.println("<li><a href='/menu'>Menu</a></li>");
client.println("<li><a href='/admin'>Admin</a></li>");
//client.println("<li><a href='/infos'>Infos</a></li>");
client.println("<li><a href='/status'>Status</a></li>");
//client.println("<li><a href='/reset'>Reset</a></li>");
client.println("<li><a href='/graph'>Graph</a></li>");
//client.println("<li><a href='/aide'>Aide</a></li>");
client.println("</ul>");
client.println("</nav>");
client.println("</div>");
client.println("</header>");
client.println("<main role='main'>");
client.println("<div class='wrapper'>");
if (page == PAGE_MENU) {
client.print("<form><div><input type=\"checkbox\" id=\"relay_01\" onclick=\"handleClick(this);\" ");
if (val0 == 0) {
client.print("unchecked");
} else {
client.print("checked");
}
client.println("><label for=\"relay_01\" onclick=\"relay_01();\">Relai 1</label></div></form>");
client.println("<form><div><input type=\"checkbox\" id=\"relay_02\" onclick=\"handleClick(this);\" ");
if (val2 == 0) {
client.print("unchecked");
} else {
client.print("checked");
}
client.println("><label for=\"relay_02\" onclick=\"relay_02();\">Relai 2</label></div></form>");
client.println("<form><div><input type=\"checkbox\" id=\"relay_03\" onclick=\"handleClick(this);\" ");
if (val3 == 0) {
client.print("unchecked");
} else {
client.print("checked");
}
client.println("><label for=\"relay_03\" onclick=\"relay_03();\">Relai 3</label></div></form>");
client.println("<form><div><input type=\"checkbox\" id=\"relay_04\" onclick=\"handleClick(this);\" ");
if (val4 == 0) {
client.print("unchecked");
} else {
client.print("checked");
}
client.println("><label for=\"relay_04\" onclick=\"relay_04();\">Relai 4</label></div></form>");
} else if (page == PAGE_ADMIN) {
client.println( "<form action='/ident' method='get'>");
client.println( "<script type='text/javascript'>\nfunction showValue(newValue)\n{\ndocument.getElementById('text').innerHTML=newValue;\n}\n</script>");
// client.println( "<div>");
// client.println( "<label for='name'>SSID:</label>");
// client.println( "<input type='text' id='name' name='name' value='" + domoticz->_ssid + "'/>");
// client.println( "</div>");
client.println( "<div>");
client.println( "<label for='pass'>Password:</label>");
client.println( "<input type='password' id='pass' name='pass' />");
client.println( "</div>");
client.println( "<div>");
client.println( "<label for='domo'>Domoticz:</label>");
client.println( "<input type='text' id='domo' name='domo' value='" + domoticz->_domoticz + "'/>"); // />");
client.println( "</div>");
client.println( "<div>");
client.println( "<label for='port'>Port:</label>");
client.println( "<input type='text' id='port' name='port' value='" + domoticz->_port + "'/>");
client.println( "</div>");
client.println( "<div>");
client.println( "<label for='radi'>Id Radiateur:</label>");
client.println( "<input type='radi' id='radi' name='radi' value='" + radiateur + "'/>");
client.println( "</div>");
client.println( "<div>");
client.println( "<label for='temp'>Id Thermometre:</label>");
client.println( "<input type='temp' id='temp' name='temp' value='" + temp + "'/>");
client.println( "</div>");
client.println( "<div>");
client.println( "<label for='cons'>Id Consigne:</label>");
client.println( "<input type='cons' id='cons' name='cons' value='" + cons + "'/>");
client.println( "</div>");
client.println( "<div class='button'>");
client.println( "<button name=H type='submit'>Ok</button>");
client.println( "</div>");
client.println( "</form>");
} else if (page == PAGE_STATUS) {
client.println("<article>");
printWifiStatus();
client.println("</article>");
} else if (page == PAGE_GRAPH) {
graph();
} else if (page == PAGE_INFOS) {
infos();
}
client.println(" </div>");
client.println("</main>");
client.println("<script>");
client.println("var show_menu=document.querySelector('.show_menu_btn'),viewport_width=document.documentElement.clientWidth,menu=document.querySelector('#nav ul');600>viewport_width&&(menu.style.display='none'),window.addEventListener('resize',function(){var e=document.documentElement.clientWidth;menu.style.display=e>599?'block':'none'}),show_menu.addEventListener('click',function(){var e=document.querySelector(show_menu.getAttribute('data-target'));'none'==e.style.display?(e.style.display='block',show_menu.innerHTML=show_menu.getAttribute('data-shown-text')):(e.style.display='none',show_menu.innerHTML=show_menu.getAttribute('data-hidden-text'))});");
//menuJS();
// Fonction pour les voutons
//client.println("function click(){$(function() {$( '#dialog' ).dialog({width : 250, height: 180, modal : true }); }); }");
client.println("</script>");
if (page == PAGE_GRAPH) {
// client.println("<script src=\"http://" + domoticz->_domoticz + "/" + jsPath + "/" + chartName + "\"></script>");
client.println("<script src=\"https://www.chartjs.org/dist/2.9.3/Chart.min.js\"></script>");
}
else if (page == PAGE_MENU) {
client.println("<script>");
client.println("function relay_02() {document.getElementById(\"relay_02\").click();}");
client.println("function relay_01() {document.getElementById(\"relay_01\").click();}");
client.println("function handleClick(cb) {post_to_url(cb, \"/action\", { submit: \"submit\" });}");
client.println("function post_to_url(x, path, params, method) {");
client.println("method = \"get\"; var form = document.createElement(\"form\");");
//1client.println("var x = document.getElementById(\"relay_01\");");
// client.println("var x2 = document.getElementById(\"relay_02\");");
client.println("form._submit_function_ = form.submit;");
client.println("form.setAttribute(\"method\", method);");
client.println("form.setAttribute(\"action\", path);");
client.println("var hiddenField = document.createElement(\"input\");");
client.println("hiddenField.setAttribute(\"type\", \"hidden\");");
client.println("hiddenField.setAttribute(\"name\", x.id);");
client.println("hiddenField.setAttribute(\"value\", x.checked);");
client.println("form.appendChild(hiddenField);");
client.println("document.body.appendChild(form);");
// client.println("var hiddenField2 = document.createElement(\"input\");");
// client.println("hiddenField2.setAttribute(\"type\", \"hidden\");");
// client.println("hiddenField2.setAttribute(\"name\", x2.id);");
// client.println("hiddenField2.setAttribute(\"value\", x2.checked);");
// client.println("form.appendChild(hiddenField2);");
// client.println("document.body.appendChild(form);");
client.println("form._submit_function_(); }</script>");
}
client.println("</body>");
}
void ServeurWeb::menuStyle(int page) {
client.println("<style>");
client.println( "a,abbr,acronym,address,applet,article,aside,audio,b,big,blockquote,body,canvas,caption,center,cite,code,dd,del,details,dfn,div,dl,dt,em,embed,fieldset,figcaption,");
client.println( "figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,html,i,iframe,img,ins,kbd,label,legend,li,mark,menu,nav,object,ol,output,p,pre,q,ruby,s,samp,section,small,span,");
client.println( "strike,strong,sub,summary,sup,table,tbody,td,tfoot,th,thead,time,tr,tt,u,ul,var,video{margin:0;padding:0;border:0;font:inherit;vertical-align:baseline}");
client.println( "article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}nav ul{list-style:none}blockquote,q{quotes:none}blockquote:");
client.println( "after,blockquote:before,q:after,q:before{content:'';");
client.println( "content:none}table{border-collapse:collapse;border-spacing:0}h1{font-size:1.5em;font-weight:700;padding:.5em 0;letter-spacing:1px}@media screen and ");
client.println( "(max-width:599px){h1{text-align:center}}h2{font-size:1.25em;font-weight:700;line-height:1.2;padding:.5em 0}p{font-size:1em;padding:0 0 1em}a{color:#555;");
client.println( "text-decoration:none;border-bottom:1px solid #555}a:hover{color:#88b47f;border-bottom:1px solid #88b47f}*{-moz-box-sizing:border-box;-webkit-box-sizing:");
client.println( "border-box;box-sizing:border-box;-webkit-text-size-adjust:auto}body{font-family:sans-serif;font-size:100%;text-align:center;line-height:1.5;background:");
client.println( "#f8f7f0;color:#555}.wrapper{width:90%;max-width:50em;margin:0 auto;text-align:left;overflow:hidden}");
client.println( "header{margin-bottom:1em;padding-bottom:1em;background:#57575f;color:#fff}@media screen and (max-width:599px){.no-js .show_menu_btn{display:none}.js .show_menu_btn,.no-js #nav ul{display:block}.js #nav ul{display:none}}@media screen and (min-width:600px){.show_menu_btn{display:none}#nav ul{display:block}}.show_menu_btn{width:35%;margin:0 auto;padding:.3em;cursor:pointer;text-align:center;background:#88b47f}#nav ul{margin:1em 0}#nav ul li{padding:.5em}#nav ul li:hover{background:#88b47f}#nav ul a{display:block;font-size:1em;color:#eee;border-bottom:none}@media screen and (max-width:599px){#nav ul{display:block}#nav ul li{display:block;text-align:center;border-bottom:1px solid #6f6f7a}}@media screen and (min-width:600px){#nav{overflow:hidden}#nav ul li{width:7em;float:left;margin-right:1em}}");
//Bouton
client.println( ".boutonTemp {width:85px;height:85px;background:#fafafa;box-shadow:2px 2px 8px #aaa;font:bold 13px Arial;border-radius:50%;color:#555;}");
client.println( ".boutonCons {width:85px;height:85px;background:#cc0000;font:bold 13px Arial;border-radius:50%;border:none;color:#fff;}");
// PAGE MENU
client.println("input[type=\"checkbox\"] {display: none;}");
client.println("input[type=\"checkbox\"] + label {display:inline-block; line-height:normal; cursor:pointer; padding: 3px 14px;");
client.println("background-color: #EFEFEF;border-radius: 4px;border: 1px solid #D0D0D0;margin: 40px 100px 10px 40px;");
client.println("}input[type=\"checkbox\"] + label:hover {border-color: #000;background-color: #911;color: #fff;}");
client.println("input[type=\"checkbox\"]:checked + label {border-color: #000;background-color: #888;color: #fff;}");
client.println("</style>");
}
///////////////////////////////////////////////////
// PAGE ADMIN
///////////////////////////////////////////////////
void ServeurWeb::pageAdmin() {
client.println("<html>");
style();
body();
client.println("</html>\n\r");
}
void ServeurWeb::body() {
client.println( "<body>");
client.println( "<form action='/ident' method='get'>");
client.println( "<script type='text/javascript'>\nfunction showValue(newValue)\n{\ndocument.getElementById('text').innerHTML=newValue;\n}\n</script>");
client.println( "<div>");
client.println( "<label for='name'>SSID:</label>");
client.println( "<input type='text' id='name' name='name' />");
client.println( "</div>");
client.println( "<div>");
client.println( " <label for='pass'>Password:</label>");
client.println( " <input type='password' id='pass' name='pass' />");
client.println( "</div>");
client.println( "<div>");
client.println( " <label for='domo'>Domoticz:</label>");
client.println( " <input type='text' id='domo' name='domo' />");
client.println( " <label for='port'>Port:</label>");
client.println( " <input type='text' id='port' name='port' />");
client.println( "</div>");
client.println( "<div>");
client.println( " <label for='radi'>Id Radiateur:</label>");
client.println( " <input type='radi' id='radi' name='radi' />");
client.println( "</div>");
client.println( "<div class='button'>");
client.println( " <button name=H type='submit'>Ok</button>");
client.println( "</div>");
client.println( "</form>");
client.println( "</body>");
}
void ServeurWeb::style() {
client.println( "<style>");
client.println( "form {");
// client.println( " /* Just to center the form on the page */");
client.println( " margin: 0 auto;");
client.println( " width: 400px;");
client.println( "");
// client.println( " /* To see the limits of the form */");
client.println( " padding: 1em;");
client.println( " border: 1px solid #CCC;");
client.println( " border-radius: 1em;");
client.println( "}");
client.println( "");
client.println( "div + div {");
client.println( " margin-top: 1em;");
client.println( "}");
client.println( "");
client.println( "label {");
// client.println( " /* To make sure that all label have the same size and are properly align */");
client.println( " display: inline-block;");
client.println( " width: 90px;");
client.println( " text-align: right;");
client.println( "}");
client.println( "");
client.println( "input, textarea {");
// client.println( " /* To make sure that all text field have the same font settings");
// client.println( " By default, textarea are set with a monospace font */");
client.println( " font: 1em sans-serif;");
client.println( "");
// client.println( " /* To give the same size to all text field */");
client.println( " width: 300px;");
client.println( "");
client.println( " -moz-box-sizing: border-box;");
client.println( " box-sizing: border-box;");
client.println( "");
// client.println( " /* To harmonize the look & feel of text field border */");
client.println( " border: 1px solid #999;");
client.println( "}");
client.println( "");
client.println( "input:focus, textarea:focus {");
// client.println( " /* To give a little highligh on active elements */");
client.println( " border-color: #000;");
client.println( "}");
client.println( "");
client.println( "textarea {");
// client.println( " /* To properly align multiline text field with their label */");
client.println( " vertical-align: top;");
client.println( "");
// client.println( " /* To give enough room to type some text */");
client.println( " height: 5em;");
client.println( "");
// client.println( " /* To allow users to resize any textarea vertically");
// client.println( " It works only on Chrome, Firefox and Safari */");
client.println( " resize: vertical;");
client.println( "}");
client.println( "");
client.println( ".button {");
// client.println( " /* To position the buttons to the same position of the text fields */");
// client.println( " padding-left: 90px; /* same size as the label elements */");
client.println( "}");
client.println( "");
client.println( "button {");
// client.println( " /* This extra magin represent the same space as the space between");
// client.println( " the labels and their text fields */");
client.println( " margin-left: .5em;");
client.println( "}");
client.println(".toggle-slide {");
client.println(" overflow: hidden;");
client.println(" cursor: pointer;");
client.println(" -webkit-touch-callout: none;");
client.println(" -webkit-user-select: none;");
client.println(" -khtml-user-select: none;");
client.println(" -moz-user-select: none;");
client.println(" -ms-user-select: none;");
client.println(" user-select: none;");
client.println(" direction: ltr;");
client.println("}");
client.println(".toggle-slide .toggle-on,.toggle-slide .toggle-off,.toggle-slide .toggle-blob {");
client.println(" float: left;");
client.println("}");
client.println(".toggle-slide .toggle-blob {");
client.println(" position: relative;");
client.println(" z-index: 99;");
client.println(" cursor: hand;");
client.println(" cursor: grab;");
client.println(" cursor: -moz-grab;");
client.println(" cursor: -webkit-grab;");
client.println("}");
client.println( "</style>");
}
void ServeurWeb::graph() {
// infos();
client.println( "<canvas id='canvas' ></canvas>");
client.println( "<script>");
client.println( "var randomScalingFactor = function(){ return Math.round(Math.random()*100)};");
client.println( "var config = {");
client.println( "type: 'line',");
client.println( " data: {");
client.print( "labels : ["); //\"January\",\"February\",\"March\",\"April\",\"May\",\"June\",\"July\"],");
client.print(domoticz->labels);
client.println("],");
client.println( "datasets : [");
client.println( "{");
client.println( "label: \"My First dataset\",");
client.println( " fillColor : \"rgba(220,220,220,0.2)\",");
client.println( " strokeColor : \"rgba(220,220,220,1)\",");
client.println( " pointColor : \"rgba(220,220,220,1)\",");
client.println( " pointStrokeColor : \"#fff\",");
client.println( " pointHighlightFill : \"#fff\",");
client.println( " pointHighlightStroke : \"rgba(220,220,220,1)\",");
client.print( " data : [");
// randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()
client.print(domoticz->data);
client.print("]}");
client.println( " ]}};");
client.println( "window.onload = function(){");
client.println( " var ctx = document.getElementById(\"canvas\").getContext(\"2d\");");
client.println( " window.myLine = new Chart(ctx, config);");
// client.println( " responsive: true, animation:true});");
client.println( "}");
client.println( "</script>");
}
//String domoticz->getIndexOfString(String data, String separator, int index)
//{
// int found = 0;
// int strIndex[] = { 0, -1 };
// int maxIndex = data.length() - 1;
//
// for (int i = 0; i <= maxIndex && found <= index; i++) {
// if (data.charAt(i) == separator.charAt(0) || i == maxIndex) {
// found++;
// strIndex[0] = strIndex[1] + 1;
// strIndex[1] = (i == maxIndex) ? i+1 : i;
// }
// }
// return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
//}

View File

@@ -0,0 +1,82 @@
#ifndef ServeurWeb_h
#define ServeurWeb_h
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "Domoticz.h"
#include "Params.h"
#include "Modules.h"
#include "Pins.h"
#define PAGE_MENU 0
#define PAGE_ADMIN 1
#define PAGE_STATUS 2
#define PAGE_INFOS 3
#define PAGE_GRAPH 4
#define DELAI_LECTURE 120
class ServeurWeb
{
public:
ServeurWeb();
//void setup();
void loop();
private:
boolean connectToWifi();
//void initHardware();
char* convertToChar(String s, char* buf);
void infos();
void menuBody(int page);
void pageAdmin();
void pageMenu(int page);
void printWifiStatus();
//void setupWiFi();
void body();
String getValueFrom(String request, int deb, int fin);
void menuStyle(int page);
void style();
void graph();
public:
Domoticz* domoticz;
Modules* modules;
// WiFiClient _client;
String radiateur = ""; //"217";
String temp = ""; //"281";
String cons = ""; //"212";
String jsPath = "/ESP8266/js/";
String jqueryName = "jquery.js";
String chartName = "chart.js";
String AP_NameString = "";
int nbData = 0;
String data = "22.3,22.3,22.3,22.3";
String labels = "0,1,2,3";
int bcl = 0;
int val0;
int val2;
int val3;
int val4;
String separator = ",";
String nom = "";
int refresh = 2;
WiFiClient client;
WiFiServer* server;
};
#endif
// // Ordre dans Domoticz
// // Radiateur Temp Consigne
// //Manon 217 281 212
// //Théo 219 335 211
// //Chambre 218 254 213
// //Bureau 163 260 214