Hi,
I have a basement where I read out several sensor values (about 10) with an Arduino Mega. Until now I published the values via an Ethernet Shield to my network as a web server.
As I found WebThings, I thougt great!
But now I am struggling with multiple things from the same arduino.
Is multiple things implementet in the Arduino? Is there a documentation or better an example?
I tried just to copy the LED example, but did not get far with this. My goal was to see two things on the gateway. The first one is found, but the second (led2) returns 400.
Maybe you could give me a hint…
#define LARGE_JSON_BUFFERS 1
#define ARDUINOJSON_USE_LONG_LONG 1
#include <Arduino.h>
#include "Thing.h"
#include "EthernetWebThingAdapter.h"
#if defined(LED_BUILTIN)
const int ledPin = LED_BUILTIN;
#else
const int ledPin = 13; // manually configure LED pin
#endif
WebThingAdapter *adapter;
WebThingAdapter *adapter2;
const char *ledTypes[] = {"OnOffSwitch", "Light", nullptr};
ThingDevice led("led", "Built-in LED", ledTypes);
ThingDevice led2("led2", "Built-out LED", ledTypes);
ThingProperty ledOn("on", "", BOOLEAN, "OnOffProperty");
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xFB, 0x80 };
IPAddress ip(192, 168, 0, 100);
//EthernetServer server(80);
bool lastOn = false;
void setup(void) {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
Serial.begin(9600);
Serial.println("");
bool blink = true;
Ethernet.begin(mac, ip);
// server.begin();
Serial.print("Server gestartet. IP: ");
Serial.println(Ethernet.localIP());
// Wait for connection
// while (WiFi.status() != WL_CONNECTED) {
// delay(500);
// Serial.print(".");
// digitalWrite(ledPin, blink ? LOW : HIGH); // active low led
// blink = !blink;
// }
digitalWrite(ledPin, HIGH); // active low led
adapter = new WebThingAdapter("w25", Ethernet.localIP());
adapter2 = new WebThingAdapter("w26", Ethernet.localIP());
led.addProperty(&ledOn);
led2.addProperty(&ledOn);
adapter->addDevice(&led);
adapter2->addDevice(&led2);
adapter->begin();
adapter2->begin();
Serial.println("HTTP server started");
Serial.print("http://");
Serial.print(Ethernet.localIP());
Serial.print("/things/");
Serial.println(led.id);
Serial.println("HTTP server started");
Serial.print("http://");
Serial.print(Ethernet.localIP());
Serial.print("/things/");
Serial.println(led2.id);
}
void loop(void) {
adapter->update();
bool on = ledOn.getValue().boolean;
digitalWrite(ledPin, on ? LOW : HIGH); // active low led
if (on != lastOn) {
Serial.print(led.id);
Serial.print(": ");
Serial.println(on);
}
lastOn = on;
}