{"id":13499818,"url":"https://github.com/WebThingsIO/webthing-arduino","last_synced_at":"2025-03-29T05:32:24.651Z","repository":{"id":43773160,"uuid":"121672328","full_name":"WebThingsIO/webthing-arduino","owner":"WebThingsIO","description":"Simple server for ESP8266, ESP32, Ethernet, or WiFi101-compatible boards compliant with Mozilla's proposed WoT API","archived":false,"fork":false,"pushed_at":"2023-06-24T09:02:42.000Z","size":1228,"stargazers_count":205,"open_issues_count":19,"forks_count":82,"subscribers_count":22,"default_branch":"master","last_synced_at":"2024-05-02T06:11:34.421Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WebThingsIO.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-02-15T19:28:48.000Z","updated_at":"2024-04-02T17:40:28.000Z","dependencies_parsed_at":"2024-01-24T04:53:29.721Z","dependency_job_id":"9b0e6c70-112e-4d07-9e29-f9238b667690","html_url":"https://github.com/WebThingsIO/webthing-arduino","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebThingsIO%2Fwebthing-arduino","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebThingsIO%2Fwebthing-arduino/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebThingsIO%2Fwebthing-arduino/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebThingsIO%2Fwebthing-arduino/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebThingsIO","download_url":"https://codeload.github.com/WebThingsIO/webthing-arduino/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222465676,"owners_count":16989057,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T22:00:43.399Z","updated_at":"2024-10-31T18:31:15.887Z","avatar_url":"https://github.com/WebThingsIO.png","language":"C++","funding_links":[],"categories":["Section"],"sub_categories":["Libraries"],"readme":"[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/WebThingsIO/webthing-arduino)\n\nwebthing-arduino\n================\n\nA simple server for the ESP8266, the ESP32, boards with Ethernet, or any\nWiFi101-compatible board that implements Mozilla's proposed Web of Things API.\nThe [LED\nexample](https://github.com/WebThingsIO/webthing-arduino/blob/master/examples/LED)\nexposes an OnOffSwitch named \"Built-in LED\" which controls the board's built-in\nLED. The [LED Lamp\nexample](https://github.com/WebThingsIO/webthing-arduino/blob/master/examples/LEDLamp)\nups the ante by introducing a `level` property to expose a dimmable Light.\n\n## Arduino\n\n### ESP8266 or ESP32\n\nTo run on either of these boards, download the Arduino IDE and set it up for\nboard-specific development. These Adafruit guides explain [how to set up for an\nESP8266](https://learn.adafruit.com/adafruit-feather-huzzah-esp8266/using-arduino-ide)\nand [how to set up for an\nESP32](https://learn.adafruit.com/adafruit-huzzah32-esp32-feather/using-with-arduino-ide).\nYou will also need to download the [ESP Async\nWebServer](https://github.com/me-no-dev/ESPAsyncWebServer/) library and unpack\nit in your sketchbook's libraries folder.\n\n### MKR1000, MKR1010, etc.\n\n* MKR1000 (and similar): Install the WiFi101 library from the Arduino library\n  manager.\n* MKR1010 (and similar): Install the WiFiNINA library from the Arduino library\n  manager.\n\n### Continuing onwards\n\nMake sure to install the current release of the ArduinoJson library (6) if you\ndon't have it installed already.\n\n![ArduinoJson install process](https://github.com/WebThingsIO/webthing-arduino/raw/master/docs/arduinojson.png)\n\nNext, download this library from the same library manager by searching for\n`webthing`.\n\n![add zip library and LED example](https://github.com/WebThingsIO/webthing-arduino/raw/master/docs/add-library-open-example.png)\n\nYou should be able to upload the example sketch onto your board and use it as a\nsimple Web Thing. This Web Thing can be talked to using the WoT API or added to\nthe WebThings Gateway using the \"Add Thing by URL\" feature. Note that\nright now, WiFi101-based Things must be manually added by typing the full URL\nto the Web Thing, e.g. `http://192.168.0.103/things/led`.\n\nIf you want to create a Web Thing from scratch, make sure to include both\n\"Thing.h\" and \"WebThingAdapter.h\" (or \"EthernetWebThingAdapter.h\", if using an\nEthernet board). You can then add Things and Properties to your board using our\nproposed API.\n\n## PlatformIO\n\nAdd the `webthing-arduino` library through PlatformIO's package management\ninterface. Ensure that you get the latest release by examining the entries\nin the version number dropdown list. It may be sorted counter-intuitively.\nYou may also need to manually add the ArduinoJson and other libraries to \nyour project.\n\n## Example\n\n```c++\n#include \u003cArduino.h\u003e\n#include \"Thing.h\"\n#include \"WebThingAdapter.h\"\n\n// TODO: Hardcode your wifi credentials here (and keep it private)\nconst char *ssid = \"public\";\nconst char *password = \"\";\n\n#if defined(LED_BUILTIN)\nconst int ledPin = LED_BUILTIN;\n#else\nconst int ledPin = 13; // manually configure LED pin\n#endif\n\nWebThingAdapter *adapter;\n\nconst char *ledTypes[] = {\"OnOffSwitch\", \"Light\", nullptr};\nThingDevice led(\"led\", \"Built-in LED\", ledTypes);\nThingProperty ledOn(\"on\", \"\", BOOLEAN, \"OnOffProperty\");\n\nbool lastOn = false;\n\nvoid setup(void) {\n  pinMode(ledPin, OUTPUT);\n  digitalWrite(ledPin, HIGH);\n  Serial.begin(115200);\n  Serial.println(\"\");\n  Serial.print(\"Connecting to \\\"\");\n  Serial.print(ssid);\n  Serial.println(\"\\\"\");\n#if defined(ESP8266) || defined(ESP32)\n  WiFi.mode(WIFI_STA);\n#endif\n  WiFi.begin(ssid, password);\n  Serial.println(\"\");\n\n  // Wait for connection\n  bool blink = true;\n  while (WiFi.status() != WL_CONNECTED) {\n    delay(500);\n    Serial.print(\".\");\n    digitalWrite(ledPin, blink ? LOW : HIGH); // active low led\n    blink = !blink;\n  }\n  digitalWrite(ledPin, HIGH); // active low led\n\n  Serial.println(\"\");\n  Serial.print(\"Connected to \");\n  Serial.println(ssid);\n  Serial.print(\"IP address: \");\n  Serial.println(WiFi.localIP());\n  adapter = new WebThingAdapter(\"w25\", WiFi.localIP());\n\n  led.addProperty(\u0026ledOn);\n  adapter-\u003eaddDevice(\u0026led);\n  adapter-\u003ebegin();\n  Serial.println(\"HTTP server started\");\n  Serial.print(\"http://\");\n  Serial.print(WiFi.localIP());\n  Serial.print(\"/things/\");\n  Serial.println(led.id);\n}\n\nvoid loop(void) {\n  adapter-\u003eupdate();\n  bool on = ledOn.getValue().boolean;\n  digitalWrite(ledPin, on ? LOW : HIGH); // active low led\n  if (on != lastOn) {\n    Serial.print(led.id);\n    Serial.print(\": \");\n    Serial.println(on);\n  }\n  lastOn = on;\n}\n```\n\n## Configuration\n\n* If you have a complex device with large thing descriptions, you may need to\n  increase the size of the JSON buffers. The buffer sizes are configurable as\n  such:\n\n    ```cpp\n    // By default, buffers are 256 bytes for small documents, 1024 for larger ones\n\n    // To use a pre-defined set of larger JSON buffers (4x larger)\n    #define LARGE_JSON_BUFFERS 1\n\n    // Else, you can define your own size\n    #define SMALL_JSON_DOCUMENT_SIZE \u003csomething\u003e\n    #define LARGE_JSON_DOCUMENT_SIZE \u003csomething\u003e\n\n    #include \u003cThing.h\u003e\n    #include \u003cWebThingAdapter.h\u003e\n    ```\n\n# Adding to Gateway\n\nTo 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).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWebThingsIO%2Fwebthing-arduino","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FWebThingsIO%2Fwebthing-arduino","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWebThingsIO%2Fwebthing-arduino/lists"}