• Stars
    star
    204
  • Rank 192,063 (Top 4 %)
  • Language
    C++
  • License
    Mozilla Public Li...
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple server for ESP8266, ESP32, Ethernet, or WiFi101-compatible boards compliant with Mozilla's proposed WoT API

Gitpod ready-to-code

webthing-arduino

A simple server for the ESP8266, the ESP32, boards with Ethernet, or any WiFi101-compatible board that implements Mozilla's proposed Web of Things API. The LED example exposes an OnOffSwitch named "Built-in LED" which controls the board's built-in LED. The LED Lamp example 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 and how to set up for an ESP32. You will also need to download the ESP Async WebServer library and unpack it in your sketchbook's libraries folder.

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.

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

Next, download this library from the same library manager by searching for webthing.

add zip library and LED example

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.

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.

PlatformIO

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.

Example

#include <Arduino.h>
#include "Thing.h"
#include "WebThingAdapter.h"

// TODO: Hardcode your wifi credentials here (and keep it private)
const char *ssid = "public";
const char *password = "";

#if defined(LED_BUILTIN)
const int ledPin = LED_BUILTIN;
#else
const int ledPin = 13; // manually configure LED pin
#endif

WebThingAdapter *adapter;

const char *ledTypes[] = {"OnOffSwitch", "Light", nullptr};
ThingDevice led("led", "Built-in LED", ledTypes);
ThingProperty ledOn("on", "", BOOLEAN, "OnOffProperty");

bool lastOn = false;

void setup(void) {
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, 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
  bool blink = true;
  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

  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  adapter = new WebThingAdapter("w25", WiFi.localIP());

  led.addProperty(&ledOn);
  adapter->addDevice(&led);
  adapter->begin();
  Serial.println("HTTP server started");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.print("/things/");
  Serial.println(led.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;
}

Configuration

  • If you have a complex device with large thing descriptions, you may need to increase the size of the JSON buffers. The buffer sizes are configurable as such:

    // By default, buffers are 256 bytes for small documents, 1024 for larger ones
    
    // To use a pre-defined set of larger JSON buffers (4x larger)
    #define LARGE_JSON_BUFFERS 1
    
    // Else, you can define your own size
    #define SMALL_JSON_DOCUMENT_SIZE <something>
    #define LARGE_JSON_DOCUMENT_SIZE <something>
    
    #include <Thing.h>
    #include <WebThingAdapter.h>

Adding to Gateway

To add your web thing to the WebThings Gateway, install the "Web Thing" add-on and follow the instructions here.

More Repositories

1

gateway

WebThings Gateway
TypeScript
2,599
star
2

wiki

Developer Wiki
Shell
291
star
3

webthing-node

Node.js implementation of a Web Thing server
TypeScript
232
star
4

webthing-rust

Rust implementation of a Web Thing server
Rust
206
star
5

webthing-python

Python implementation of a Web Thing server
Python
177
star
6

api

Web Thing API Specification
HTML
164
star
7

registration_server

The registration server for WebThings Gateway.
Rust
78
star
8

addon-list

List of installable add-ons for WebThings Gateway
Python
77
star
9

gateway-docker

Legacy docker image for WebThings Gateway - now moved to main gateway repo at https://github.com/WebThingsIO/gateway
Dockerfile
71
star
10

webthing-java

Java implementation of a Web Thing server
Java
51
star
11

webthing-upy

MicroPython implementation of a Web Thing server
Python
50
star
12

zigbee-adapter

Zigbee adapter add-on for WebThings Gateway
JavaScript
46
star
13

example-adapter

Example adapter add-on for WebThings Gateway
JavaScript
34
star
14

homekit-adapter

HomeKit device adapter for WebThings Gateway
JavaScript
22
star
15

thing-url-adapter

Proxy adapter for Web Thing API endpoints
JavaScript
22
star
16

philips-hue-adapter

WebThings Gateway Philips Hue Adapter
TypeScript
21
star
17

mozilla-iot.github.io

Mozilla IoT Website
SCSS
20
star
18

curl-examples

Examples of using the gateway API using curl
Shell
19
star
19

gateway-addon-python

Python bindings for developing add-ons for WebThings Gateway
Python
16
star
20

zwave-adapter

Z-Wave adapter add-on for WebThings Gateway
JavaScript
15
star
21

tplink-adapter

TP-Link Kasa smart plug/bulb adapter for WebThings Gateway
Python
15
star
22

gateway-addon-node

Node bindings for developing add-ons for WebThings Gateway
TypeScript
13
star
23

virtual-things-adapter

WebThings Gateway Virtual Things Adapter for experimenting with new thing types
JavaScript
12
star
24

onvif-adapter

ONVIF Profile S video camera adapter
JavaScript
10
star
25

voice-addon

Voice control add-on for WebThings Gateway
JavaScript
8
star
26

yeelight-adapter

Yeelight device adapter for WebThings Gateway
JavaScript
7
star
27

weather-adapter

Weather adapter for WebThings Gateway
JavaScript
7
star
28

lg-tv-adapter

LG webOS TV adapter for WebThings Gateway
JavaScript
7
star
29

serial-adapter

WebThings Gateway adapter for talking to serial-mcu based software through a serial port.
JavaScript
7
star
30

deconz-api

Talk to Zigbee devices using ConBee dongle or RaspBee HAT, modelled after xbee-api
JavaScript
7
star
31

gateway-deb

Debian package for running WebThings Gateway
Shell
6
star
32

things-controller

Things Controller
Java
6
star
33

roku-adapter

Roku adapter
JavaScript
6
star
34

mozgateway-alexa-skill

Alexa Skill to interact with Mozilla WebThings Gateway
Python
6
star
35

rpi-image-builder

Builds gate files needed to create a Raspberry Pi image
Shell
6
star
36

intent-parser

Intent Parser for the Mozilla WebThings Gateway
Python
5
star
37

schemas

A Web of Things schema repository
HTML
5
star
38

zigbee-zdo

Module for parsing and building Zigbee ZDO frames for use with xbee-api or deconz-api
JavaScript
5
star
39

android-app

A Web of Things client for Android
Kotlin
5
star
40

gpio-adapter

GPIO adapter add-on for WebThings Gateway
JavaScript
5
star
41

gateway-addon-ipc-schema

JSON-Schema for add-on IPC messages
Python
5
star
42

meross-adapter

Meross smart device adapter for WebThings Gateway
Python
4
star
43

webthing-tester

Web Thing test script
Python
4
star
44

tapo-adapter

TP-Link Tapo smart plug adapter for WebThings Gateway
Python
4
star
45

tunnelclient-rs

A Rust client library for the DNS/pagekite tunnel
Rust
4
star
46

node-mozilla-iot-gateway

gateway package for OpenWRT
Makefile
3
star
47

serial-mcu

MCU side code which talks with the serial-adapter
C++
3
star
48

registration-server-docker

Docker image for WebThingsIO/registration_server
Dockerfile
3
star
49

twilio-adapter

Simple adapter exposing the texting part of the Twilio API to the WebThings Gateway
JavaScript
3
star
50

sengled-adapter

Sengled Wi-Fi smart bulb adapter for WebThings Gateway
Python
3
star
51

wake-on-lan-adapter

Wake-on-LAN adapter for WebThings gateway.
JavaScript
3
star
52

email-sender-adapter

Simple SMTP-based email sending adapter for the WebThings Gateway
JavaScript
3
star
53

crateway

Rust
3
star
54

gateway-package-turris-omnia

WebThings gateway package for theTurris Omnia
Makefile
2
star
55

le-store-certbot

Mozilla IoT's fork of le-store-certbot
JavaScript
2
star
56

device-compat

Hardware compatibility data for WebThings Gateway
JavaScript
2
star
57

cli

Command line tools for working with things
Python
2
star
58

wot-adapter

Proxy adapter for W3C compliant WoT devices
TypeScript
2
star
59

gateway-ipc-types-rust

Rust
2
star
60

pulse-adapter

Adapter which can create pulse devices.
JavaScript
2
star
61

le-challenge-dns

Mozilla's iot fork of le-challenge-dns to issue certificates automatically
JavaScript
2
star
62

example-extension

Example extension add-on for WebThings Gateway
JavaScript
2
star
63

http-on-off-wifi101

Simple HTTP server which turns an LED on or off
C++
2
star
64

gotify-notifier

Simple notifier which uses a self-hosted Gotify server.
JavaScript
2
star
65

things-browser

Things Browser
1
star
66

webthingsio.github.io

HTML
1
star
67

webhook-events

JavaScript
1
star
68

scene-control-adapter

WebThings Gateway add-on to emulate scenes
JavaScript
1
star
69

earthquake-monitor-adapter

Earthquake monitor for WebThings Gateway
Python
1
star
70

tide-calendar-adapter

Tide calendar for WebThings Gateway
Python
1
star
71

mailchimp-proxy

Python
1
star
72

speed-test-adapter

Internet speed test adapter for WebThings Gateway
Python
1
star
73

gateway-package-docker

Docker images for creating the gateway .ipk files for OpenWRT
Dockerfile
1
star
74

example-notifier

Example notifier add-on for WebThings Gateway
JavaScript
1
star
75

eufy-adapter

Eufy smart plug/bulb adapter for WebThings Gateway
Python
1
star
76

etekcity-adapter

Etekcity smart plug/switch adapter for WebThings Gateway
Python
1
star
77

xctu-logdump

Parses an XCTU log file
JavaScript
1
star
78

gateway-aur

AUR package for running WebThings Gateway
Shell
1
star