Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Arduino demo source code for KC868-A4]-13 work with KBOX phone app
#1
use for "KBOX" phone app in local network , without internet.


.zip   KBOX.zip (Size: 837 bytes / Downloads: 256)
Reply
#2
Sad 
(05-04-2022, 11:40 AM)admin Wrote: use for "KBOX" phone app in local network , without internet.


hello admin.

I have a KC868-A8, I am trying to use KBOX to control the Relays, but running the application does not activate the relays, can you help me with this?
Thanks for everything.

this is the code:


Code:
#include <WiFi.h>

#include "Arduino.h"
#include "PCF8574.h"

const char* ssid = "ARRIS-1001";
const char* password =  "AAAAABBBBBCCCCC";

//Salidas -OUTPUTS
PCF8574 pcf8574_S(0x24);

//Entradas -INPUTS
PCF8574 pcf8574(0x22);





WiFiServer wifiServer(4196);

void setup() {

// Set pinMode to OUTPUT
  pcf8574_S.pinMode(P0, OUTPUT);
  pcf8574_S.pinMode(P1, OUTPUT);
  pcf8574_S.pinMode(P2, OUTPUT);
  pcf8574_S.pinMode(P3, OUTPUT);
  pcf8574_S.pinMode(P4, OUTPUT);
  pcf8574_S.pinMode(P5, OUTPUT);
  pcf8574_S.pinMode(P6, OUTPUT);
  pcf8574_S.pinMode(P7, OUTPUT);
// 

//Entradas -  to INPUTS
pcf8574.pinMode(P0, INPUT);
pcf8574.pinMode(P1, INPUT);
pcf8574.pinMode(P2, INPUT);
pcf8574.pinMode(P3, INPUT);
pcf8574.pinMode(P4, INPUT);
pcf8574.pinMode(P5, INPUT);
pcf8574.pinMode(P6, INPUT);
pcf8574.pinMode(P7, INPUT);


  Serial.begin(115200);

  delay(1000);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }

  Serial.println("Connected to the WiFi network");
  Serial.println(WiFi.localIP());

  wifiServer.begin();
}

void loop() {

  WiFiClient client = wifiServer.available();

  if (client) {

    while (client.connected()) {

      while (client.available()>0) {

      Serial.print("incoming :");
      int size;
      while ((size = client.available()) > 0) {
        uint8_t* msg = (uint8_t*)malloc(size);
        size = client.read(msg, size);
        Serial.write(msg, size);

        if ( memcmp(msg, "RELAY-SET-255,1,1", 17) == 0 ) {Serial.write("RELAY-SET-255,1,1,OK");pcf8574_S.digitalWrite(P0,HIGH);client.write("RELAY-SET-255,1,1,OK");}
        if ( memcmp(msg, "RELAY-SET-255,1,0", 17) == 0 ) {Serial.write("RELAY-SET-255,1,0,OK");pcf8574_S.digitalWrite(P0,LOW);client.write("RELAY-SET-255,1,0,OK");}

        if ( memcmp(msg, "RELAY-SET-255,2,1", 17) == 0 ) {Serial.write("RELAY-SET-255,2,1,OK");pcf8574_S.digitalWrite(P1,HIGH);client.write("RELAY-SET-255,2,1,OK");}
        if ( memcmp(msg, "RELAY-SET-255,2,0", 17) == 0 ) {Serial.write("RELAY-SET-255,2,0,OK");pcf8574_S.digitalWrite(P1,LOW);client.write("RELAY-SET-255,2,0,OK");}

        if ( memcmp(msg, "RELAY-SET-255,3,1", 17) == 0 ) {Serial.write("RELAY-SET-255,3,1,OK");pcf8574_S.digitalWrite(P2,HIGH);client.write("RELAY-SET-255,3,1,OK");}
        if ( memcmp(msg, "RELAY-SET-255,3,0", 17) == 0 ) {Serial.write("RELAY-SET-255,3,0,OK");pcf8574_S.digitalWrite(P2,LOW);client.write("RELAY-SET-255,3,0,OK");}

        if ( memcmp(msg, "RELAY-SET-255,4,1", 17) == 0 ) {Serial.write("RELAY-SET-255,4,1,OK");pcf8574_S.digitalWrite(P3,HIGH);client.write("RELAY-SET-255,4,1,OK");}
        if ( memcmp(msg, "RELAY-SET-255,4,0", 17) == 0 ) {Serial.write("RELAY-SET-255,4,0,OK");pcf8574_S.digitalWrite(P3,LOW);client.write("RELAY-SET-255,4,0,OK");}

        if ( memcmp(msg, "RELAY-SET-255,5,1", 17) == 0 ) {Serial.write("RELAY-SET-255,5,1,OK");pcf8574_S.digitalWrite(P4,HIGH);client.write("RELAY-SET-255,5,1,OK");}
        if ( memcmp(msg, "RELAY-SET-255,5,0", 17) == 0 ) {Serial.write("RELAY-SET-255,5,0,OK");pcf8574_S.digitalWrite(P4,LOW);client.write("RELAY-SET-255,5,0,OK");}
     
        if ( memcmp(msg, "RELAY-SET-255,6,1", 17) == 0 ) {Serial.write("RELAY-SET-255,6,1,OK");pcf8574_S.digitalWrite(P5,HIGH);client.write("RELAY-SET-255,6,1,OK");}
        if ( memcmp(msg, "RELAY-SET-255,6,0", 17) == 0 ) {Serial.write("RELAY-SET-255,6,0,OK");pcf8574_S.digitalWrite(P5,LOW);client.write("RELAY-SET-255,6,0,OK");}
     
        if ( memcmp(msg, "RELAY-SET-255,7,1", 17) == 0 ) {Serial.write("RELAY-SET-255,7,1,OK");pcf8574_S.digitalWrite(P6,HIGH);client.write("RELAY-SET-255,7,1,OK");}
        if ( memcmp(msg, "RELAY-SET-255,7,0", 17) == 0 ) {Serial.write("RELAY-SET-255,7,0,OK");pcf8574_S.digitalWrite(P6,LOW);client.write("RELAY-SET-255,7,0,OK");}

        if ( memcmp(msg, "RELAY-SET-255,8,1", 17) == 0 ) {Serial.write("RELAY-SET-255,8,1,OK");pcf8574_S.digitalWrite(P7,HIGH);client.write("RELAY-SET-255,8,1,OK");}
        if ( memcmp(msg, "RELAY-SET-255,8,0", 17) == 0 ) {Serial.write("RELAY-SET-255,8,0,OK");pcf8574_S.digitalWrite(P7,LOW);client.write("RELAY-SET-255,8,0,OK");}
        free(msg);
      }

     
  //    client.write(c);
      }

    // delay(10);
    }

    client.stop();
    Serial.println("Client disconnected");

  }}


Attached Files Image(s)
           
Reply
#3
do you have set the correct I2C address in your arduino IDE config file?
Reply
#4
I think so,
I'm using for outputs.

PCF8574 pcf8574_S(0x24);
Reply
#5
(05-07-2022, 02:56 AM)Hector_Lozano Wrote: I think so,
I'm using for outputs.

PCF8574 pcf8574_S(0x24);
These two lines of code are modified into the following:

//Salidas -OUTPUTS

PCF8574 pcf8574_S(0x24,4,5);

//Entradas -INPUTS
PCF8574 pcf8574(0x22,4,5);
Reply
#6
(05-07-2022, 02:56 AM)Hector_Lozano Wrote: I think so,
I'm using for outputs.

PCF8574 pcf8574_S(0x24);

That's right, I modified


Attached Files Image(s)
   
Reply
#7
(05-07-2022, 03:24 AM)Hector_Lozano Wrote:
(05-07-2022, 02:56 AM)Hector_Lozano Wrote: I think so,
I'm using for outputs.

PCF8574 pcf8574_S(0x24);

That's right, I modified

you should set the A8 to MQTT mode    i think now your code is use TCP mode 
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)