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

View File

@@ -0,0 +1,109 @@
#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.println(" connected ");
// // printf(connected);
return connected;
}
void Domoticz::close()
{
}
void Domoticz::initWifi()
{
WiFi.mode(WIFI_AP);
WiFi.begin(_ssid, _pass); //Connect to local Wifi
// printf();
// printf("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi Connected!");
Serial.print("Connexion au reseau ");
Serial.println(WiFi.localIP());
delay(500);
}
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 = "ESP32 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);
// printf("macID=" + macID);
return macID;
}
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,33 @@
#ifndef Domoticz_h
#define Domoticz_h
//#include <Arduino.h>
#include <WiFi.h>
#include "Params.h"
#include "Arduino_JSON.h"
#define WL_MAC_ADDR_LENGTH 8
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 generateKey();
static String getIndexOfString(String data, String separator, int index);
private:
const char* _ssid;
const char* _pass;
public:
WiFiClient _client;
int _iport;
String _domoticz;
String _port;
char _domoc[];
};
#endif

View File

@@ -0,0 +1,225 @@
/////////////////////
// Domoticz Classe
/////////////////////
#include <WiFi.h>
#include <HTTPClient.h>
#include "Domoticz.h"
Domoticz domo("192.168.1.3", "81", "Livebox-37cc", "8A6060920A8A86896F770F2C47");
//
Params * params;
#include "Ecran.h"
Ecran * ecran;
double temp;
class Meteo {
public:
double temp;
double pressure;
int humidity;
String description;
String icon;
};
Meteo * meteo;
const char* meteo_url = "http://api.openweathermap.org/data/2.5/weather?q=La%20gacilly,fr&APPID=feba3f4d926db3b358a25ec782bd1c8b&lang=FR&units=metric";
// Convert image to char array http://www.digole.com/tools/PicturetoC_Hex_converter.php
// domoticz
String macID = "";
void setup()
{
Serial.begin(115200);
//
// Conversion d'objet en pointeur
Params p;
params = &p;
Meteo m;
meteo = &m;
// display Bitcoin Logo LCD_X
// ecran->gotoXY(0,0); ecran->LcdString("Init :"); ecran->LcdString(domo._domoticz);
domo.initWifi();
macID = domo.generateKey();
readMeteo();
delay(500);
Ecran e;
ecran = &e;
ecran->initialise();
ecran->intro();
//#if 1 // show image for array
// printf("show image for array\r\n");
// Paint_SelectImage(BlackImage);
// Paint_Clear(WHITE);
//// Paint_DrawBitMap(gImage_7in5_V2);
// EPD_7IN5_V2_Display(BlackImage);
// DEV_Delay_ms(2000);
//#endif
//
//#if 1 // Drawing on the image
// //1.Select Image
// printf("SelectImage:BlackImage\r\n");
// Paint_SelectImage(BlackImage);
ecran->clear();
// 2.Drawing on the image
printf("Drawing:BlackImage\r\n");
// Paint_DrawPoint(10, 80, BLACK, DOT_PIXEL_1X1, DOT_STYLE_DFT);
// Paint_DrawPoint(10, 90, BLACK, DOT_PIXEL_2X2, DOT_STYLE_DFT);
// Paint_DrawPoint(10, 100, BLACK, DOT_PIXEL_3X3, DOT_STYLE_DFT);
ecran->drawLine(20, 70, 70, 120, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
ecran->drawLine(70, 70, 20, 120, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
ecran->drawRect(3, 3, 797, 477, RED, DOT_PIXEL_3X3, DRAW_FILL_EMPTY);
ecran->drawRect(80, 70, 130, 120, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
ecran->drawCircle(45, 95, 20, LUT_RED_0, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
ecran->drawCircle(105, 95, 20, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);
ecran->drawLine(85, 95, 125, 95, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
ecran->drawLine(105, 75, 105, 115, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
Paint_DrawString_EN(10, 0, String(meteo->description).c_str(), &Font16, BLACK, WHITE);
Paint_DrawString_EN(10, 20, "hello world", &Font12, WHITE, BLACK);
// Paint_DrawNum(10, 33, meteo->humidity, &Font12, BLACK, WHITE);
Paint_DrawNum(10, 50, 987654321, &Font16, WHITE, BLACK);
// Paint_DrawString_CN(130, 0, " 你好abc", &Font12CN, BLACK, WHITE);
// Paint_DrawString_CN(130, 20, "微雪电子", &Font24CN, WHITE, BLACK);
printf("EPD_Display\r\n");
EPD_7IN5_V2_Display(ecran->BlackImage);
DEV_Delay_ms(2000);
// printf("Clear...\r\n");
// EPD_7IN5_V2_Clear();
//
// printf("Goto Sleep...\r\n");
// EPD_7IN5_V2_Sleep();
// free(BlackImage);
// BlackImage = NULL;
// ecran->LcdBitmap(LCD_X, LCD_Y, bitcoin);
// ecran->LcdString(0, 0, domo._domoticz);
// ecran->LcdChar(0, 10, "ID : ");
// ecran->LcdString(40, 10, macID);
// domo.getIdFromDomoticz(macID, params);
//readTemp();
// printInfo();
// 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");
// delay(100);
// }
delay(2000);
// Test Json
ecran->sleep();
}
void loop() { }
void sleepWifi()
{
//Time to let the WiFi go to sleep!
// printf("Sleeping...");
WiFi.disconnect();
WiFi.mode(WIFI_OFF);
// WiFi.forceSleepBegin(params->sleepTime * 1000000L); //In uS. Must be same length as your delay
delay(params->sleepTime * 1000); //Hang out at 15mA for 6 seconds
WiFi.mode(WIFI_STA);
// printf("Awake!");
}
void readMeteo()
{
// if (WiFi.status()== WL_CONNECTED){
String sensorReadings = httpGETRequest(meteo_url);
Serial.println(sensorReadings);
JSONVar myObject = JSON.parse(sensorReadings);
// JSON.typeof(jsonVar) can be used to get the type of the var
if (JSON.typeof(myObject) == "undefined") {
Serial.println("Parsing input failed!");
return;
}
Serial.print("JSON object = ");
Serial.println(myObject);
// myObject.keys() can be used to get an array of all the keys in the object
JSONVar main = myObject["main"];
Serial.print("main ===>");
Serial.println(main);
Serial.print("weather ===>");
JSONVar weathers = myObject["weather"];
String weather0 = weathers[0];
// JSONVar weather = JSON.parse(weather0);
Serial.println(weathers[0].keys());
JSONVar keys = main.keys();
JSONVar t = main["temp"];
temp = double(t);
JSONVar d = weathers[0]["description"];
// meteo->humidity = int(main['humidity']);
meteo->description = String(d);
// Serial.println(weathers[0]["description"]);
for (int i = 0; i < keys.length(); i++) {
JSONVar value = main[keys[i]];
Serial.print(keys[i]);
Serial.print(" = ");
Serial.println(value);
// sensorReadingsArr[i] = double(value);
}
// }
}
String httpGETRequest(const char* serverName) {
WiFiClient client;
HTTPClient http;
// Your Domain name with URL path or IP address with path
http.begin(client, serverName);
// If you need Node-RED/server authentication, insert user and password below
//http.setAuthorization("REPLACE_WITH_SERVER_USERNAME", "REPLACE_WITH_SERVER_PASSWORD");
// Send HTTP POST request
int httpResponseCode = http.GET();
String payload = "{}";
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
payload = http.getString();
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
return payload;
}

View File

@@ -0,0 +1,135 @@
#include "Ecran.h"
Ecran::Ecran()
{
// printf("--------------------------------------");
// printf("Init Ecran");
// ECRAN
// LcdInitialise();
// LcdClear();
// LcdChar(0, 0, "Starting");
//
// FIN ECRAN
}
// ECRAN Methodes
void Ecran::LcdCharacter(char character)
{
}
void Ecran::clear(void)
{
Paint_Clear(WHITE);
}
//void Ecran::fullBlack(void)
//{
// //Create a new image cache
// UBYTE *BlackImage;
// /* you have to edit the startup_stm32fxxx.s file and set a big enough heap size */
// UWORD Imagesize = ((EPD_7IN5_V2_WIDTH % 8 == 0) ? (EPD_7IN5_V2_WIDTH / 8 ) : (EPD_7IN5_V2_WIDTH / 8 + 1)) * EPD_7IN5_V2_HEIGHT;
// if ((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
// printf("Failed to apply for black memory...\r\n");
// while (1);
// }
// printf("Paint_NewImage\r\n");
// Paint_NewImage(BlackImage, EPD_7IN5_V2_WIDTH, EPD_7IN5_V2_HEIGHT, 0, WHITE);
//
//}
void Ecran::initialise(void)
{
// printf("EPD_7IN5_V2_test Demo\r\n");
DEV_Module_Init();
// printf("e-Paper Init and Clear...\r\n");
EPD_7IN5_V2_Init();
EPD_7IN5_V2_Clear();
DEV_Delay_ms(500);
//Create a new image cache
// UBYTE *BlackImage;
/* you have to edit the startup_stm32fxxx.s file and set a big enough heap size */
UWORD Imagesize = ((EPD_7IN5_V2_WIDTH % 8 == 0) ? (EPD_7IN5_V2_WIDTH / 8 ) : (EPD_7IN5_V2_WIDTH / 8 + 1)) * EPD_7IN5_V2_HEIGHT;
if ((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
printf("Failed to apply for black memory...\r\n");
while (1);
}
printf("Paint_NewImage\r\n");
Paint_NewImage(BlackImage, EPD_7IN5_V2_WIDTH, EPD_7IN5_V2_HEIGHT, 0, WHITE);
}
void Ecran::LcdChar(int x, int y, char *characters)
{
Paint_DrawString_EN(x, y, "characters", &Font16, BLACK, WHITE);
}
void Ecran::LcdString(int x, int y, String s, int foreground, int color)
{
Paint_DrawString_EN(x, y, s.c_str(), &Font16, foreground, color);
}
void Ecran::LcdWrite(byte dc, byte data)
{
}
void Ecran::setContrast(byte contrast)
{
}
//This takes a large array of bits and sends them to the LCD
void Ecran::LcdBitmap(int x, int y, char my_array[])
{
}
void Ecran::intro()
{
Paint_DrawString_EN(380, 200, "hello world", &Font24, WHITE, BLACK);
Paint_NewImage(BlackImage, EPD_7IN5_V2_WIDTH, EPD_7IN5_V2_HEIGHT, 0, WHITE);
delay(1000);
}
void Ecran::sleep()
{
// printf("Goto Sleep...\r\n");
EPD_7IN5_V2_Sleep();
}
void Ecran::drawLine(int x0, int y0, int x1, int y1, int color, DOT_PIXEL dot, LINE_STYLE style)
{
Paint_DrawLine(x0, y0, x1, y1, color, dot, style);
}
void Ecran::drawCircle(int x0, int y0, int r, int color, DOT_PIXEL dot, DRAW_FILL ifill)
{
Paint_DrawCircle(x0, y0, r, color, dot, ifill);
}
void Ecran::drawRect(int x0, int y0, int x1, int y1, int color, DOT_PIXEL dot, DRAW_FILL ifill)
{
Paint_DrawRectangle(x0, y0, x1, y1, color, dot, ifill);
}
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);
// }
}
void Ecran::drawFace(int x0, int y0, int x1, int y1, int x2, int y2)
{
}

View File

@@ -0,0 +1,33 @@
#ifndef Ecran_h
#define Ecran_h
#include "DEV_Config.h"
#include "EPD.h"
#include "GUI_Paint.h"
#include <stdlib.h>
class Ecran
{
public:
Ecran();
void drawCircle(int x0, int y0, int r, int color, DOT_PIXEL dot, DRAW_FILL ifill);
void drawLine(int x0, int y0, int x1, int y1, int color, DOT_PIXEL dot, LINE_STYLE style);
void drawFace(int x0, int y0, int x1, int y1, int x2, int y2);
void drawRect(int x0, int y0, int x1, int y1, int color, DOT_PIXEL dot, DRAW_FILL ifill);
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, int foreground, int color);
void initialise(void);
void clear(void);
void LcdBitmap(int x, int y,char my_array[]);
void LcdCharacter(char character);
void setContrast(byte contrast);
void sleep();
private:
public:
UBYTE *BlackImage;
long contrast = 200;
};
#endif

View File

@@ -0,0 +1,34 @@
#include "Graph.h"
Graph::Graph(Ecran * _ecran, int _x0, int _y0 ,int _x1, int _y1)
{
// printf("--------------------------------------");
// printf("Init Graph");
x0 = _x0;
x1 = _x1;
y0 = _y0;
y1 = _y1;
ecran = _ecran;
}
void Graph::drawAxes()
{
// ecran->u8g2->drawLine(x0 + 5, y0 + 5, x1, y0 + 5);
// ecran->u8g2->drawLine(x0 + 5, y0 + 5, x0 + 5, y1);
}
void Graph::drawTitle()
{
if (title != "") {
ecran->LcdString(x0, y0, title, WHITE, BLACK);
}
}
void Graph::drawDatas()
{
}
void Graph::drawGraph()
{
drawAxes();
drawTitle();
drawDatas();
}

View File

@@ -0,0 +1,19 @@
#ifndef Graph_h
#define Graph_h
//#include <Arduino.h>
#include "Ecran.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;
};
#endif

View File

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

View File

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

View File

@@ -0,0 +1,20 @@
#ifndef Pins_h
#define Pins_h
//#include <Arduino.h>
//#define SDA D1
//#define SCL D2
//
//#define ONE_WIRE_BUS 10 // DS18B20 pin
//#define DHTPIN 11 // what pin we're connected to
//// 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