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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 5,367
» Latest member: talljane
» Forum threads: 2,574
» Forum posts: 13,309

Full Statistics

Online Users
There are currently 47 online users.
» 0 Member(s) | 29 Guest(s)
Bing, Bytespider, Crawl, Google, PetalBot, Semrush, Yandex, bot

Latest Threads
How can I power multiple ...
Forum: KC868-A series and Uair Smart Controller
Last Post: ingersoj
27 minutes ago
» Replies: 9
» Views: 111
Problem with IFTTT automa...
Forum: "KCS" firmware system
Last Post: admin
1 hour ago
» Replies: 6
» Views: 42
A32 Pro ESPHome yaml incl...
Forum: KC868-A32/A32 Pro
Last Post: admin
1 hour ago
» Replies: 18
» Views: 183
KC868-A2 ESP32 I/O pin de...
Forum: KC868-A2
Last Post: admin
1 hour ago
» Replies: 8
» Views: 2,266
change wake up name
Forum: KinCony AS
Last Post: gal
Yesterday, 07:36 AM
» Replies: 12
» Views: 84
Need help with configurat...
Forum: KC868-HxB series Smart Controller
Last Post: admin
Yesterday, 04:32 AM
» Replies: 32
» Views: 394
ESP32 S3 set up issue
Forum: Extender module
Last Post: admin
12-17-2024, 11:43 PM
» Replies: 10
» Views: 68
KC868-A8 Schematic
Forum: KC868-A8
Last Post: admin
12-17-2024, 11:40 PM
» Replies: 7
» Views: 51
"KCS" v2.2.8 firmware BIN...
Forum: "KCS" firmware system
Last Post: admin
12-17-2024, 11:38 PM
» Replies: 2
» Views: 178
Dimensions/drawings of bo...
Forum: Schematic and diagram
Last Post: admin
12-17-2024, 11:37 PM
» Replies: 1
» Views: 23

  KC868-A4 PCB updated V1.2.4
Posted by: admin - 08-24-2022, 12:09 AM - Forum: News - Replies (7)

new pcb v1.2.4 of KC868-A4, replaced USB-C with MiniUSB port.
[Image: KC868-A4_03.jpg]

Print this item

  KC 868 AG - YAML Code
Posted by: nrnr - 08-23-2022, 07:14 PM - Forum: Development - Replies (4)

I've edited YAML code for IR gateway. I'm recieving error message related to "if" command - "Component not found if."

The code:

remote_receiver:
  pin: GPIO23
  dump: all

binary_sensor:
  - platform: remote_receiver
    name: "TEST"
    pronto:
      data: "0000 006D 0022 0000 0151 00AD 0015 0014 0017 0041 0015 0014 0017 0016 0015 0044 0012 0014 0017 0044 0013 0018 0013 0043 0013 0016 0015 0044 0012 0044 0013 0016 0015 0043 0013 0016 0015 0044 0013 0016 0015 0041 0016 0015 0015 0041 0016 0040 0015 0014 0017 0013 0018 0013 0018 003F 0018 0013 0018 003F 0019 0012 0018 0013 0018 003F 0018 003F 0018 003F 0018 06C3"

if:
  condition:
    binary_sensor.is_on: TEST
  then:
    - mqtt.publish:
        topic: IR_Bridge
        payload: "Something happened!"


component not found if.
component not found if.

Print this item

  [Arduino IDE demo source code for KC868-A8]--#10-Web server_code
Posted by: KinCony Support - 08-23-2022, 09:01 AM - Forum: KC868-A8 - No Replies

[Arduino IDE demo source code for KC868-A8]--#10-Web server_code


.zip   KC868-A8_Web_Server.zip (Size: 462.26 KB / Downloads: 308)

   

Code:
/***********************************************************
* Create Your own WebServer for KC868-A8 Smart Controller*
* https://www.kincony.com                                **
***********************************************************/

// Load Wi-Fi library
#include <WiFi.h>
#include "PCF8574.h"
#include <WiFiManager.h>
#define TRIGGER_PIN 0   // reset wifi button
WiFiManager wm;
int timeout =20; // seconds to run for
// Replace with your network credentials
/*******config the WIFI by phone*****************/

/* const char* ssid     = "xxx"; //your router's ssid
const char* password = "yyy"; //your router's password*/
/*******************************************************/

// Set web server port number to 80
WiFiServer server(80);

// Variable to store the HTTP request
String header;

// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;

int flag_read_di=0;

TwoWire I2Cone = TwoWire(0);

//set I2C of A8
PCF8574 pcf8574_I1(&I2Cone,0x22,4,5);
PCF8574 pcf8574_R1(&I2Cone,0x24,4,5);

String relaystate[8]={"relay1state","relay2state","relay3state","relay4state",
                       "relay5state","relay6state","relay7state","relay8state",
                     };
String relay1state = "off";// state of relay1
String relay2state = "off";// state of relay2
String relay3state = "off";// state of relay3
String relay4state = "off";// state of relay4
String relay5state = "off";// state of relay5
String relay6state = "off";// state of relay6
String relay7state = "off";// state of relay7
String relay8state = "off";// state of relay8


void setup() {

  pinMode(TRIGGER_PIN, INPUT_PULLUP); // wifi reset button
  Serial.begin(115200);

  // Set PCF8574 pinMode to OUTPUT
  for(int i=0;i<=7;i++)
  {
     pcf8574_R1.pinMode(i, OUTPUT);
  }
 
  pcf8574_R1.begin();
 
  for(int i=0;i<=7;i++)
  {
     pcf8574_I1.pinMode(i, INPUT);
  }

    pcf8574_I1.begin();
     

  for(int i=0;i<=7;i++)
  {
     pcf8574_R1.digitalWrite(i, HIGH);
    
  }
    WiFi.mode(WIFI_STA);
    wm.setConfigPortalTimeout(timeout);
     bool res;
       res = wm.autoConnect("KC868-A8-AP"); // anonymous ap
    if(!res) {
        Serial.println("Failed to connect");
    }
    else {
        //if you get here you have connected to the WiFi   
        Serial.println("connected...yeey :)");
    }  
 
  // Print local IP address and start web server
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  server.begin();

}

void loop(){
  WiFiClient client = server.available();   // Listen for incoming clients

  if (client) {                             // If a new client connects,
    Serial.println("New Client.");          // print a message out in the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    currentTime = millis();
    previousTime = currentTime;
    while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected
      currentTime = millis();        
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        header += c;
        if (c == '\n') {                    // if the byte is a newline character
          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();
           
            // turns 16 relays on and off
            if (header.indexOf("GET /1/on") >= 0) {relay1state = "on";pcf8574_R1.digitalWrite(P0, LOW);}
            else if (header.indexOf("GET /1/off") >= 0) {relay1state = "off";pcf8574_R1.digitalWrite(P0, HIGH);}
            else if (header.indexOf("GET /2/on") >= 0)  {relay2state = "on";pcf8574_R1.digitalWrite(P1, LOW);}
            else if (header.indexOf("GET /2/off") >= 0) {relay2state = "off";pcf8574_R1.digitalWrite(P1, HIGH);}
            else if (header.indexOf("GET /3/on") >= 0)  {relay3state = "on";pcf8574_R1.digitalWrite(P2, LOW);}
            else if (header.indexOf("GET /3/off") >= 0) {relay3state = "off";pcf8574_R1.digitalWrite(P2, HIGH);}        
            else if (header.indexOf("GET /4/on") >= 0)  {relay4state = "on";pcf8574_R1.digitalWrite(P3, LOW);}
            else if (header.indexOf("GET /4/off") >= 0) {relay4state = "off";pcf8574_R1.digitalWrite(P3, HIGH);}
            else if (header.indexOf("GET /5/on") >= 0)  {relay5state = "on";pcf8574_R1.digitalWrite(P4, LOW);}
            else if (header.indexOf("GET /5/off") >= 0) {relay5state = "off";pcf8574_R1.digitalWrite(P4, HIGH);}
            else if (header.indexOf("GET /6/on") >= 0)  {relay6state = "on";pcf8574_R1.digitalWrite(P5, LOW);}
            else if (header.indexOf("GET /6/off") >= 0) {relay6state = "off";pcf8574_R1.digitalWrite(P5, HIGH);}         
            else if (header.indexOf("GET /7/on") >= 0)  {relay7state = "on";pcf8574_R1.digitalWrite(P6, LOW);}
            else if (header.indexOf("GET /7/off") >= 0) {relay7state = "off";pcf8574_R1.digitalWrite(P6, HIGH);}
            else if (header.indexOf("GET /8/on") >= 0)  {relay8state = "on";pcf8574_R1.digitalWrite(P7, LOW);}
            else if (header.indexOf("GET /8/off") >= 0) {relay8state = "off";pcf8574_R1.digitalWrite(P7, HIGH);}
                 
            else if (header.indexOf("GET /read") >= 0) flag_read_di=1;
            else if (header.indexOf("GET /all/on") >= 0)
            {
              relay1state = "on";// state of relay1
              relay2state = "on";// state of relay2
              relay3state = "on";// state of relay3
              relay4state = "on";// state of relay4
              relay5state = "on";// state of relay5
              relay6state = "on";// state of relay6
              relay7state = "on";// state of relay7
              relay8state = "on";// state of relay8

              for(int i=0;i<=7;i++)
              {
                 pcf8574_R1.digitalWrite(i, LOW);
              }
             
            }
            else if (header.indexOf("GET /all/off") >= 0)
            {
              relay1state = "off";// state of relay1
              relay2state = "off";// state of relay2
              relay3state = "off";// state of relay3
              relay4state = "off";// state of relay4
              relay5state = "off";// state of relay5
              relay6state = "off";// state of relay6
              relay7state = "off";// state of relay7
              relay8state = "off";// state of relay8

              for(int i=0;i<=7;i++)
              {
                 pcf8574_R1.digitalWrite(i, HIGH);
              }
              
            }
           
            // Display the HTML web page
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            // CSS to style the on/off buttons
            // Feel free to change the background-color and font-size attributes to fit your preferences
            client.println("<style>html { font-family: Helvetica; display: inline-block; border: 3px solid green;margin: 0px 15px;}");
            client.println(".button { background-color: #195B00; border-radius: 10px;color: white; padding: 10px 40px;");
            client.println("text-decoration: none; font-size: 20px; margin: 2px;text-align: center; cursor: pointer;}");
            client.println(".button2 {background-color: #77878A;}</style></head>");
           
            if (flag_read_di==1)
            {
              client.println(" relay1:" + relay1state + " relay2:" + relay2state + " relay3:" + relay3state + " relay4:" + relay4state + " relay5:" + relay5state + " relay6:" + relay6state + " relay7:" + relay7state + " relay8:" + relay8state);
            }
            else
            {
            // Web Page Heading
            client.println("<body><h1>KC868-A8 Web Server</h1>");


            // Display current state, and ON/OFF buttons for relay
            //client.println("<p>relay1 - State " + relay1state + "</p>");
            // If the relay is off, it displays the ON button     
            if (relay1state == "off") client.println("<a href=\"/1/on\"><button class=\"button\">01-OFF</button></a>"); else client.println("<a href=\"/1/off\"><button class=\"button\">01-ON </button></a>");
            if (relay2state == "off") client.println("<a href=\"/2/on\"><button class=\"button\">02-OFF</button></a>"); else client.println("<a href=\"/2/off\"><button class=\"button\">02-ON </button></a>");                                
            if (relay3state == "off") client.println("<a href=\"/3/on\"><button class=\"button\">03-OFF</button></a>"); else client.println("<a href=\"/3/off\"><button class=\"button\">03-ON </button></a>");
            if (relay4state == "off") client.println("<a href=\"/4/on\"><button class=\"button\">04-OFF</button></a>"); else client.println("<a href=\"/4/off\"><button class=\"button\">04-ON </button></a>");
            if (relay5state == "off") client.println("<a href=\"/5/on\"><button class=\"button\">05-OFF</button></a>"); else client.println("<a href=\"/5/off\"><button class=\"button\">05-ON </button></a>");
            if (relay6state == "off") client.println("<a href=\"/6/on\"><button class=\"button\">06-OFF</button></a>"); else client.println("<a href=\"/6/off\"><button class=\"button\">06-ON </button></a>");                                
            if (relay7state == "off") client.println("<a href=\"/7/on\"><button class=\"button\">07-OFF</button></a>"); else client.println("<a href=\"/7/off\"><button class=\"button\">07-ON </button></a>");
            if (relay8state == "off") client.println("<a href=\"/8/on\"><button class=\"button\">08-OFF</button></a>"); else client.println("<a href=\"/8/off\"><button class=\"button\">08-ON </button></a>");
           
              client.println("<a href=\"/all/on\"><button class=\"button\">All-ON</button></a>");
              client.println("<a href=\"/all/off\"><button class=\"button\">All-OFF</button></a>");
            } 
            client.println("</body></html>");
           
            // The HTTP response ends with another blank line
            client.println();
            break;
          } else { // if you got a newline, then clear currentLine
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
      }
    }
    // Clear the header variable
    header = "";
    // Close the connection
    client.stop();
    Serial.println("Client disconnected.");
    Serial.println("");
    flag_read_di=0;
  }

  ScanKey();            //scan key
  if ( digitalRead(TRIGGER_PIN) == LOW) {wm.resetSettings();ESP.restart();}
}

void ScanKey()           
{
  for(int i=0;i<=7;i++)
  {
    if(pcf8574_I1.digitalRead(i) == LOW)         //key pressed
      {
        delay(20);                       
        if(pcf8574_I1.digitalRead(i) == LOW)       //key pressed again
        {
          pcf8574_R1.digitalWrite(i,!pcf8574_R1.digitalRead(i));    // toggle relay1 state    
          while(pcf8574_I1.digitalRead(i) == LOW); //wait remove hand
          if (pcf8574_R1.digitalRead(i) == LOW) relaystate[i+1]="on";else relaystate[i+1]="off";
        }
      }
  }

}

Print this item

  [Arduino IDE demo source code for KC868-A6]--#12-Web_server_code
Posted by: KinCony Support - 08-23-2022, 08:59 AM - Forum: KC868-A6 - Replies (3)

[Arduino IDE demo source code for KC868-A6]--#12-Web_server_code

.zip   KC868-A6_Web_Server.zip (Size: 461.74 KB / Downloads: 452)

   

Code:
/***********************************************************
* Create Your own WebServer for KC868-A6 Smart Controller*
* https://www.kincony.com                                **
***********************************************************/

// Load Wi-Fi library
#include <WiFi.h>
#include "PCF8574.h"
#include <WiFiManager.h>
#define TRIGGER_PIN 0   // reset wifi button
WiFiManager wm;
int timeout =20; // seconds to run for
// Replace with your network credentials
/*******config the WIFI by phone*****************/

/* const char* ssid     = "xxx"; //your router's ssid
const char* password = "yyy"; //your router's password*/
/*******************************************************/

// Set web server port number to 80
WiFiServer server(80);

// Variable to store the HTTP request
String header;

// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;

int flag_read_di=0;

TwoWire I2Cone = TwoWire(0);
TwoWire I2Ctwo = TwoWire(1);

//set I2C of A6
PCF8574 pcf8574_I1(&I2Cone,0x22,4,15);
PCF8574 pcf8574_R1(&I2Cone,0x24,4,15);

String relaystate[16]={"relay1state","relay2state","relay3state","relay4state",
                       "relay5state","relay6state"
                      };
String relay1state = "off";// state of relay1
String relay2state = "off";// state of relay2
String relay3state = "off";// state of relay3
String relay4state = "off";// state of relay4
String relay5state = "off";// state of relay5
String relay6state = "off";// state of relay6


void setup() {

  pinMode(TRIGGER_PIN, INPUT_PULLUP); // wifi reset button
  Serial.begin(115200);

  // Set PCF8574 pinMode to OUTPUT
  for(int i=0;i<=5;i++)
  {
     pcf8574_R1.pinMode(i, OUTPUT);
  }
 
  pcf8574_R1.begin();

 
  for(int i=0;i<=5;i++)
  {
     pcf8574_I1.pinMode(i, INPUT);
  }
    pcf8574_I1.begin();
   
  for(int i=0;i<=5;i++)
  {
     pcf8574_R1.digitalWrite(i, HIGH);
  }
    WiFi.mode(WIFI_STA);
    wm.setConfigPortalTimeout(timeout);
     bool res;
       res = wm.autoConnect("KC868-A6-AP"); // anonymous ap
    if(!res) {
        Serial.println("Failed to connect");
    }
    else {
        //if you get here you have connected to the WiFi   
        Serial.println("connected...yeey :)");
    }   
 
  // Print local IP address and start web server
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  server.begin();

}

void loop(){
  WiFiClient client = server.available();   // Listen for incoming clients

  if (client) {                             // If a new client connects,
    Serial.println("New Client.");          // print a message out in the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    currentTime = millis();
    previousTime = currentTime;
    while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected
      currentTime = millis();         
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        header += c;
        if (c == '\n') {                    // if the byte is a newline character
          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();
           
            // turns 16 relays on and off
            if (header.indexOf("GET /1/on") >= 0) {relay1state = "on";pcf8574_R1.digitalWrite(P0, LOW);}
            else if (header.indexOf("GET /1/off") >= 0) {relay1state = "off";pcf8574_R1.digitalWrite(P0, HIGH);}
            else if (header.indexOf("GET /2/on") >= 0)  {relay2state = "on";pcf8574_R1.digitalWrite(P1, LOW);}
            else if (header.indexOf("GET /2/off") >= 0) {relay2state = "off";pcf8574_R1.digitalWrite(P1, HIGH);}
            else if (header.indexOf("GET /3/on") >= 0)  {relay3state = "on";pcf8574_R1.digitalWrite(P2, LOW);}
            else if (header.indexOf("GET /3/off") >= 0) {relay3state = "off";pcf8574_R1.digitalWrite(P2, HIGH);}         
            else if (header.indexOf("GET /4/on") >= 0)  {relay4state = "on";pcf8574_R1.digitalWrite(P3, LOW);}
            else if (header.indexOf("GET /4/off") >= 0) {relay4state = "off";pcf8574_R1.digitalWrite(P3, HIGH);}
            else if (header.indexOf("GET /5/on") >= 0)  {relay5state = "on";pcf8574_R1.digitalWrite(P4, LOW);}
            else if (header.indexOf("GET /5/off") >= 0) {relay5state = "off";pcf8574_R1.digitalWrite(P4, HIGH);}
            else if (header.indexOf("GET /6/on") >= 0)  {relay6state = "on";pcf8574_R1.digitalWrite(P5, LOW);}
            else if (header.indexOf("GET /6/off") >= 0) {relay6state = "off";pcf8574_R1.digitalWrite(P5, HIGH);}         
       
            else if (header.indexOf("GET /read") >= 0) flag_read_di=1;
            else if (header.indexOf("GET /all/on") >= 0)
            {
              relay1state = "on";// state of relay1
              relay2state = "on";// state of relay2
              relay3state = "on";// state of relay3
              relay4state = "on";// state of relay4
              relay5state = "on";// state of relay5
              relay6state = "on";// state of relay6

              for(int i=0;i<=5;i++)
              {
                 pcf8574_R1.digitalWrite(i, LOW);
              }
             
            }
            else if (header.indexOf("GET /all/off") >= 0)
            {
              relay1state = "off";// state of relay1
              relay2state = "off";// state of relay2
              relay3state = "off";// state of relay3
              relay4state = "off";// state of relay4
              relay5state = "off";// state of relay5
              relay6state = "off";// state of relay6


              for(int i=0;i<=5;i++)
              {
                 pcf8574_R1.digitalWrite(i, HIGH);
              }
               
            }
           
            // Display the HTML web page
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            // CSS to style the on/off buttons
            // Feel free to change the background-color and font-size attributes to fit your preferences
            client.println("<style>html { font-family: Helvetica; display: inline-block; border: 3px solid green;margin: 0px 15px;}");
            client.println(".button { background-color: #195B00; border-radius: 10px;color: white; padding: 10px 40px;");
            client.println("text-decoration: none; font-size: 20px; margin: 2px;text-align: center; cursor: pointer;}");
            client.println(".button2 {background-color: #77878A;}</style></head>");
           
            if (flag_read_di==1)
            {
              client.println(" relay1:" + relay1state + " relay2:" + relay2state + " relay3:" + relay3state + " relay4:" + relay4state + " relay5:" + relay5state + " relay6:" + relay6state);
            }
            else
            {
            // Web Page Heading
            client.println("<body><h1>KC868-A6 Web Server</h1>");


            // Display current state, and ON/OFF buttons for relay
            //client.println("<p>relay1 - State " + relay1state + "</p>");
            // If the relay is off, it displays the ON button     
            if (relay1state == "off") client.println("<a href=\"/1/on\"><button class=\"button\">01-OFF</button></a>"); else client.println("<a href=\"/1/off\"><button class=\"button\">01-ON </button></a>");
            if (relay2state == "off") client.println("<a href=\"/2/on\"><button class=\"button\">02-OFF</button></a>"); else client.println("<a href=\"/2/off\"><button class=\"button\">02-ON </button></a>");                                 
            if (relay3state == "off") client.println("<a href=\"/3/on\"><button class=\"button\">03-OFF</button></a>"); else client.println("<a href=\"/3/off\"><button class=\"button\">03-ON </button></a>");
            if (relay4state == "off") client.println("<a href=\"/4/on\"><button class=\"button\">04-OFF</button></a>"); else client.println("<a href=\"/4/off\"><button class=\"button\">04-ON </button></a>");
            if (relay5state == "off") client.println("<a href=\"/5/on\"><button class=\"button\">05-OFF</button></a>"); else client.println("<a href=\"/5/off\"><button class=\"button\">05-ON </button></a>");
            if (relay6state == "off") client.println("<a href=\"/6/on\"><button class=\"button\">06-OFF</button></a>"); else client.println("<a href=\"/6/off\"><button class=\"button\">06-ON </button></a>");                                 
   
              client.println("<a href=\"/all/on\"><button class=\"button\">All-ON</button></a>");
              client.println("<a href=\"/all/off\"><button class=\"button\">All-OFF</button></a>");
            } 
            client.println("</body></html>");
           
            // The HTTP response ends with another blank line
            client.println();
            break;
          } else { // if you got a newline, then clear currentLine
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
      }
    }
    // Clear the header variable
    header = "";
    // Close the connection
    client.stop();
    Serial.println("Client disconnected.");
    Serial.println("");
    flag_read_di=0;
  }

  ScanKey();            //scan key
  if ( digitalRead(TRIGGER_PIN) == LOW) {wm.resetSettings();ESP.restart();}
}

void ScanKey()           
{
  for(int i=0;i<=5;i++)
  {
    if(pcf8574_I1.digitalRead(i) == LOW)         //key pressed
      {
        delay(20);                       
        if(pcf8574_I1.digitalRead(i) == LOW)       //key pressed again
        {
          pcf8574_R1.digitalWrite(i,!pcf8574_R1.digitalRead(i));    // toggle relay1 state     
          while(pcf8574_I1.digitalRead(i) == LOW); //wait remove hand
          if (pcf8574_R1.digitalRead(i) == LOW) relaystate[i+1]="on";else relaystate[i+1]="off";
        }
      }
  }


}

Print this item

  [Arduino demo source code for KC868-A4]-12 web server by wifi
Posted by: KinCony Support - 08-23-2022, 08:54 AM - Forum: KC868-A4 - No Replies

[Arduino IDE demo source code for KC868-A4]--#12-WEB_SERVER_CODE

.zip   KC868-A4_Web_Server.zip (Size: 454.76 KB / Downloads: 322)

   

Code:
/***********************************************************
* Create Your own WebServer for KC868-A4 Smart Controller*
* https://www.kincony.com                                **
***********************************************************/

// Load Wi-Fi library
#include <WiFi.h>
#include <WiFiManager.h>
#define TRIGGER_PIN 0   // reset wifi button
WiFiManager wm;
int timeout =20; // seconds to run for
// Replace with your network credentials
/*******config the WIFI by phone*****************/

/* const char* ssid     = "xxx"; //your router's ssid
const char* password = "yyy"; //your router's password*/
/*******************************************************/

// Set web server port number to 80
WiFiServer server(80);

// Variable to store the HTTP request
String header;

// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;

int flag_read_di=0;

String relay1state = "off";// state of relay1
String relay2state = "off";// state of relay2
String relay3state = "off";// state of relay3
String relay4state = "off";// state of relay4



void setup() {

  pinMode(TRIGGER_PIN, INPUT_PULLUP); // wifi reset button
  Serial.begin(115200);
  pinMode(2,OUTPUT);
  pinMode(15,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(4,OUTPUT);
 

  pinMode(36,INPUT); 
  pinMode(39,INPUT);
  pinMode(27,INPUT);
  pinMode(14,INPUT);

  digitalWrite(2, HIGH);
  digitalWrite(15,HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(4, HIGH);
 

 
    WiFi.mode(WIFI_STA);
    wm.setConfigPortalTimeout(timeout);
     bool res;
       res = wm.autoConnect("KC868-A4-AP"); // anonymous ap
    if(!res) {
        Serial.println("Failed to connect");
    }
    else {
        //if you get here you have connected to the WiFi   
        Serial.println("connected...yeey :)");
    }  
 
  // Print local IP address and start web server
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  server.begin();

}

void loop(){
  WiFiClient client = server.available();   // Listen for incoming clients

  if (client) {                             // If a new client connects,
    Serial.println("New Client.");          // print a message out in the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    currentTime = millis();
    previousTime = currentTime;
    while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected
      currentTime = millis();        
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        header += c;
        if (c == '\n') {                    // if the byte is a newline character
          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();
           
            // turns 16 relays on and off
                 if (header.indexOf("GET /1/on") >= 0)  {relay1state = "on"; digitalWrite(2, HIGH);}
            else if (header.indexOf("GET /1/off") >= 0) {relay1state = "off";digitalWrite(2, LOW);}
            else if (header.indexOf("GET /2/on") >= 0)  {relay2state = "on"; digitalWrite(15, HIGH);}
            else if (header.indexOf("GET /2/off") >= 0) {relay2state = "off";digitalWrite(15, LOW);}
            else if (header.indexOf("GET /3/on") >= 0)  {relay3state = "on"; digitalWrite(5, HIGH);}
            else if (header.indexOf("GET /3/off") >= 0) {relay3state = "off";digitalWrite(5, LOW);}        
            else if (header.indexOf("GET /4/on") >= 0)  {relay4state = "on"; digitalWrite(4, HIGH);}
            else if (header.indexOf("GET /4/off") >= 0) {relay4state = "off";digitalWrite(4, LOW);}
              
            else if (header.indexOf("GET /read") >= 0) flag_read_di=1;
            else if (header.indexOf("GET /all/on") >= 0)
            {
              relay1state = "on";// state of relay1
              relay2state = "on";// state of relay2
              relay3state = "on";// state of relay3
              relay4state = "on";// state of relay4
  digitalWrite(2, HIGH);
                digitalWrite(15,HIGH);
                digitalWrite(5, HIGH);
                digitalWrite(4, HIGH);
              
             
            }
            else if (header.indexOf("GET /all/off") >= 0)
            {
              relay1state = "off";// state of relay1
              relay2state = "off";// state of relay2
              relay3state = "off";// state of relay3
              relay4state = "off";// state of relay4

                digitalWrite(2, LOW);
                digitalWrite(15,LOW);
                digitalWrite(5, LOW);
                digitalWrite(4, LOW);
           
            }
           
            // Display the HTML web page
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            // CSS to style the on/off buttons
            // Feel free to change the background-color and font-size attributes to fit your preferences
            client.println("<style>html { font-family: Helvetica; display: inline-block; border: 3px solid green;margin: 0px 15px;}");
            client.println(".button { background-color: #195B00; border-radius: 10px;color: white; padding: 10px 40px;");
            client.println("text-decoration: none; font-size: 20px; margin: 2px;text-align: center; cursor: pointer;}");
            client.println(".button2 {background-color: #77878A;}</style></head>");
           
            if (flag_read_di==1)
            {
              client.println(" relay1:" + relay1state + " relay2:" + relay2state + " relay3:" + relay3state + " relay4:" + relay4state );
            }
            else
            {
            // Web Page Heading
            client.println("<body><h1>KC868-A4 Web Server</h1>");


            // Display current state, and ON/OFF buttons for relay
            //client.println("<p>relay1 - State " + relay1state + "</p>");
            // If the relay is off, it displays the ON button     
            if (relay1state == "off") client.println("<a href=\"/1/on\"><button class=\"button\">01-OFF</button></a>"); else client.println("<a href=\"/1/off\"><button class=\"button\">01-ON </button></a>");
            if (relay2state == "off") client.println("<a href=\"/2/on\"><button class=\"button\">02-OFF</button></a>"); else client.println("<a href=\"/2/off\"><button class=\"button\">02-ON </button></a>");                                
            if (relay3state == "off") client.println("<a href=\"/3/on\"><button class=\"button\">03-OFF</button></a>"); else client.println("<a href=\"/3/off\"><button class=\"button\">03-ON </button></a>");
            if (relay4state == "off") client.println("<a href=\"/4/on\"><button class=\"button\">04-OFF</button></a>"); else client.println("<a href=\"/4/off\"><button class=\"button\">04-ON </button></a>");
                                         
  
              client.println("<a href=\"/all/on\"><button class=\"button\">All-ON</button></a>");
              client.println("<a href=\"/all/off\"><button class=\"button\">All-OFF</button></a>");
            } 
            client.println("</body></html>");
           
            // The HTTP response ends with another blank line
            client.println();
            break;
          } else { // if you got a newline, then clear currentLine
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
      }
    }
    // Clear the header variable
    header = "";
    // Close the connection
    client.stop();
    Serial.println("Client disconnected.");
    Serial.println("");
    flag_read_di=0;
  }

  ScanKey();            //scan key
  if ( digitalRead(TRIGGER_PIN) == LOW) {wm.resetSettings();ESP.restart();}
}

void ScanKey()           
{
 
    if(digitalRead(36) == LOW)         //key pressed
      {
        delay(20);                       
        if(digitalRead(36) == LOW)       //key pressed again
        {
          digitalWrite(2,!digitalRead(2));    // toggle relay1 state    
          while(digitalRead(36) == LOW); //wait remove hand
          if (digitalRead(2) == LOW) relay1state="on";else relay1state="off";
        }
      }

if(digitalRead(39) == LOW)         //key pressed
      {
        delay(20);                       
        if(digitalRead(39) == LOW)       //key pressed again
        {
          digitalWrite(15,!digitalRead(15));    // toggle relay1 state    
          while(digitalRead(39) == LOW); //wait remove hand
          if (digitalRead(15) == LOW) relay2state="on";else relay2state="off";
        }
      }

    if(digitalRead(27) == LOW)         //key pressed
      {
        delay(20);                       
        if(digitalRead(27) == LOW)       //key pressed again
        {
          digitalWrite(5,!digitalRead(5));    // toggle relay1 state    
          while(digitalRead(27) == LOW); //wait remove hand
          if (digitalRead(5) == LOW) relay3state="on";else relay3state="off";
        }
      } 
      if(digitalRead(14) == LOW)         //key pressed
          {
            delay(20);                       
            if(digitalRead(14) == LOW)       //key pressed again
            {
              digitalWrite(4,!digitalRead(4));    // toggle relay1 state    
              while(digitalRead(14) == LOW); //wait remove hand
              if (digitalRead(4) == LOW) relay4state="on";else relay4state="off";
            }
          }
 


}

Print this item

  kbox android app updated
Posted by: admin - 08-23-2022, 12:37 AM - Forum: News - No Replies

add "clear cache" function in app. You can download from Google play store, search: KBOX smart
when change mqtt broker IP or domain name, you need to do "clear cache" .

Print this item

  KC868-H32BS V1.48 new firmware update
Posted by: admin - 08-23-2022, 12:35 AM - Forum: News - No Replies

improvement:

1. when mqtt broker or server restart, KC868-H32BS can auto connect to mqtt broker again without reboot. such as if home assistant updated new version, after home assistant reboot, H32BS can work well without reboot.


.zip   H32BS_V148_20220819.zip (Size: 53.47 KB / Downloads: 224)

Print this item

Question KC868-AG ESP32 315/433Mhz or only 433Mhz?
Posted by: greg - 08-21-2022, 11:35 PM - Forum: KC868-A series and Uair Smart Controller - Replies (5)

Hi Team, is the KC868-AG ESP32 both 315Mhz & 433Mhz? The Aliexpress listing says it's both 315Mhz & 433Mhz but I can't find any reference to 315Mhz in the documentation. Cheers!

Print this item

Sad KC868-H32B malfunctioned
Posted by: saun2000 - 08-21-2022, 09:26 PM - Forum: KC868-HxB series Smart Controller - Replies (9)

I was using this both KC868-H32B Relay modules with touch switches and MQTT with Home assistant. This was working fine. Suddenly one relay module reset to its ip address to 192.168.1.200 by itself and now nothing is working. Even touch switches are not working. I change the ip back to the existing one. but still doesn't work. Do you have any idea to fix this?

Print this item

  I2C Display to A4
Posted by: masoos - 08-16-2022, 10:16 PM - Forum: DIY Project - Replies (5)

Hello,
I need for my project a cheap 2 line display.
Please suggest me how to wire the SDA and SCL Line.
And maybe you have small code? that would be wonderful.
Thanks

Print this item