Hi again
Is it possible to add multiple separated things on a single device (ex:esp8266) instead of grouping them all?
The following images describe exactly what I want:
Active case:
Admirable one:
I’m pretty sure that this can be done by giving things different URLs like this: Ip/things/LED Ip/things/DISTANCE etc, but I don’t know how to do it.
I’ve checked out one of the suggested posts during the creation of this post titled “Multiple things on Arduino”, and edited it to fit my needs. The sketch is as follows:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <Thing.h>
#include <WebThingAdapter.h>
const char *ssid = "*=* dP *=*";
const char *password = "djfa1953";
#if defined(LED_BUILTIN)
const int ledPin = LED_BUILTIN;
#else
const int ledPin = 13; // manually configure LED pin
#endif
WebThingAdapter *adapter;
const char *ledTypes[] = {"Light", nullptr};
ThingDevice led1("led1", "Built-in LED 1", ledTypes);
ThingDevice led2("led2", "Built-in LED 2", ledTypes);
ThingProperty ledOn1("on", "", BOOLEAN, "OnOffProperty");
ThingProperty ledOn2("on", "", BOOLEAN, "OnOffProperty");
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xFB, 0x80 };
IPAddress ip(192, 168, 0, 100);
bool lastOn = false;
void setup(void) {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
adapter = new WebThingAdapter("w25", WiFi.localIP());
led1.addProperty(&ledOn1);
led2.addProperty(&ledOn2);
adapter->addDevice(&led1);
adapter->addDevice(&led2);
adapter->begin();
Serial.println("HTTP server started");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.print("/things/");
Serial.println(led1.id);
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.print("/things/");
Serial.println(led2.id);
}
void loop(void) {
adapter->update();
bool on = ledOn1.getValue().boolean;
digitalWrite(ledPin, on ? LOW : HIGH); // active low led
if (on != lastOn) {
Serial.print(led1.id);
Serial.print(": ");
Serial.println(on);
}
lastOn = on;
}
Am I on the right way?
I hope my question is clear enough.
Thanks in advance.
Nas