first commit
This commit is contained in:
250
ESP8266_DOMOTICZ_ECRAN/ESP8266_DOMOTICZ_ECRAN.ino
Normal file
250
ESP8266_DOMOTICZ_ECRAN/ESP8266_DOMOTICZ_ECRAN.ino
Normal 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¶m=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¶m=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¶m=udevice&idx=");
|
||||
domo.executeJson("/json.htm?type=command¶m=udevice&idx=" + params->esp8266_id_Vcc, vcc, "0");
|
||||
domo._client.stop();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user