How do I create multiple toggle switches (on/off switches) inside one thing?
I want to manage 1 device as a custom thing via the gateway and the device (esp32) transfers data to another device(esp32 again) which is part of the already setup mesh system … Please help …
//I edited the arduino example a lil bit to implement, no success
#define LARGE_JSON_BUFFERS 1
#include <Arduino.h>
#include <Thing.h>
#include <WebThingAdapter.h>
const char *ssid = ".......";
const char *password = ".......";
const int lampPin = 2;
ThingActionObject *action_generator(DynamicJsonDocument *);
WebThingAdapter *adapter;
const char *lampTypes[] = {"OnOffSwitch", "Light", nullptr};
ThingDevice lamp("urn:dev:ops:my-home", "Home", lampTypes);
ThingDevice lamptwo("urn:dev:ops:my-home", "not-home", lampTypes); //tried to implement it
ThingProperty lampOn("on", "Whether the lamp is turned on", BOOLEAN,"OnOffProperty");
ThingProperty lampTwoOn("on", "Whether the lamp is turned on", BOOLEAN,"OnOffProperty");
void setup(void) {
pinMode(lampPin, OUTPUT);
digitalWrite(lampPin, HIGH);
Serial.begin(115200);
Serial.println("");
Serial.print("Connecting to \"");
Serial.print(ssid);
Serial.println("\"");
//#if defined(ESP8266) || defined(ESP32)
WiFi.mode(WIFI_STA);
//#endif
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
adapter = new WebThingAdapter("led-lamp", WiFi.localIP());
lamp.description = "A web connected lamp";
lamptwo.description = "A web connected lamp";
lampOn.title = "On/Off";
lamp.addProperty(&lampOn);
lampTwoOn.title = "On/Off";
lamptwo.addProperty(&lampTwoOn);
//I removed the fade action because i'm currently focused on getting 2 buttons to work at least
adapter->addDevice(&lamp);
adapter->addDevice(&lamptwo);
adapter->begin();
Serial.println("HTTP server started");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.print("/things/");
Serial.println(lamp.id);
// set initial values
ThingPropertyValue initialOn = {.boolean = true};
lampOn.setValue(initialOn);
(void)lampOn.changedValueOrNull();
// set initial values for the second switch
ThingPropertyValue initialTwoOn = {.boolean = true};
lampTwoOn.setValue(initialOn);
(void)lampTwoOn.changedValueOrNull();
}
void loop(void) {
adapter->update();
bool on = lampOn.getValue().boolean;
if (on) {
//TODO: write logic as if V1 of Blynk was on
//like i want to assign the board value,pin,etc to json and send it to the other esp32
}
}