OK!
Tnx!
I post a code.
`/* PIR Advanced motion Detection with deep-sleep mode */
ADC_MODE(ADC_VCC); //vcc read
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
// WiFi credentials & Domoticz API IDX.
const char* WIFI_SSID = "<YOUR_WIFI_SSID>";
const char* WIFI_PASS = "<YOUR_WIFI_PASS>";
const char* DOMOTICZ_SRV = "http://192.168.123.100:8080";
const char* DOMOTICZ_SWITCH_IDX = "45";
const char* DOMOTICZ_VOLT_IDX = "22";
const int PIRSignalPin = 14; //Using GPIO14 for PIR Data
void setup() {
HTTPClient http; // HTTP object
String api; // Holds full API string for Domoticz
int httpCode; // Return HTTP code
String response; // Response from HTTP GET request
float vdd; // Internal voltage
String s_vdd; // Internal voltage (formatted as string)
Serial.begin(115200);
Serial.setTimeout(2000);
while (!Serial) { } // Wait for serial to initialize.
Serial.println("");
Serial.println("-------------------------------------");
Serial.println("PIR Motion Detection Firmware!");
Serial.println("-------------------------------------");
// Connect to Wifi.
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) {
// Check to see if
if (WiFi.status() == WL_CONNECT_FAILED) {
Serial.println("");
Serial.println("Failed to connect to WiFi. Please verify credentials!");
delay(10000);
} else {
delay(500);
Serial.print(".");
}
}
Serial.println("");
Serial.print("WiFi connected with IP address: ");
Serial.println(WiFi.localIP());
// Send post request to Domoticz
Serial.println("");
Serial.println("Sending On signal to Domoticz.");
//Build API command
api = DOMOTICZ_SRV;
api += "/json.htm?type=command¶m=switchlight&idx=";
api += DOMOTICZ_SWITCH_IDX;
if (digitalRead(PIRSignalPin)==HIGH) {
api += "&switchcmd=On";
} else {
DEBUGPRINTLN0("Sending 'Off' signal to Domoticz.");
api += "&switchcmd=Off";
}
http.begin(api); //Specify request destination
httpCode = http.GET(); //Send the request and set return code
Serial.print("Return code: ");
Serial.println(httpCode);
if (httpCode > 0) { //Check the returning code
response = http.getString(); //Get the request response
Serial.println("Response:");
Serial.println(response);
}
http.end(); //Close connection
delay(200);
Serial.print("Sending voltage to Domoticz: ");
vdd = ESP.getVcc() / 1024.0f;
s_vdd = String(vdd, 3);
Serial.println(s_vdd);
api = DOMOTICZ_SRV;
api += "/json.htm?type=command¶m=udevice&idx=";
api += DOMOTICZ_VOLT_IDX;
api += "&nvalue=0&svalue=";
api += s_vdd;
http.begin(api); //Specify request destination
httpCode = http.GET(); //Send the request and set return code
Serial.print("Return code: ");
Serial.println(httpCode);
if (httpCode > 0) { //Check the returning code
response = http.getString(); //Get the request response
Serial.println("Response:");
Serial.println(response);
}
http.end(); //Close connection
Serial.println("");
Serial.println("Going into deep sleep!");
ESP.deepSleep(0); // forever
}
void loop() {
// Never reached!
}`