top of page
Sensorflow
K6a4aIRll5uIFCyEE
Product Dashboard
Product Name
Device
Product Type
Software
Product ID
5hbhGHBJHDVGJ51
Product Info
Heading 5
Properties/ Schema
Check
Product Firmware
Your content has been submitted
An error occurred. Try again later
Production
Device Name
User ID
Lastseen
Device
5hbhGHBJHDVGJ51
Device
5hbhGHBJHDVGJ51
Device
5hbhGHBJHDVGJ51
Device
5hbhGHBJHDVGJ51
Device
5hbhGHBJHDVGJ51
Device
5hbhGHBJHDVGJ51
Device
5hbhGHBJHDVGJ51
Device
5hbhGHBJHDVGJ51
Device
5hbhGHBJHDVGJ51
Device
5hbhGHBJHDVGJ51
Device
5hbhGHBJHDVGJ51
Device
5hbhGHBJHDVGJ51
Device
5hbhGHBJHDVGJ51
Device
5hbhGHBJHDVGJ51
#include
#include
#include
#include
//#include
BluetoothSerial HyperwisorBT;
Preferences preferences;
#define CH_1 23
#define CH_2 22
#define CH_3 19
#define CH_4 18
#define CH_5 5
#define CH_6 4
#define CH_7 32
#define CH_8 33
#define CH_9 26
#define CH_10 27
#define CH_11 14
#define CH_12 12
#define buzz 2
String NAME = "
";
String header;
String apikey;
String userid;
String deviceid;
String ssid;
String pass;
String E_CH1;
String E_CH2;
String E_CH3;
String E_CH4;
String E_CH5;
String E_CH6;
String E_CH7;
String E_CH8;
String E_CH9;
String E_CH10;
String E_CH11;
String E_CH12;
String E_delay;
int restartcountdoun = 0;
HYPERWISOR_IOT HyperwisorPLC;
void setup() {
Serial.begin(115200);
initializePins();
makelowPins();
preferences.begin("my-app", false);
apikey = preferences.getString("apikey");
userid = preferences.getString("userid");
deviceid = preferences.getString("deviceid");
ssid = preferences.getString("ssid");
pass = preferences.getString("pass");
HyperwisorPLC.init(apikey);
Serial.println(apikey);
Serial.println(userid);
Serial.println(ssid);
Serial.println(pass);
E_CH1 = preferences.getString("PCH1");
E_CH2 = preferences.getString("PCH2");
E_CH3 = preferences.getString("PCH3");
E_CH4 = preferences.getString("PCH4");
E_CH5 = preferences.getString("PCH5");
E_CH6 = preferences.getString("PCH6");
E_CH7 = preferences.getString("PCH7");
E_CH8 = preferences.getString("PCH8");
E_CH9 = preferences.getString("PCH9");
E_CH10 = preferences.getString("PCH10");
E_CH11 = preferences.getString("PCH11");
E_CH12 = preferences.getString("PCH12");
E_delay = preferences.getString("Pdelay");
Serial.println(E_CH1);
Serial.println(E_CH2);
Serial.println(E_CH3);
Serial.println(E_CH4);
Serial.println(E_CH5);
Serial.println(E_CH6);
Serial.println(E_CH7);
Serial.println(E_CH8);
Serial.println(E_CH9);
Serial.println(E_CH10);
Serial.println(E_CH11);
Serial.println(E_CH12);
WiFi.disconnect();
delay(50);
WiFi.setHostname(NAME.c_str());
WiFi.begin(ssid.c_str(), pass.c_str());
delay(1000);
Serial.println("connected to");
Serial.println(ssid);
Serial.println(pass);
Serial.println(WiFi.localIP());
digitalWrite(buzz, HIGH);
delay(2000);
digitalWrite(buzz, LOW);
delay(100);
changestate();
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
String jsonobj = HyperwisorPLC.get_ch_status();
char json[1512];
String payload = jsonobj;
Serial.println(payload);
int leng = payload.length();
String newpayload = payload.substring(1, leng - 1);
newpayload.replace(" ", "");
newpayload.replace("\n", "");
newpayload.trim();
newpayload.remove(0, 10);
newpayload.toCharArray(json, 1512);
StaticJsonDocument jsonDoc;
DeserializationError error = deserializeJson(jsonDoc, newpayload);
if (error) {
Serial.print("deserializeJson() failed: ");
Serial.println(error.c_str());
return;
}
// Serial.println(deviceid);
// Serial.println(newpayload);
String S_CH1 = jsonDoc["ch1"];
String S_CH2 = jsonDoc["ch2"];
String S_CH3 = jsonDoc["ch3"];
String S_CH4 = jsonDoc["ch4"];
String S_CH5 = jsonDoc["ch5"];
String S_CH6 = jsonDoc["ch6"];
String S_CH7 = jsonDoc["ch7"];
String S_CH8 = jsonDoc["ch8"];
String S_CH9 = jsonDoc["ch9"];
String S_CH10 = jsonDoc["ch10"];
String S_CH11 = jsonDoc["ch11"];
String S_CH12 = jsonDoc["ch12"];
String S_delay = jsonDoc["delay"];
delay(S_delay.toInt());
Serial.println(S_delay);
// String S_CH1 = HyperwisorPLC.extractor(jsonobj, "ch1");
// String S_CH2 = HyperwisorPLC.extractor(jsonobj, "ch2");
// String S_CH3 = HyperwisorPLC.extractor(jsonobj, "ch3");
// String S_CH4 = HyperwisorPLC.extractor(jsonobj, "ch4");
// String S_CH5 = HyperwisorPLC.extractor(jsonobj, "ch5");
// String S_CH6 = HyperwisorPLC.extractor(jsonobj, "ch6");
// String S_CH7 = HyperwisorPLC.extractor(jsonobj, "ch7");
// String S_CH8 = HyperwisorPLC.extractor(jsonobj, "ch8");
// String S_CH9 = HyperwisorPLC.extractor(jsonobj, "ch9");
// String S_CH10 = HyperwisorPLC.extractor(jsonobj, "ch10");
// String S_CH11 = HyperwisorPLC.extractor(jsonobj, "ch11");
// String S_CH12 = HyperwisorPLC.extractor(jsonobj, "ch12");
// Serial.println(S_CH1);
// Serial.println(S_CH2);
// Serial.println(S_CH3);
// Serial.println(S_CH4);
// Serial.println(S_CH5);
// Serial.println(S_CH6);
// Serial.println(S_CH7);
// Serial.println(S_CH8);
// Serial.println(S_CH9);
// Serial.println(S_CH10);
// Serial.println(S_CH11);
// Serial.println(S_CH12);
delay(100);
E_CH1 = preferences.getString("PCH1");
E_CH2 = preferences.getString("PCH2");
E_CH3 = preferences.getString("PCH3");
E_CH4 = preferences.getString("PCH4");
E_CH5 = preferences.getString("PCH5");
E_CH6 = preferences.getString("PCH6");
E_CH7 = preferences.getString("PCH7");
E_CH8 = preferences.getString("PCH8");
E_CH9 = preferences.getString("PCH9");
E_CH10 = preferences.getString("PCH10");
E_CH11 = preferences.getString("PCH11");
E_CH12 = preferences.getString("PCH12");
//E_delay = preferences.getString("Pdelay");
if (E_CH1 != S_CH1) {
preferences.putString("PCH1", S_CH1);
delay(10);
changestate();
Serial.println("updated1" + S_CH1);
} else {
Serial.println(E_CH1);
}
if (E_CH2 != S_CH2) {
preferences.putString("PCH2", S_CH2);
delay(10);
changestate();
Serial.println("updated2" + S_CH2);
} else {
Serial.println(E_CH2);
}
if (E_CH3 != S_CH3) {
preferences.putString("PCH3", S_CH3);
delay(10);
changestate();
Serial.println("updated3" + S_CH3);
} else {
Serial.println(E_CH3);
}
if (E_CH4 != S_CH4) {
preferences.putString("PCH4", S_CH4);
delay(10);
changestate();
Serial.println("updated4" + S_CH4);
} else {
Serial.println(E_CH4);
}
if (E_CH5 != S_CH5) {
preferences.putString("PCH5", S_CH5);
delay(10);
changestate();
Serial.println("updated5" + S_CH5);
} else {
Serial.println(E_CH5);
}
if (E_CH6 != S_CH6) {
preferences.putString("PCH6", S_CH6);
delay(10);
changestate();
Serial.println("updated6" + S_CH6);
} else {
Serial.println(E_CH6);
}
if (E_CH7 != S_CH7) {
preferences.putString("PCH7", S_CH7);
delay(10);
changestate();
Serial.println("updated7" + S_CH7);
} else {
Serial.println(E_CH7);
}
if (E_CH8 != S_CH8) {
preferences.putString("PCH8", S_CH8);
delay(10);
changestate();
Serial.println("updated8" + S_CH8);
} else {
Serial.println(E_CH8);
}
if (E_CH9 != S_CH9) {
preferences.putString("PCH9", S_CH9);
delay(10);
changestate();
Serial.println("updated9" + S_CH9);
} else {
Serial.println(E_CH9);
}
if (E_CH10 != S_CH10) {
preferences.putString("PCH10", S_CH10);
delay(10);
changestate();
Serial.println("updated10" + S_CH10);
} else {
Serial.println(E_CH10);
}
if (E_CH11 != S_CH11) {
preferences.putString("PCH11", S_CH11);
delay(10);
changestate();
Serial.println("updated11" + S_CH11);
} else {
Serial.println(E_CH11);
}
if (E_CH12 != S_CH12) {
preferences.putString("PCH12", S_CH12);
delay(10);
changestate();
Serial.println("updated12" + S_CH12);
} else {
Serial.println(E_CH12);
}
} else {
startBT();
}
}
void initializePins() {
pinMode(CH_1, OUTPUT);
pinMode(CH_2, OUTPUT);
pinMode(CH_3, OUTPUT);
pinMode(CH_4, OUTPUT);
pinMode(CH_5, OUTPUT);
pinMode(CH_6, OUTPUT);
pinMode(CH_7, OUTPUT);
pinMode(CH_8, OUTPUT);
pinMode(CH_9, OUTPUT);
pinMode(CH_10, OUTPUT);
pinMode(CH_11, OUTPUT);
pinMode(CH_12, OUTPUT);
pinMode(buzz, OUTPUT);
}
void makelowPins() {
digitalWrite(CH_1, LOW);
digitalWrite(CH_2, LOW);
digitalWrite(CH_3, LOW);
digitalWrite(CH_4, LOW);
digitalWrite(CH_5, LOW);
digitalWrite(CH_6, LOW);
digitalWrite(CH_7, LOW);
digitalWrite(CH_8, LOW);
digitalWrite(CH_9, LOW);
digitalWrite(CH_10, LOW);
digitalWrite(CH_11, LOW);
digitalWrite(CH_12, LOW);
digitalWrite(buzz, LOW);
}
void changestate() {
Serial.println("CHANGE STATE");
E_CH1 = preferences.getString("PCH1");
E_CH2 = preferences.getString("PCH2");
E_CH3 = preferences.getString("PCH3");
E_CH4 = preferences.getString("PCH4");
E_CH5 = preferences.getString("PCH5");
E_CH6 = preferences.getString("PCH6");
E_CH7 = preferences.getString("PCH7");
E_CH8 = preferences.getString("PCH8");
E_CH9 = preferences.getString("PCH9");
E_CH10 = preferences.getString("PCH10");
E_CH11 = preferences.getString("PCH11");
E_CH12 = preferences.getString("PCH12");
if (E_CH1 == "0") {
digitalWrite(CH_1, LOW);
} else {
//analogWrite(CH_1, E_CH1.toInt());
digitalWrite(CH_1, HIGH);
}
delay(10);
if (E_CH2 == "0") {
digitalWrite(CH_2, LOW);
} else if (E_CH2 != 0) {
digitalWrite(CH_2, HIGH);
//analogWrite(CH_2, E_CH2.toInt());
}
delay(10);
if (E_CH3 == "0") {
// digitalWrite(CH_3, LOW);
analogWrite(CH_3, E_CH3.toInt());
} else {
// digitalWrite(CH_3, HIGH);
analogWrite(CH_3, E_CH3.toInt());
}
delay(10);
if (E_CH4 == "0") {
//digitalWrite(CH_4, LOW);
analogWrite(CH_4, E_CH4.toInt());
} else {
//digitalWrite(CH_4, HIGH);
analogWrite(CH_4, E_CH4.toInt());
}
delay(10);
if (E_CH5 == "0") {
// digitalWrite(CH_5, LOW);
analogWrite(CH_5, E_CH5.toInt());
} else {
//digitalWrite(CH_5, HIGH);
analogWrite(CH_5, E_CH5.toInt());
}
delay(10);
if (E_CH6 == "0") {
digitalWrite(CH_6, LOW);
} else {
digitalWrite(CH_6, HIGH);
}
delay(10);
if (E_CH7 == "0") {
digitalWrite(CH_7, LOW);
//Serial.println("check 7 low : " + E_CH7);
} else {
digitalWrite(CH_7, HIGH);
// Serial.println("check 7 high : " + E_CH7);
}
delay(10);
if (E_CH8 == "0") {
digitalWrite(CH_8, LOW);
} else {
digitalWrite(CH_8, HIGH);
}
delay(10);
if (E_CH9 == "0") {
digitalWrite(CH_9, LOW);
} else {
digitalWrite(CH_9, HIGH);
}
delay(10);
if (E_CH10 == "0") {
digitalWrite(CH_10, LOW);
} else {
digitalWrite(CH_10, HIGH);
}
delay(10);
if (E_CH11 == "0") {
digitalWrite(CH_11, LOW);
} else {
digitalWrite(CH_11, HIGH);
}
delay(10);
if (E_CH12 == "0") {
digitalWrite(CH_12, LOW);
} else {
digitalWrite(CH_12, HIGH);
}
delay(10);
// Serial.println(E_CH1);
// Serial.println(E_CH2);
// Serial.println(E_CH3);
// Serial.println(E_CH4);
// Serial.println(E_CH5);
// Serial.println(E_CH6);
// Serial.println(E_CH7);
// Serial.println(E_CH8);
// Serial.println(E_CH9);
// Serial.println(E_CH10);
// Serial.println(E_CH11);
// Serial.println(E_CH12);
// Serial.println(E_CI);
// Serial.println(E_Active);
}
void startBT() {
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
HyperwisorBT.begin(NAME.c_str());
if (HyperwisorBT.available()) {
String btdata = HyperwisorBT.readString();
Serial.println(btdata);
StaticJsonDocument jsonDoc;
DeserializationError error = deserializeJson(jsonDoc, btdata);
if (error) {
Serial.print("deserializeJson() failed: ");
Serial.println(error.c_str());
return;
}
String datatype = jsonDoc["Datatype"];
if (datatype == "wifiinfo") {
Serial.println("datatype = wifiinfo");
String apikey = jsonDoc["apikey"];
String userid = jsonDoc["userid"];
String deviceid = jsonDoc["deviceid"];
String ssid = jsonDoc["ssid"];
String pass = jsonDoc["pass"];
if (ssid.length() > 0 && pass.length() > 0 && apikey.length() > 0) {
preferences.putString("apikey", apikey);
preferences.putString("userid", userid);
preferences.putString("deviceid", deviceid);
preferences.putString("ssid", ssid);
preferences.putString("pass", pass);
preferences.putString("PCH1", "0");
preferences.putString("PCH2", "0");
preferences.putString("PCH3", "0");
preferences.putString("PCH4", "0");
preferences.putString("PCH5", "0");
preferences.putString("PCH6", "0");
preferences.putString("PCH7", "0");
preferences.putString("PCH8", "0");
preferences.putString("PCH9", "0");
preferences.putString("PCH10", "0");
preferences.putString("PCH11", "0");
preferences.putString("PCH12", "0");
Serial.println(apikey);
Serial.println(userid);
Serial.println(ssid);
Serial.println(pass);
digitalWrite(buzz, HIGH);
delay(2000);
digitalWrite(buzz, LOW);
delay(1000);
digitalWrite(buzz, HIGH);
delay(2000);
digitalWrite(buzz, LOW);
delay(1000);
ESP.restart();
}
} else if (datatype == "BTCONTROLL") {
Serial.println("datatype = BTCONTROLL");
String S_CH1 = jsonDoc["ch1"];
String S_CH2 = jsonDoc["ch2"];
String S_CH3 = jsonDoc["ch3"];
String S_CH4 = jsonDoc["ch4"];
String S_CH5 = jsonDoc["ch5"];
String S_CH6 = jsonDoc["ch6"];
String S_CH7 = jsonDoc["ch7"];
String S_CH8 = jsonDoc["ch8"];
String S_CH9 = jsonDoc["cH9"];
String S_CH10 = jsonDoc["ch10"];
String S_CH11 = jsonDoc["ch11"];
String S_CH12 = jsonDoc["ch12"];
delay(500);
Serial.println(E_CH1);
Serial.println(E_CH2);
Serial.println(E_CH3);
Serial.println(E_CH4);
Serial.println(E_CH5);
Serial.println(E_CH6);
Serial.println(E_CH7);
Serial.println(E_CH8);
Serial.println(E_CH9);
Serial.println(E_CH10);
Serial.println(E_CH11);
Serial.println(E_CH12);
if (E_CH1 != S_CH1) {
preferences.putString("PCH1", S_CH1);
Serial.println("updated1" + S_CH1);
changestate();
} else {
Serial.println(E_CH1);
}
if (E_CH2 != S_CH2) {
preferences.putString("PCH2", S_CH2);
Serial.println("updated2" + S_CH2);
changestate();
} else {
Serial.println(E_CH2);
}
if (E_CH3 != S_CH3) {
preferences.putString("PCH3", S_CH3);
Serial.println("updated3" + S_CH3);
changestate();
} else {
Serial.println(E_CH3);
}
if (E_CH4 != S_CH4) {
preferences.putString("PCH4", S_CH4);
Serial.println("updated4" + S_CH4);
changestate();
} else {
Serial.println(E_CH4);
}
if (E_CH5 != S_CH5) {
preferences.putString("PCH5", S_CH5);
Serial.println("updated5" + S_CH5);
changestate();
} else {
Serial.println(E_CH5);
}
if (E_CH6 != S_CH6) {
preferences.putString("PCH6", S_CH6);
Serial.println("updated6" + S_CH6);
changestate();
} else {
Serial.println(E_CH6);
}
if (E_CH7 != S_CH7) {
preferences.putString("PCH7", S_CH7);
Serial.println("updated7" + S_CH7);
changestate();
} else {
Serial.println(E_CH7);
}
if (E_CH8 != S_CH8) {
preferences.putString("PCH8", S_CH8);
Serial.println("updated8" + S_CH8);
changestate();
} else {
Serial.println(E_CH8);
}
if (E_CH9 != S_CH9) {
preferences.putString("PCH9", S_CH9);
Serial.println("updated9" + S_CH9);
changestate();
} else {
Serial.println(E_CH9);
}
if (E_CH10 != S_CH10) {
preferences.putString("PCH10", S_CH10);
Serial.println("updated10" + S_CH10);
changestate();
} else {
Serial.println(E_CH10);
}
if (E_CH11 != S_CH11) {
preferences.putString("PCH11", S_CH11);
Serial.println("updated11" + S_CH11);
changestate();
} else {
Serial.println(E_CH11);
}
if (E_CH12 != S_CH12) {
preferences.putString("PCH12", S_CH12);
Serial.println("updated12" + S_CH12);
changestate();
} else {
Serial.println(E_CH12);
}
} else if (datatype == "wifiupdate") {
String Nssid = jsonDoc["ssid"];
String Npass = jsonDoc["pass"];
preferences.putString("ssid", Nssid);
preferences.putString("pass", Npass);
Serial.println("wifiinfoupdated");
digitalWrite(buzz, HIGH);
delay(5000);
digitalWrite(buzz, LOW);
delay(10);
ESP.restart();
} else if (datatype == "RESTART") {
ESP.restart();
}
} else {
Serial.println("NOT RECIVED");
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
WiFi.setHostname(NAME.c_str());
WiFi.begin(ssid.c_str(), pass.c_str());
delay(500);
//server.begin();
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
restartcountdoun++;
if (restartcountdoun == 500) {
ESP.restart();
}
}
}
Collapsible text is great for longer section titles and descriptions. It gives people access to all the info they need, while keeping your layout clean. Link your text to anything, or set your text box to expand on click. Write your text here...
bottom of page