// Code generated by Arduino IoT Cloud
#include <HardwareSerial.h>
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
const char DEVICE_LOGIN_NAME[] = "40d9a694-4740-4c81-a144-08493b8ab29d";
const char SSID[] = "Wokwi-GUEST";
const char PASS[] = "";
const char DEVICE_KEY[] = "rqlDIuNXJ9mM6DjRMgRRt!qjz";
void onDataChange();
void onPotChange();
void onSrvChange();
void onLdChange();
void onSwChange();
HardwareSerial Serialok(1);
String data;
int pot;
int srv, srv1;
bool ld, ld1;
bool sw;
void initProperties() {
ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
ArduinoCloud.addProperty(data, READWRITE, ON_CHANGE, onDataChange);
ArduinoCloud.addProperty(pot, READWRITE, ON_CHANGE, onPotChange);
ArduinoCloud.addProperty(srv, READWRITE, ON_CHANGE, onSrvChange);
ArduinoCloud.addProperty(ld, READWRITE, ON_CHANGE, onLdChange);
ArduinoCloud.addProperty(sw, READWRITE, ON_CHANGE, onSwChange);
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
void setup() {
Serial.begin(9600);
Serialok.begin(9600, SERIAL_8N1, 4, 2);
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
if (ld != ld1) {
Serial.print("b");
Serial.println(ld);
Serialok.print("b");
Serialok.println(ld);
data = "b" + String(ld);
}
ld1 = ld;
if (srv != srv1) {
Serial.print("d");
Serial.println(srv);
Serialok.print("d");
Serialok.println(srv);
data = "d" + String(srv);
}
srv1 = srv;
if (Serialok.available()) {
char awal = Serialok.read();
int nilai = Serialok.parseInt();
if (Serialok.read() == char(13)) {
if (awal == 'a') sw = nilai;
if (awal == 'c') pot = nilai;
data = awal + String(nilai);
}
}
}
void onDataChange() {
}
void onPotChange() {
}
void onSrvChange() {
}
void onLdChange() {
}
void onSwChange() {
}
4<------
2------>
Arduino
TX/RX<---> PC