From 088de47ede70f08da8aa9415f116c6c07c24ad69 Mon Sep 17 00:00:00 2001 From: Citrullin Date: Wed, 29 Sep 2021 14:44:12 +0200 Subject: [PATCH 1/5] Remove webthings in context --- Thing.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Thing.h b/Thing.h index 54ce5af..5219b38 100644 --- a/Thing.h +++ b/Thing.h @@ -559,7 +559,6 @@ class ThingDevice { descr["title"] = this->title; JsonArray context = descr.createNestedArray("@context"); context.add("https://www.w3.org./2019/wot/td/v1"); - context.add("https://webthings.io/schemas"); if (this->description != "") { descr["description"] = this->description; From ba0fb0c9901e3f237e2af98fb1f8872d5ca9edce Mon Sep 17 00:00:00 2001 From: Citrullin Date: Thu, 7 Oct 2021 15:39:32 +0200 Subject: [PATCH 2/5] Readme update --- README.md | 91 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 7c306d0..b907c84 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,13 @@ webthing-arduino ================ -A simple server for the ESP8266, the ESP32, boards with Ethernet, or any +A simple Web of Things Thing Description compatible library, for the ESP32. +Available examples +- [BME280](/examples/BME280) +- [LED](/examples/LED) +- [OLED display](/examples/TextDisplay) + +A simple server for ESP32, boards with Ethernet, or any WiFi101-compatible board that implements Mozilla's proposed Web of Things API. The [LED example](https://github.com/WebThingsIO/webthing-arduino/blob/master/examples/LED) @@ -12,25 +18,12 @@ LED. The [LED Lamp example](https://github.com/WebThingsIO/webthing-arduino/blob/master/examples/LEDLamp) ups the ante by introducing a `level` property to expose a dimmable Light. -## Arduino - -### ESP8266 or ESP32 - -To run on either of these boards, download the Arduino IDE and set it up for -board-specific development. These Adafruit guides explain [how to set up for an -ESP8266](https://learn.adafruit.com/adafruit-feather-huzzah-esp8266/using-arduino-ide) -and [how to set up for an -ESP32](https://learn.adafruit.com/adafruit-huzzah32-esp32-feather/using-with-arduino-ide). -You will also need to download the [ESP Async -WebServer](https://github.com/me-no-dev/ESPAsyncWebServer/) library and unpack -it in your sketchbook's libraries folder. +## Installation -### MKR1000, MKR1010, etc. - -* MKR1000 (and similar): Install the WiFi101 library from the Arduino library - manager. -* MKR1010 (and similar): Install the WiFiNINA library from the Arduino library - manager. +1. Download and install [ArduinoJSON](https://arduinojson.org/v6/doc/installation/) +1. Download and install [ESP Async WebServer](https://github.com/me-no-dev/ESPAsyncWebServer/) +1. Download the code as ZIP file `Code -> Download ZIP` +2. Install the library in the Arduino IDE `Sketch -> Include Library -> Add ZIP Library...` ### Continuing onwards @@ -44,24 +37,53 @@ Next, download this library from the same library manager by searching for ![add zip library and LED example](https://github.com/WebThingsIO/webthing-arduino/raw/master/docs/add-library-open-example.png) -You should be able to upload the example sketch onto your board and use it as a -simple Web Thing. This Web Thing can be talked to using the WoT API or added to -the WebThings Gateway using the "Add Thing by URL" feature. Note that -right now, WiFi101-based Things must be manually added by typing the full URL -to the Web Thing, e.g. `http://192.168.0.103/things/led`. + +You should upload one of the example applications to your board. +The Web of Things Thing Description is available under `/.well-known/wot-thing-description`. +All available actions and properties are described in the Thing Description. If you want to create a Web Thing from scratch, make sure to include both -"Thing.h" and "WebThingAdapter.h" (or "EthernetWebThingAdapter.h", if using an -Ethernet board). You can then add Things and Properties to your board using our -proposed API. +"Thing.h" and "WebThingAdapter.h". +You can then add Actions and Properties to your board. + +**Properties** +```c++ +WebThingAdapter *adapter; + +ThingProperty weatherTemp("temperature", "", NUMBER, "TemperatureProperty"); -## PlatformIO +const char *bme280Types[] = {"TemperatureSensor", nullptr}; +ThingDevice weather("bme280", "BME280 Weather Sensor", bme280Types); -Add the `webthing-arduino` library through PlatformIO's package management -interface. Ensure that you get the latest release by examining the entries -in the version number dropdown list. It may be sorted counter-intuitively. -You may also need to manually add the ArduinoJson and other libraries to -your project. +weather.addProperty(&weatherTemp); +adapter->addDevice(&weather); + +``` + +**Actions** +```c++ +WebThingAdapter *adapter; +ThingActionObject *action_generator(DynamicJsonDocument *); + +StaticJsonDocument<256> oledInput; +JsonObject oledInputObj = oledInput.to(); +ThingAction displayAction("display", "Display text", "display a text on OLED", + "displayAction", &oledInputObj, action_generator); + +const char *displayTypes[] = {"OLED Display", nullptr}; +ThingDevice displayThing("oled", "OLED Display", displayTypes); + +oledThing.addAction(&displayAction); +adapter->addDevice(&displayThing); + +void do_display(const JsonVariant &input){ + println("Action request"); +} + +ThingActionObject *action_generator(DynamicJsonDocument *input) { + return new ThingActionObject("display", input, callback, nullptr); +} +``` ## Example @@ -162,6 +184,3 @@ void loop(void) { #include ``` -# Adding to Gateway - -To add your web thing to the WebThings Gateway, install the "Web Thing" add-on and follow the instructions [here](https://github.com/WebThingsIO/thing-url-adapter#readme). From a962e695fcd2a82645fae3a85b86685680f2a9ae Mon Sep 17 00:00:00 2001 From: Citrullin Date: Thu, 7 Oct 2021 15:40:37 +0200 Subject: [PATCH 3/5] Remove screenshots --- README.md | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/README.md b/README.md index b907c84..52c8ab7 100644 --- a/README.md +++ b/README.md @@ -25,18 +25,7 @@ ups the ante by introducing a `level` property to expose a dimmable Light. 1. Download the code as ZIP file `Code -> Download ZIP` 2. Install the library in the Arduino IDE `Sketch -> Include Library -> Add ZIP Library...` -### Continuing onwards - -Make sure to install the current release of the ArduinoJson library (6) if you -don't have it installed already. - -![ArduinoJson install process](https://github.com/WebThingsIO/webthing-arduino/raw/master/docs/arduinojson.png) - -Next, download this library from the same library manager by searching for -`webthing`. - -![add zip library and LED example](https://github.com/WebThingsIO/webthing-arduino/raw/master/docs/add-library-open-example.png) - +### Start development You should upload one of the example applications to your board. The Web of Things Thing Description is available under `/.well-known/wot-thing-description`. From 064c974665f9bb895c7867d1d25432af56bd4974 Mon Sep 17 00:00:00 2001 From: Citrullin Date: Thu, 7 Oct 2021 15:41:22 +0200 Subject: [PATCH 4/5] Remove incorrect statements --- README.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/README.md b/README.md index 52c8ab7..aa5ce80 100644 --- a/README.md +++ b/README.md @@ -9,15 +9,6 @@ Available examples - [LED](/examples/LED) - [OLED display](/examples/TextDisplay) -A simple server for ESP32, boards with Ethernet, or any -WiFi101-compatible board that implements Mozilla's proposed Web of Things API. -The [LED -example](https://github.com/WebThingsIO/webthing-arduino/blob/master/examples/LED) -exposes an OnOffSwitch named "Built-in LED" which controls the board's built-in -LED. The [LED Lamp -example](https://github.com/WebThingsIO/webthing-arduino/blob/master/examples/LEDLamp) -ups the ante by introducing a `level` property to expose a dimmable Light. - ## Installation 1. Download and install [ArduinoJSON](https://arduinojson.org/v6/doc/installation/) From 4da14e661b0922fd06ace35beccd6423c255a792 Mon Sep 17 00:00:00 2001 From: Citrullin Date: Mon, 11 Oct 2021 16:34:01 +0200 Subject: [PATCH 5/5] Add beginner tutorials to README --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index aa5ce80..89d277e 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,29 @@ Available examples - [LED](/examples/LED) - [OLED display](/examples/TextDisplay) +## Beginner Tutorials + +If you need a more extensive explanation of the usage of this library, we have some step by step tutorials available with more context. + +### WebThings Arduino + Node-WoT + +[Node-WoT](https://github.com/eclipse/thingweb.node-wot) is a Javascript client library to consume Web of Things devices. + +- [Show number of Github forks and stars on Matrix display](https://bind.systems/blog/web-of-things-github-forks-stars/) +- [Run speedtest and show results on an OLED display](https://bind.systems/blog/web-of-things-speedtest/) + +### WebThings Arduino + Node-RED + +[Node-RED](https://nodered.org/) is a drag and drop tool for connecting devices. It requires little Javascript programming knowledge. + +- [Connect temperature sensor to OLED display](https://bind.systems/blog/web-of-things-node-red-temperature-oled/) + +### WebThings Arduino + +- [Blinking LED](https://bind.systems/blog/web-of-things-led/) +- [Matrix display](https://bind.systems/blog/web-of-things-arduino-matrix-display/) +- [OLED display](https://bind.systems/blog/web-of-things-arduino-oled/) + ## Installation 1. Download and install [ArduinoJSON](https://arduinojson.org/v6/doc/installation/)