Skip to content

Commit 6582f19

Browse files
authored
Merge pull request #56 from mozilla-iot/diegojuc-master
Manual updates to #47
2 parents 4af79db + 4de317c commit 6582f19

File tree

8 files changed

+61
-5
lines changed

8 files changed

+61
-5
lines changed

ESPWebThingAdapter.h

+21
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,27 @@ class WebThingAdapter {
167167
prop["type"] = "string";
168168
break;
169169
}
170+
171+
if (property->readOnly) {
172+
prop["readOnly"] = true;
173+
}
174+
175+
if (property->unit != "") {
176+
prop["unit"] = property->unit;
177+
}
178+
179+
const char **enumVal = property->propertyEnum;
180+
bool hasEnum = (property->propertyEnum != nullptr) && ((*property->propertyEnum) != nullptr);
181+
182+
if (hasEnum) {
183+
enumVal = property->propertyEnum;
184+
JsonArray &propEnum = prop.createNestedArray("enum");
185+
while (property->propertyEnum != nullptr && (*enumVal) != nullptr){
186+
propEnum.add(*enumVal);
187+
enumVal++;
188+
}
189+
}
190+
170191
if (property->atType != nullptr) {
171192
prop["@type"] = property->atType;
172193
}

Thing.h

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class ThingProperty {
3232
String atType;
3333
ThingProperty* next = nullptr;
3434

35+
bool readOnly = false;
36+
const char** propertyEnum = nullptr;
37+
String unit = "";
38+
3539
ThingProperty(const char* id_, const char* description_, ThingPropertyType type_, const char* atType_):
3640
id(id_),
3741
description(description_),

WiFi101WebThingAdapter.h

+21
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,27 @@ class WebThingAdapter {
429429
prop["type"] = "string";
430430
break;
431431
}
432+
433+
if (property->readOnly) {
434+
prop["readOnly"] = true;
435+
}
436+
437+
if (property->unit != "") {
438+
prop["unit"] = property->unit;
439+
}
440+
441+
const char **enumVal = property->propertyEnum;
442+
bool hasEnum = (property->propertyEnum != nullptr) && ((*property->propertyEnum) != nullptr);
443+
444+
if (hasEnum) {
445+
enumVal = property->propertyEnum;
446+
JsonArray &propEnum = prop.createNestedArray("enum");
447+
while (property->propertyEnum != nullptr && (*enumVal) != nullptr){
448+
propEnum.add(*enumVal);
449+
enumVal++;
450+
}
451+
}
452+
432453
if (property->atType != nullptr) {
433454
prop["@type"] = property->atType;
434455
}

examples/PlatformIO/BME280/platformio.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ env_default = samw25
1919
; https://platformio.org/lib/show/2848/ArduinoMDNS
2020
lib_deps =
2121
https://github.com/mozilla-iot/webthing-arduino.git
22-
ArduinoJson
22+
ArduinoJson@5.13.4
2323
WiFi101
2424
ArduinoMDNS
2525
BME280

examples/PlatformIO/BME280/src/BME280.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545

4646
WebThingAdapter* adapter;
4747

48-
const char* bme280Types[] = {nullptr};
48+
const char* bme280Types[] = {"TemperatureSensor", nullptr};
4949
ThingDevice weather("bme280", "BME280 Weather Sensor", bme280Types);
50-
ThingProperty weatherTemp("temperature", "", NUMBER, nullptr);
50+
ThingProperty weatherTemp("temperature", "", NUMBER, "TemperatureProperty");
5151
ThingProperty weatherHum("humidity", "", NUMBER, nullptr);
5252
ThingProperty weatherPres("pressure", "", NUMBER, nullptr);
5353

@@ -122,6 +122,7 @@ void setup() {
122122
digitalWrite(LED_BUILTIN, PIN_STATE_HIGH);
123123
adapter = new WebThingAdapter("weathersensor", WiFi.localIP());
124124

125+
weatherTemp.unit = "c";
125126
weather.addProperty(&weatherTemp);
126127
weather.addProperty(&weatherPres);
127128
weather.addProperty(&weatherHum);

examples/PlatformIO/LED/platformio.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
[global]
1919
lib_deps =
2020
https://github.com/mozilla-iot/webthing-arduino.git
21-
ArduinoJson
21+
ArduinoJson@5.13.4
2222
monitor_speed = 115200
2323

2424
[env:d1]

examples/PlatformIO/TextDisplay/platformio.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
[global]
1818
lib_deps =
1919
https://github.com/mozilla-iot/webthing-arduino.git
20-
ArduinoJson
20+
ArduinoJson@5.13.4
2121
Adafruit GFX Library
2222
Adafruit SSD1306
2323

examples/RGBLamp/RGBLamp.ino

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ const int ledPin = LED_BUILTIN;
2525
const int ledPin = 13; // manully configure LED pin
2626
#endif
2727

28+
//for optional properties
29+
//const char * valEnum[5] = {"RED", "GREEN", "BLACK", "white", nullptr};
30+
//const char * valEnum[5] = {"#db4a4a", "#4adb58", "000000", "ffffff", nullptr};
31+
2832
WebThingAdapter* adapter;
2933

3034
const char* deviceTypes = {"Light", "OnOffSwitch", "ColorControl", nullptr};
@@ -89,6 +93,11 @@ void setup(void) {
8993
deviceLevel.setValue(levelValue);
9094
device.addProperty(&deviceLevel);
9195

96+
//optional properties
97+
//deviceColor.propertyEnum = valEnum;
98+
//deviceColor.readOnly = true;
99+
//deviceColor.unit = "HEX";
100+
92101
ThingPropertyValue colorValue;
93102
colorValue.string = &lastColor; //default color is white
94103
deviceColor.setValue(colorValue);

0 commit comments

Comments
 (0)