104 lines
2.5 KiB
C++
104 lines
2.5 KiB
C++
//extern "C" {
|
|
//#include "user_interface.h"
|
|
//}
|
|
|
|
// Need for getVcc
|
|
// Disable 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;
|
|
Params p;
|
|
|
|
IPAddress gateway(192, 168, 1, 1);
|
|
IPAddress subnet(255, 255, 0, 0);
|
|
IPAddress DNS(192, 168, 1, 1);
|
|
|
|
void setup()
|
|
{
|
|
|
|
Serial.begin(9600);
|
|
// Conversion d'objet en pointeur
|
|
String macId = domo.generateKey();
|
|
IPAddress ip = domo.getIP(macId);
|
|
params = &p;
|
|
|
|
|
|
domo.initWifiStatic(ip, gateway, subnet, DNS);
|
|
|
|
// domo.initWifi();
|
|
domo.getIdFromDomoticz(domo.generateKey(), params);
|
|
|
|
// modules.readTemperature();
|
|
|
|
modules.readIntensite();
|
|
printInfo();
|
|
delay(2000);
|
|
//modules.sleep(params->sleepTime);
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
modules.readIntensite();
|
|
printInfo();
|
|
delay(30000);
|
|
}
|
|
|
|
void printInfo()
|
|
{
|
|
// Domoticz format /json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT
|
|
|
|
Serial.println("Dans printInfo " + params->esp8266_id);
|
|
|
|
boolean connected = domo.connect();
|
|
|
|
if (connected && modules.temp > 0) {
|
|
Serial.println("Dans set temperature");
|
|
String svalue = String(modules.temp) + ";" + String(modules.humidity) + ";0;0;0";
|
|
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);
|
|
|
|
// 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();
|
|
}
|
|
|
|
Serial.print("Intensite ");
|
|
Serial.println(modules.lum);
|
|
|
|
connected = domo.connect();
|
|
if (connected && params->esp8266_id_lum != "") {
|
|
Serial.print(" Envoi intensite ");
|
|
Serial.print(params->esp8266_id_lum);
|
|
Serial.print(" ");
|
|
Serial.println(modules.lum);
|
|
|
|
// domo._client.print("GET /json.htm?type=command¶m=udevice&idx=");
|
|
domo.executeJson("/json.htm?type=command¶m=udevice&idx=" + params->esp8266_id_lum, String(modules.lum), "0");
|
|
domo._client.stop();
|
|
}
|
|
|
|
Serial.print("Time = ");
|
|
Serial.println(millis());
|
|
|
|
delay(200);
|
|
}
|