Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 8,785
» Latest member: rozyjuise
» Forum threads: 3,846
» Forum posts: 19,668

Full Statistics

Online Users
There are currently 201 online users.
» 0 Member(s) | 188 Guest(s)
AhrefsBot, Amazonbot, Applebot, Bing, Google, PetalBot, bot

Latest Threads
AS-ESP32-S3 won't initial...
Forum: Getting Started with ESPHome and Home Assistant
Last Post: scottq
5 hours ago
» Replies: 2
» Views: 20
A24 configure yaml for ES...
Forum: KinCony A24
Last Post: kiloptero
5 hours ago
» Replies: 20
» Views: 6,628
Kincony KC868-A16 (ESP32)...
Forum: KC868-A16
Last Post: admin
6 hours ago
» Replies: 3
» Views: 22
Advice for DIY underfloor...
Forum: DIY Project
Last Post: admin
6 hours ago
» Replies: 3
» Views: 24
SHT30 temp/humidity i2c s...
Forum: B8
Last Post: admin
9 hours ago
» Replies: 1
» Views: 9
E16V3 - Dimensions compat...
Forum: Suggestions and feedback on KinCony's products
Last Post: admin
9 hours ago
» Replies: 3
» Views: 18
ESP32 Smart Controller – ...
Forum: Schematic & diagram & Dimensions of KinCony PCB layout CAD file
Last Post: admin
9 hours ago
» Replies: 3
» Views: 12
E16v3 - CE
Forum: Suggestions and feedback on KinCony's products
Last Post: ldebacker
10 hours ago
» Replies: 6
» Views: 215
E16V3 - Cover electrical ...
Forum: Suggestions and feedback on KinCony's products
Last Post: admin
11 hours ago
» Replies: 1
» Views: 11
Github ... finally?
Forum: Suggestions and feedback on KinCony's products
Last Post: admin
11 hours ago
» Replies: 1
» Views: 10

  KC868-AI ESPHome demo config for home assistant
Posted by: admin - 07-06-2022, 12:56 AM - Forum: KC868-AI - Replies (3)

esphome:
  name: kc868-ai
  platform: ESP32
  board: esp32dev
 
 
# Example configuration entry for ESP32
i2c:
  sda: 4
  scl: 5
  scan: true
  id: bus_a


# Example configuration entry
ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 0

  # Optional manual IP
  manual_ip:
    static_ip: 192.168.1.198
    gateway: 192.168.1.1
    subnet: 255.255.255.0 


# Example configuration entry
pcf8574:
  - id: 'pcf8574_hub_in_1'  # for input channel 1-8
    address: 0x24

  - id: 'pcf8574_hub_in_2'  # for input channel 9-16
    address: 0x25

  - id: 'pcf8574_hub_in_3'  # for input channel 17-24
    address: 0x21

  - id: 'pcf8574_hub_in_4'  # for input channel 25-32
    address: 0x22

  - id: 'pcf8574_hub_in_5'  # for input channel 33-40
    address: 0x26

  - id: 'pcf8574_hub_in_6'  # for input channel 41-48
    address: 0x23



# Individual outputs

binary_sensor:
  - platform: gpio
    name: "ai-input1"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 0
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input2"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 1
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input3"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 2
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input4"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 3
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input5"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 4
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input6"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 5
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input7"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 6
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input8"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 7
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input9"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 0
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input10"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 1
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input11"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 2
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input12"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 3
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input13"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 4
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input14"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 5
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input15"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 6
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input16"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 7
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input17"
    pin:
      pcf8574: pcf8574_hub_in_3
      number: 0
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input18"
    pin:
      pcf8574: pcf8574_hub_in_3
      number: 1
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input19"
    pin:
      pcf8574: pcf8574_hub_in_3
      number: 2
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input20"
    pin:
      pcf8574: pcf8574_hub_in_3
      number: 3
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input21"
    pin:
      pcf8574: pcf8574_hub_in_3
      number: 4
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input22"
    pin:
      pcf8574: pcf8574_hub_in_3
      number: 5
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input23"
    pin:
      pcf8574: pcf8574_hub_in_3
      number: 6
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input24"
    pin:
      pcf8574: pcf8574_hub_in_3
      number: 7
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input25"
    pin:
      pcf8574: pcf8574_hub_in_4
      number: 0
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input26"
    pin:
      pcf8574: pcf8574_hub_in_4
      number: 1
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input27"
    pin:
      pcf8574: pcf8574_hub_in_4
      number: 2
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input28"
    pin:
      pcf8574: pcf8574_hub_in_4
      number: 3
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input29"
    pin:
      pcf8574: pcf8574_hub_in_4
      number: 4
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input30"
    pin:
      pcf8574: pcf8574_hub_in_4
      number: 5
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input31"
    pin:
      pcf8574: pcf8574_hub_in_4
      number: 6
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input32"
    pin:
      pcf8574: pcf8574_hub_in_4
      number: 7
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input33"
    pin:
      pcf8574: pcf8574_hub_in_5
      number: 0
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input34"
    pin:
      pcf8574: pcf8574_hub_in_5
      number: 1
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input35"
    pin:
      pcf8574: pcf8574_hub_in_5
      number: 2
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input36"
    pin:
      pcf8574: pcf8574_hub_in_5
      number: 3
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input37"
    pin:
      pcf8574: pcf8574_hub_in_5
      number: 4
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input38"
    pin:
      pcf8574: pcf8574_hub_in_5
      number: 5
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input39"
    pin:
      pcf8574: pcf8574_hub_in_5
      number: 6
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input40"
    pin:
      pcf8574: pcf8574_hub_in_5
      number: 7
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input41"
    pin:
      pcf8574: pcf8574_hub_in_6
      number: 0
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input42"
    pin:
      pcf8574: pcf8574_hub_in_6
      number: 1
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input43"
    pin:
      pcf8574: pcf8574_hub_in_6
      number: 2
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input44"
    pin:
      pcf8574: pcf8574_hub_in_6
      number: 3
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input45"
    pin:
      pcf8574: pcf8574_hub_in_6
      number: 4
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input46"
    pin:
      pcf8574: pcf8574_hub_in_6
      number: 5
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input47"
    pin:
      pcf8574: pcf8574_hub_in_6
      number: 6
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "ai-input48"
    pin:
      pcf8574: pcf8574_hub_in_6
      number: 7
      mode: INPUT
      inverted: true

# Enable logging
logger:

# Enable Home Assistant API
api:


.txt   KC868-AI_ESPhome.txt (Size: 7.9 KB / Downloads: 769)

Print this item

  KC868-AI ESP32 I/O pin define
Posted by: admin - 07-06-2022, 12:53 AM - Forum: KC868-AI - No Replies

IIC Bus:

SDA:GPIO4
SCL:GPIO5

PCF8574:U14 (DI1-8): 100 100 = 0x24
PCF8574:U31 (DI9-16): 100 101 = 0x25
PCF8574:U56 (DI17-24): 100 001 = 0x21
PCF8574:U57 (DI25-32): 100 010 = 0x22
PCF8574:U58 (DI33-40): 100 110 = 0x26
PCF8574:U32 (DI41-48): 100 011 = 0x23


free GPIO:
GPIO35
GPIO39
GPIO34
GPIO36

-----------------

Ethernet (LAN8720) I/O define:

#define ETH_ADDR        0
#define ETH_POWER_PIN  -1
#define ETH_MDC_PIN    23
#define ETH_MDIO_PIN  18
#define ETH_TYPE      ETH_PHY_LAN8720
#define ETH_CLK_MODE  ETH_CLOCK_GPIO17_OUT

--------------------

RS485:
RXD:GPIO16
TXD:GPIO14

RS232:
RXD:GPIO33
TXD:GPIO32

IR receiver: GPIO15
433M receiver: GPIO13

Print this item

  WARNING GPIO4 is a Strapping PIN and should be avoided
Posted by: fabuena - 07-05-2022, 06:19 PM - Forum: KC868-A8 - Replies (1)

When I am configuring KC868-A8 to connect with Home Assistan by Ethernet I received this message

WARNING GPIO4 is a Strapping PIN and should be avoided.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.

What does it means?

How can I solve it?

Print this item

  KC868-AI ESP32 input module released!
Posted by: admin - 07-05-2022, 07:00 AM - Forum: News - No Replies

We have designed KC868-AI ESP32 board use for sensors for home automation DIY. it is a input module based on ESP32 chip. it have 48 channel digital input ports, every input channel use optocoupler isolation, so that can work for 1000 meter with sensors or any dry contact devices. It can receive data from IR remoter and RF433MHz remoter. Support work with RS232 or RS485. Made For ESPHome and easily integrate to home assistant for smart home automation project DIY. You can write any code by Arduino IDE to ESP32 wifi/bluetooth/ethernet RS485 module.

[Image: KC868-AI-1_01.png]
[Image: KC868-AI-1_02.png]
[Image: KC868-AI-1_03.png]
[Image: KC868-AI-1_04.png]

Print this item

  Uair
Posted by: ahmedwizza - 07-04-2022, 08:42 PM - Forum: DIY Project - Replies (3)

can we make scnce from alexa by Uair after integration with homeassistant??????????????



Attached Files Thumbnail(s)
   
Print this item

  Switch 24v DC KC868-Ax
Posted by: fabuena - 07-04-2022, 07:59 AM - Forum: KC868-Server Raspberry Pi4 local server - Replies (4)

I just bought a KC868-A8 and I want to switch on/off a 24v DC signal. It is posible?

Print this item

  KC868-H32B blinds motor control and connect
Posted by: Autotec2022 - 07-03-2022, 09:47 PM - Forum: KC868-HxB series Smart Controller - Replies (23)

Hello

Can you help with connection and adjustment of all motor blinds on the house
I have 22 shutter motors
i want to connect everything to KC868-H32B
I bought two pieces
Order ID: 8151334628020945
Order ID: 8151122210730945

The engine model I own are Solus 2PA
https://www.somfy.co.in/products/1032574...2-pack-100

I need help with connecting the wires because I won't have a button to control the blinds, but all the motors are connected directly to the KC868-H32B, the control is only done using the app.

In order not to damage the relay by wrong connection, you can send me some instructions and information.

I have see that diagram but im not understand 
https://ibb.co/nChbVM3

Im not understand becuse i have think that all motors get power from the relay KC868-H32B or i must bring power cable N L direkt on motors

Print this item

  KinCony ESP32 Tuya iot adapter released!
Posted by: admin - 06-30-2022, 04:32 AM - Forum: News - Replies (4)

KinCony ESP32 Tuya IoT adapter let relay board or IoT devices easy integrate to tuya IoT platform. We have designed by ESP32 work with Tuya module. Tuya module will connect with Tuya cloud server, when using tuya phone app, message will send to tuya wifi module and decode by ESP32. ESP32 support use arduino IDE to write code, get the tuya message and send any command to RS232 or RS485 or network device. it’s a good convert tool for smart home automation DIY.

adapter support to use “Tuya MCU SDK Arduino Library”

KC868-H32B,KC868-H32BS …. HxB series smart controller will be easy support TUYA phone application, alexa and google home voice control function.


[Image: kincony-tuya-adapter-1.jpg]
[Image: kincony-tuya-adapter-2.JPG]

it support install on the DIN rail.
[Image: esp32-tuya-adapter-pins.jpg]
you can write any arduino IDE code or by IDF tool to write code and download firmware by USB-C cable.
[Image: kincony-tuya-adapter-3.JPG]
[Image: kincony-tuya-adapter-4.JPG]
[Image: kincony-tuya-adapter-5.JPG]
[Image: kincony-tuya-adapter-6.JPG]

install wifi antena by SMA socket.
Tuya app , alexa app and google home / google assistant app will be support.
[Image: h32bs-tuya-app-1_pix400.jpg][Image: h32bs-tuya-app-2_pix400.jpg]
[Image: h32bs-tuya-app-3_pix400.jpg][Image: h32bs-tuya-app-4_pix400.jpg]
[Image: h32bs-alexa-app_pix400.jpg][Image: h32bs-google-app_pix400.jpg]
[Image: kincony-tuya-adapter-7.JPG]
suspport use tuya phone app, google home and alexa echo speaker
[Image: kincony-tuya-adapter-8.JPG]

KinCony esp32 tuya adapter work with KC868-H32B by RS232 port
[Image: kincony-tuya-adapter-9.JPG]

KinCony esp32 tuya adapter work with KC868-H32BS by RS232 port
[Image: kincony-tuya-adapter-10.JPG]

[Image: tuya-RS485.jpg]

Print this item

  [Arduino IDE demo source code for KC868-A8S]--#14-KC868-A8S_mqtt-relay_code
Posted by: KinCony Support - 06-30-2022, 12:55 AM - Forum: KC868-A8S - No Replies

[Arduino IDE demo source code for KC868-A8S]--#14-KC868-A8S_mqtt-relay_code
// make sure set your Serial2 pins in your "HardwareSerial.cpp" for ESP32 as follows:

//#define RX2  15
//#define TX2  13

Code:
// code use for KinCony KC868-A8S board


#include "PCF8574.h"

String Publish = "relay8/12345/state"; //Publish Topic
String Subscribe = "relay8/12345/set"; //Subscribe Topic

PCF8574 pcf8574_o(0x24,4,5);
PCF8574 pcf8574_i(0x22,4,5);

void setup()
{
  pinMode(2, OUTPUT);   //beep

  Serial.begin(115200);
  Serial2.begin(115200);
 
  pcf8574_i.pinMode(P0, INPUT);

  pcf8574_o.pinMode(P0, OUTPUT);
  pcf8574_o.pinMode(P1, OUTPUT);
  pcf8574_o.pinMode(P2, OUTPUT);
  pcf8574_o.pinMode(P3, OUTPUT);
  pcf8574_o.pinMode(P4, OUTPUT);
  pcf8574_o.pinMode(P5, OUTPUT);
  pcf8574_o.pinMode(P6, OUTPUT);
  pcf8574_o.pinMode(P7, OUTPUT);
 

    Serial.print("Init pcf8574_i...");
    if (pcf8574_i.begin()){
        Serial.println("PCF8674_input_OK");
    }else{
        Serial.println("PCF8674_input_KO");
    }

    Serial.print("Init pcf8574_o...");
    if (pcf8574_o.begin()){
        Serial.println("PCF8674_output_OK");
    }else{
        Serial.println("PCF8674_output_KO");
    }

  pcf8574_o.digitalWrite(P0, HIGH);
  pcf8574_o.digitalWrite(P1, HIGH);
  pcf8574_o.digitalWrite(P2, HIGH);
  pcf8574_o.digitalWrite(P3, HIGH);
  pcf8574_o.digitalWrite(P4, HIGH);
  pcf8574_o.digitalWrite(P5, HIGH);
  pcf8574_o.digitalWrite(P6, HIGH);
  pcf8574_o.digitalWrite(P7, HIGH);

  //AT Commands for setting up the client id and Server
  //Need to be executed once -- Open serial terminal doe seeing the debug messages
  Serial.println("Connecting To Server........");
  Serial2.println("ATE1");
  delay(2000);
  Serial2.println("AT+CMQTTSTART"); //Establishing MQTT Connection
  delay(2000);
  Serial2.println("AT+CMQTTACCQ=0,\"kincony\""); //Client ID - change this for each client as this need to be unique
  delay(2000);
  Serial2.println("AT+CMQTTCONNECT=0,\"tcp://iot.kincony.com:1883\",120,1,\"mqtt\",\"123\""); //MQTT Server Name for connecting this client  user name: mqtt   password: 123
  delay(2000);

  Serial2.println("AT+CMQTTSUB=0,16,1,1"); //Length of message
  delay(1000);
  Serial2.println("relay8/12345/set"); //message
  delay(1000);
  Serial.println("Done");
}

void loop()
{
  String incoming;

//Receiving MODEM Response
  while(Serial2.available()>0)
  {
    delay(10);
    incoming = Serial2.readString();
    Serial.println(incoming);

    //Serial.println(b);
    if(incoming.indexOf("PAYLOAD") != -1)
    {
       int new1 = incoming.indexOf("PAYLOAD");
       String neww = incoming.substring(new1);
       int new2 = neww.indexOf('\n');
       String new3 = neww.substring(new2+1);
       int new4 = new3.indexOf('\n');
       String new5 = new3.substring(0,new4);
      
       Serial.println("Topic: relay/subscribe");
       Serial.print("Message is: ");
       Serial.println(new5);
       new5.remove(new5.length()-1);
       if(new5 == "{\"relay1\":{\"on\":1}}")
       {
        Serial.println("relay1 ON");
        pcf8574_o.digitalWrite(P0, LOW);


      Serial.println("Publishing Message: relay1 ON");
      Serial2.println("AT+CMQTTTOPIC=0,18"); //AT Command for Setting up the Publish Topic Name
      delay(1000);
      Serial2.println(Publish); //Topic Name
      delay(1000);
      Serial2.println("AT+CMQTTPAYLOAD=0,19"); //Payload length
      delay(1000);
      Serial2.println("{\"relay1\":{\"on\":1}}"); //Payload message
      delay(1000);
      Serial2.println("AT+CMQTTPUB=0,1,60"); //Acknowledgment
      delay(1000);
       
       }
       else if(new5 == "{\"relay1\":{\"on\":0}}")
       {
        Serial.println("relay1 OFF");
        pcf8574_o.digitalWrite(P0, HIGH);

      
      Serial.println("Publishing Message: relay1 OFF");
      Serial2.println("AT+CMQTTTOPIC=0,18"); //AT Command for Setting up the Publish Topic Name
      delay(1000);
      Serial2.println(Publish); //Topic Name
      delay(1000);
      Serial2.println("AT+CMQTTPAYLOAD=0,19"); //Payload length
      delay(1000);
      Serial2.println("{\"relay1\":{\"on\":0}}"); //Payload message
      delay(1000);
      Serial2.println("AT+CMQTTPUB=0,1,60"); //Acknowledgment
      delay(1000);      
             
       }
    }     
  }
}

Print this item

  [Arduino IDE demo source code for KC868-A8S]--#13-KC868-A8S_sms-relay_code
Posted by: KinCony Support - 06-30-2022, 12:54 AM - Forum: KC868-A8S - No Replies

[Arduino IDE demo source code for KC868-A8S]--#13-KC868-A8S_sms-relay_code
// make sure set your Serial2 pins in your "HardwareSerial.cpp" for ESP32 as follows:
//#define RX2  15
//#define TX2  13



Code:
// code use for KinCony KC868-A8S board

#include "PCF8574.h"
#include <DS18B20.h>
String incomingData;
String message;
const char phone[] = "xxxxxxxxxxx";  // replace with your mobile phone number
DS18B20 ds(14);


// Set i2c address
PCF8574 pcf8574_o(0x24,4,5);
PCF8574 pcf8574_i(0x22,4,5);

void setup() {
pinMode(2, OUTPUT);   //beep

Serial.begin(115200);
Serial2.begin(115200);

   // set gsm module to tp show the output on serial out
Serial2.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
 
pcf8574_o.pinMode(P0, OUTPUT);
pcf8574_o.pinMode(P1, OUTPUT);
pcf8574_o.pinMode(P2, OUTPUT);
pcf8574_o.pinMode(P3, OUTPUT);
pcf8574_o.pinMode(P4, OUTPUT);
pcf8574_o.pinMode(P5, OUTPUT);
pcf8574_o.pinMode(P6, OUTPUT);
pcf8574_o.pinMode(P7, OUTPUT);

pcf8574_i.pinMode(P0, INPUT);
pcf8574_i.pinMode(P1, INPUT);
pcf8574_i.pinMode(P2, INPUT);
pcf8574_i.pinMode(P3, INPUT);
pcf8574_i.pinMode(P4, INPUT);
pcf8574_i.pinMode(P5, INPUT);
pcf8574_i.pinMode(P6, INPUT);
pcf8574_i.pinMode(P7, INPUT);


Serial.print("Init pcf8574_output...");
  if (pcf8574_o.begin()){
    Serial.println("OK");
  }else{
    Serial.println("KO");
       }

Serial.print("Init pcf8574_input...");
  if (pcf8574_i.begin()){
    Serial.println("OK");
  }else{
    Serial.println("KO");
       }


pcf8574_o.digitalWrite(P0, HIGH);
pcf8574_o.digitalWrite(P1, HIGH);
pcf8574_o.digitalWrite(P2, HIGH);
pcf8574_o.digitalWrite(P3, HIGH);
pcf8574_o.digitalWrite(P4, HIGH);
pcf8574_o.digitalWrite(P5, HIGH);
pcf8574_o.digitalWrite(P6, HIGH);
pcf8574_o.digitalWrite(P7, HIGH);

Serial.print(ds.getTempC());

Serial.print("start test");

Serial2.print("AT+CMGF=1\r");  //Set text mode
/* digitalWrite(2, HIGH);
delay(200); 
digitalWrite(2, LOW);
delay(200);
digitalWrite(2, HIGH);
delay(200); 
digitalWrite(2, LOW);*/
}

void loop() {
// if received command is to turn on relay
  receive_message();

  if(incomingData.indexOf("relay1-on")>=0)
  {
    pcf8574_o.digitalWrite(P0, LOW);
    message = "Relay1 is turned ON";
    // Send a sms back to confirm that the relay is turned on
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);
  }
 
  // if received command is to turn off relay
  if(incomingData.indexOf("relay1-off")>=0)
  {
    pcf8574_o.digitalWrite(P0, HIGH);
    message = "Relay1 is turned OFF";
    // Send a sms back to confirm that the relay is turned off
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);
  }
 
  if(incomingData.indexOf("relay2-on")>=0)
  {
    pcf8574_o.digitalWrite(P1, LOW);
    message = "Relay2 is turned ON";
    // Send a sms back to confirm that the relay is turned on
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);
  }
 
  // if received command is to turn off relay
  if(incomingData.indexOf("relay2-off")>=0)
  {
    pcf8574_o.digitalWrite(P1, HIGH);
    message = "Relay2 is turned OFF";
    // Send a sms back to confirm that the relay is turned off
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);
  } 
 
  if(incomingData.indexOf("relay3-on")>=0)
  {
    pcf8574_o.digitalWrite(P2, LOW);
    message = "Relay3 is turned ON";
    // Send a sms back to confirm that the relay is turned on
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);
  }
 
  // if received command is to turn off relay
  if(incomingData.indexOf("relay3-off")>=0)
  {
    pcf8574_o.digitalWrite(P2, HIGH);
    message = "Relay3 is turned OFF";
    // Send a sms back to confirm that the relay is turned off
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);
  } 
 
  if(incomingData.indexOf("relay4-on")>=0)
  {
    pcf8574_o.digitalWrite(P3, LOW);
    message = "Relay4 is turned ON";
    // Send a sms back to confirm that the relay is turned on
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);     
  }
 
  // if received command is to turn off relay
  if(incomingData.indexOf("relay4-off")>=0)
  {
    pcf8574_o.digitalWrite(P3, HIGH);
    message = "Relay4 is turned OFF";
    // Send a sms back to confirm that the relay is turned off
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);     
  } 
 
  if(incomingData.indexOf("relay5-on")>=0)
  {
    pcf8574_o.digitalWrite(P4, LOW);
    message = "Relay5 is turned ON";
    // Send a sms back to confirm that the relay is turned on
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);     
  }
 
  // if received command is to turn off relay
  if(incomingData.indexOf("relay5-off")>=0)
  {
    pcf8574_o.digitalWrite(P4, HIGH);
    message = "Relay5 is turned OFF";
    // Send a sms back to confirm that the relay is turned off
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);     
  } 
 
  if(incomingData.indexOf("relay6-on")>=0)
  {
    pcf8574_o.digitalWrite(P5, LOW);
    message = "Relay6 is turned ON";
    // Send a sms back to confirm that the relay is turned on
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);     
  }
 
  // if received command is to turn off relay
  if(incomingData.indexOf("relay6-off")>=0)
  {
    pcf8574_o.digitalWrite(P5, HIGH);
    message = "Relay6 is turned OFF";
    // Send a sms back to confirm that the relay is turned off
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);     
  } 
 
  if(incomingData.indexOf("relay7-on")>=0)
  {
    pcf8574_o.digitalWrite(P6, LOW);
    message = "Relay7 is turned ON";
    // Send a sms back to confirm that the relay is turned on
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);     
  }
 
  // if received command is to turn off relay
  if(incomingData.indexOf("relay7-off")>=0)
  {
    pcf8574_o.digitalWrite(P6, HIGH);
    message = "Relay7 is turned OFF";
    // Send a sms back to confirm that the relay is turned off
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);     
  } 
 
  if(incomingData.indexOf("relay8-on")>=0)
  {
    pcf8574_o.digitalWrite(P7, LOW);
    message = "Relay8 is turned ON";
    // Send a sms back to confirm that the relay is turned on
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);     
  }
 
  // if received command is to turn off relay
  if(incomingData.indexOf("relay8-off")>=0)
  {
    pcf8574_o.digitalWrite(P7, HIGH);
    message = "Relay8 is turned OFF";
    // Send a sms back to confirm that the relay is turned off
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);     
  } 
 
  if(incomingData.indexOf("all-on")>=0)
  {
    pcf8574_o.digitalWrite(P0, LOW);
    pcf8574_o.digitalWrite(P1, LOW);
    pcf8574_o.digitalWrite(P2, LOW);
    pcf8574_o.digitalWrite(P3, LOW);
    pcf8574_o.digitalWrite(P4, LOW);
    pcf8574_o.digitalWrite(P5, LOW);
    pcf8574_o.digitalWrite(P6, LOW);
    pcf8574_o.digitalWrite(P7, LOW);
    message = "All relay are turned ON";
    // Send a sms back to confirm that the relay is turned off
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);     
  }   
 
  if(incomingData.indexOf("all-off")>=0)
  {
    pcf8574_o.digitalWrite(P0, HIGH);
    pcf8574_o.digitalWrite(P1, HIGH);
    pcf8574_o.digitalWrite(P2, HIGH);
    pcf8574_o.digitalWrite(P3, HIGH);
    pcf8574_o.digitalWrite(P4, HIGH);
    pcf8574_o.digitalWrite(P5, HIGH);
    pcf8574_o.digitalWrite(P6, HIGH);
    pcf8574_o.digitalWrite(P7, HIGH);
    message = "All relay are turned OFF";
    // Send a sms back to confirm that the relay is turned off
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);     
  }     
 
  if(incomingData.indexOf("temper")>=0)
  {
   
    message = "Temperature is "+String(ds.getTempC(),2)+" C";
    send_message(message);
    Serial2.println("AT+CMGD=1,4");  //delete all SMS on SIM card
    delay(100);     
  }   


  incomingData="";

  uint8_t val1 = pcf8574_i.digitalRead(P0);
  uint8_t val2 = pcf8574_i.digitalRead(P1);
  uint8_t val3 = pcf8574_i.digitalRead(P2);
  uint8_t val4 = pcf8574_i.digitalRead(P3);
  uint8_t val5 = pcf8574_i.digitalRead(P4);
  uint8_t val6 = pcf8574_i.digitalRead(P5);
  uint8_t val7 = pcf8574_i.digitalRead(P6);
  uint8_t val8 = pcf8574_i.digitalRead(P7);

  if (val1==LOW)
   {
     Serial.println("input1 trigger");
     pcf8574_o.digitalWrite(P0, LOW);
     delay(5000);
     pcf8574_o.digitalWrite(P0, HIGH);
     
     message = "door sensor is triggered,someone in the room!";
     send_message(message);
     delay(100);
   }

  if (val2==LOW)
   {
     Serial.println("input2 trigger");
     pcf8574_o.digitalWrite(P0, LOW);
     delay(5000);
     pcf8574_o.digitalWrite(P0, HIGH);
     
     message = "window sensor is triggered,someone in the room!";
     send_message(message);
     delay(100);
   }

  if (val3==LOW)
   {
     Serial.println("input3 trigger");
     message = "sensor3 is triggered,someone in the room!";
     send_message(message);
     delay(100);
   }

  if (val4==LOW)
   {
     Serial.println("input4 trigger");   
     message = "sensor4 is triggered,someone in the room!";
     send_message(message);
     delay(100);
   }

  if (val5==LOW)
   {
     Serial.println("input5 trigger");     
     message = "sensor5 is triggered,someone in the room!";
     send_message(message);
     delay(100);
   }

  if (val6==LOW)
   {
     Serial.println("input6 trigger");     
     message = "sensor6 is triggered,someone in the room!";
     send_message(message);
     delay(100);
   }

  if (val7==LOW)
   {
     Serial.println("input7 trigger");   
     message = "sensor7 is triggered,someone in the room!";
     send_message(message);
     delay(100);
   }

  if (val8==LOW)
   {
     Serial.println("input8 trigger");     
     message = "sensor8 is triggered,someone in the room!";
     send_message(message);
     delay(100);
   }
delay(200);
}

void receive_message()
{
  if (Serial2.available() > 0)
  {
    incomingData = Serial2.readString(); // Get the data from the serial port.
    Serial.print(incomingData);
    delay(10);
  }
}

void send_message(String message)
{
  Serial2.println("AT+CMGF=1");    //Set the GSM Module in Text Mode
  delay(100); 
  Serial2.print("AT+CMGS=\""+String(phone)+"\"\r"); //Send message
  delay(100);
  Serial2.println(message);   // The SMS text you want to send
  delay(100);
  Serial2.println((char)26);  // ASCII code of CTRL+Z
  delay(100);
  Serial2.println();
  delay(100); 
}

Print this item