Posts: 6,266
Threads: 806
Joined: Oct 2020
Reputation:
152
05-04-2022, 11:40 AM
(This post was last modified: 09-12-2022, 02:21 AM by admin .)
use for "KBOX" phone app in local network , without internet.
KBOX.zip (Size: 837 bytes / Downloads: 312)
Posts: 3
Threads: 0
Joined: Apr 2022
Reputation:
0
05-07-2022, 02:36 AM
(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)
Posts: 6,266
Threads: 806
Joined: Oct 2020
Reputation:
152
do you have set the correct I2C address in your arduino IDE config file?
Posts: 3
Threads: 0
Joined: Apr 2022
Reputation:
0
I think so,
I'm using for outputs.
PCF8574 pcf8574_S(0x24);
Posts: 291
Threads: 234
Joined: Jan 2021
(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);
Posts: 3
Threads: 0
Joined: Apr 2022
Reputation:
0
(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)
Posts: 291
Threads: 234
Joined: Jan 2021
(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