iot-bus Documentation, Release latest
adapter
=
new
WebThingAdapter(
"w25"
, WiFi.localIP());
const
char
*
ledTypes[]
=
{
"OnOffSwitch"
,
"led"
,
nullptr
};
ThingDevice
led
(
"LED"
,
"LED"
, ledTypes);
ThingProperty
ledOn
(
"On"
,
""
, BOOLEAN,
"OnOffProperty"
);
These are the the lines of code that define the Mozilla-IoT Thing and its properties.
const
char
*
ledTypes[]
=
{
"OnOffSwitch"
,
"led"
,
nullptr
};
This line defines an array of types ended by a null pointer. These types are @types, that is they are pre-defined types
that the Mozilla-IoT platform understands semantically. That is, what they are and how to render and interface with
them.
ThingDevice
led
(
"LED"
,
"LED"
, ledTypes);
This line defines a LED named LED. Note the reference to ledTypes defining the device type or types. Officially these
are described as capabilities. You can find the current list available
ThingProperty
ledOn
(
"on"
,
""
, BOOLEAN,
"OnOffProperty"
);
This defines a property “on” which has a property type of OnOffProperty. Again, this is a predefined property type.
Note:
There is no connection between the property and the device or adapter at this point. Although there is no
mention of an adapter here, it is an adapter that connects to a gateway and exposes its capabilities.
led.addProperty(
&
ledOn);
adapter
->
addDevice(
&
led);
adapter
->
begin();
These three lines add the ledOn property to the led, then add the device to the adapter and then start the adapter. Once
the adapter has started it can be recognized by the gateway.
{
"@context"
:
"https://iot.mozilla.org/schemas/"
,
"@type"
: [
"Light"
,
"OnOffSwitch"
],
"name"
:
"LED"
,
"description"
:
"LED"
,
"properties"
: {
"on"
: {
"@type"
:
"OnOffProperty"
,
"type"
:
"boolean"
,
"href"
:
"/things/led/properties/on"
},
This json extract illustrates What is happening under the covers. The arduino-webthing library is turning the definitions
above into JSON when it is polled by the gateway. This json describes the capabilities, properties, actions and events
that are possible with this device or devices. In theory there is no limit to what can be described in the schema.
However, in practice if you ant to control it using Mozilla-IoT it needs to be an @type that it knows how to render or
effectively fold into one of those types.
Most of the rest is boiler plate, but do note that you’ll want to take note of the ip address that is displayed on the
serial monitor once WiFi has started because you can use that ip address to get the raw json response provided by the
device once it is up and running. This is useful for debugging because you can see exactly what will be provided to
the gateway.
138
Chapter 40. LED Thing Tutorial
Summary of Contents for IoT-Bus
Page 1: ...iot bus Documentation Release latest oddWires Mar 05 2019...
Page 2: ......
Page 5: ...iot bus Documentation Release latest IoT Bus Introduction 1...
Page 6: ...iot bus Documentation Release latest 2 IoT Bus Introduction...
Page 16: ...iot bus Documentation Release latest 12 Chapter 1 IoT Bus Overview...
Page 17: ...CHAPTER 2 IoT Bus Pinout 13...
Page 18: ...iot bus Documentation Release latest Fig 1 IoT Bus Pinout 14 Chapter 2 IoT Bus Pinout...
Page 22: ...iot bus Documentation Release latest 18 Chapter 4 Getting Started with PlatformIO...
Page 24: ...iot bus Documentation Release latest 20 Chapter 5 Getting Started with Arduino...
Page 26: ...iot bus Documentation Release latest 22 Chapter 6 Getting Started with esp idf...
Page 32: ...iot bus Documentation Release latest 28 Chapter 7 Getting Started with Mozilla IoT...
Page 34: ...iot bus Documentation Release latest 30 Chapter 8 Getting Started with Micro Python...
Page 36: ...iot bus Documentation Release latest 32 Chapter 9 Getting Started with Moddable...
Page 38: ...iot bus Documentation Release latest 34 Chapter 10 Getting Started with MicroBlocks...
Page 50: ...iot bus Documentation Release latest 46 Chapter 13 JTAG...
Page 54: ...iot bus Documentation Release latest 50 Chapter 14 2 4 QVGA Touch Display...
Page 66: ...iot bus Documentation Release latest 62 Chapter 19 IoT Bus Examples Index...
Page 76: ...iot bus Documentation Release latest 72 Chapter 22 IoT Bus Touch Draw Example...
Page 78: ...iot bus Documentation Release latest 74 Chapter 23 IoT Bus Relay Example...
Page 94: ...iot bus Documentation Release latest 90 Chapter 27 IoT Bus SD_MMC Card Example...
Page 98: ...iot bus Documentation Release latest 94 Chapter 28 IoT Bus Mozilla IoT Examples...
Page 106: ...iot bus Documentation Release latest 102 Chapter 31 IoT Bus LED Lamp Thing...
Page 114: ...iot bus Documentation Release latest 110 Chapter 33 IoT Bus Relay Display Touch Thing...
Page 117: ...CHAPTER 35 IoT Bus DHT11 Thing include arduino h continues on next page 113...
Page 122: ...iot bus Documentation Release latest 118 Chapter 35 IoT Bus DHT11 Thing...
Page 130: ...iot bus Documentation Release latest 126 Chapter 37 IoT Bus HC SR501 PIR Thing...
Page 138: ...iot bus Documentation Release latest 134 Chapter 38 IoT Bus Calculator Thing...
Page 140: ...iot bus Documentation Release latest 136 Chapter 39 IoT Bus Mozilla IoT Tutorials...
Page 146: ...iot bus Documentation Release latest 142 Chapter 40 LED Thing Tutorial...
Page 152: ...iot bus Documentation Release latest 148 Chapter 41 Touch Switch Thing Tutorial...
Page 158: ...iot bus Documentation Release latest 154 Chapter 42 Mozilla Rules Engine...
Page 160: ...iot bus Documentation Release latest 156 Chapter 43 Frameworks...
Page 161: ...CHAPTER 44 Platforms 44 1 Espressif32 ESP WROOM32 WiFi Bluetooth Combo Module 157...