MultiLevelSensor Only Updates Second Thing

Hello

I’m using ESP8266 to create a simple temperature and humidity sensor pretty much following various examples available

WebThingAdapter* adapter;
const char* sensorTypes[] = {“MultiLevelSensor”, nullptr};
ThingDevice environmentalSensor(“TemperaturHumiditySensor”, “Temperature & Humidity Sensor”, sensorTypes);
ThingProperty temperature(“temperature”, “Temperature”, NUMBER, “TemperatureProperty”);
ThingProperty humidity(“humidity”, “Humidity”, NUMBER, “LevelProperty”);

I then initialize the sensors in my setup() routine

setup() {

adapter = new WebThingAdapter(“Temperature Humidity Sensor”, WiFi.localIP());
temperature.unit = “°C”;
temperature.readOnly = true;
humidity.unit = “%”;
humidity.readOnly = true;
environmentalSensor.title = thingLocationName;
environmentalSensor.addProperty(&temperature);
environmentalSensor.addProperty(&humidity);
adapter->addDevice(&environmentalSensor);
adapter->begin();
}

However, only the second sensor I “addProperty” gets updated. In the example above only humidity gets updated, if I flip the lines and add temperature last, only temperature gets updated. The other value stays, I believe, at the first value reported.

The sensor is providing correct values when looking at http://11.22.33.44/things/TemperaturHumiditySensor/properties/temperature

The internal log only shows getValue for humidity too. After a reboot of the gateway I see temperature value exactly one time followed by only humidity.

2019-11-30 10:45:19.010 INFO : thing-url: getValue for property humidity for: Bedroom returning 44.08316
2019-11-30 10:45:23.326 INFO : getValue for property humidity for: Bedroom returning 44.29678
2019-11-30 10:45:23.329 INFO : getValue for property temperature for: Bedroom returning 23.97854
2019-11-30 10:45:49.009 INFO : thing-url: getValue for property humidity for: Bedroom returning 44.29678
2019-11-30 10:46:19.014 INFO : thing-url: getValue for property humidity for: Bedroom returning 44.64774
2019-11-30 10:46:49.007 INFO : thing-url: getValue for property humidity for: Bedroom returning 45.12076
2019-11-30 10:47:19.012 INFO : thing-url: getValue for property humidity for: Bedroom returning 45.58615
2019-11-30 10:47:49.011 INFO : thing-url: getValue for property humidity for: Bedroom returning 46.21176
2019-11-30 10:48:19.013 INFO : thing-url: getValue for property humidity for: Bedroom returning 46.77634

The problem also exists if I just replace MultiLevelSensor by TemperatureSensor, which I would prefer because of the nicer look in the web interface.

I’m using webthing-arduino_ID5397, ArduinoJson_ID64 and mozilla-iot 0.10.0 on a raspberry pi 3.

Minor question. How do I set the title for the humidity. In the web-view it only shows as “<level>”.

Another question. Is there any way to purge the database of Things on my gateway? I see that during startup the gateway tries to connect to at least one Thing I just used for debugging

2019-11-30 10:44:55.741 INFO : thing-url: Failed to connect to http://10.0.0.140/things/EnvSensor: FetchError: request to http://10.0.0.140/things/EnvSensor failed, reason: connect EHOSTUNREACH 10.0.0.140:80

Thanks

1 Like

I tested a DHT11 connected to an ESP32 and noticed that I had to refresh my browser page to see the data for both variables. But both seem to work and both are updating. I used MicroBlocks instead of Arduino, since it is much faster (and easier). Screen shot inserted below. When you download the MicroBlocks IDE an example of the below temp/humidity program is available from the File menu.

 File => Open => [] By topic => [] Mozilla Web of Things => TempHumidity.ubp

Just make sure to insert your SSID and password, then click the green start arrow.

To delete old things from the database, you can write sql directly on the command line.

sqlite3 ~/.mozilla-iot/config/db.sqlite3 "select * from things"
sqlite3 ~/.mozilla-iot/config/db.sqlite3 "delete from things where id = '_id-2-del_’"

You might want to remove the temp/humidity thing (that isn’t working correctly) from the database, and try again. It seems like your example is pretty much the same as what James had created for Arduino, so not sure why it doesn’t work.

Thanks a lot for your detailed reply. I tried above sqlite commands and delete the only Thing that was in the db and verified that the table is empty afterwards. I had to reboot the gateway to make the Thing eventually disappear.
I then re-added the MultiLevelSensor, unfortunately with the same result. After adding the Thing the temperature is read exactly once and then only humidity is updated>

2019-12-01 13:37:41.707 INFO : getValue for property humidity for: Bedroom returning 51.68967
2019-12-01 13:37:41.709 INFO : getValue for property temperature for: Bedroom returning 19.67778
2019-12-01 13:37:52.944 INFO : thing-url: getValue for property humidity for: Bedroom returning 51.68967
2019-12-01 13:38:22.944 INFO : thing-url: getValue for property humidity for: Bedroom returning 52.12454
2019-12-01 13:38:52.941 INFO : thing-url: getValue for property humidity for: Bedroom returning 52.62045

@Oscar This issue is very similar. The author noted several issues at the end, one of which was due to the device crashing/rebooting and not coming back up in a clean state.

I was out this week and only now find the time to look at this again. @mrstegeman thanks for the link. I looked at the thread but beside adding MDNS.update(), which I honestly don’t believe is the problem because values for the second sensor are being updated properly, I don’t see anything that fits.
My Pi is running without complains. I purged the db and even re-imaged the SD card just to make sure everything is all-right.

I tried all three things suggested in Where to start debugging when things don't update. However, none of them work.
I get very stable updates of the humidity (or whatever Property I add last) but the first one only gets updated once after adding the Thing or rebooting the gateway.

Hi all,
I can confirm that I saw this behavior as well, but I didn’t check recently if it’s still present. At the time when I experienced it, I used the workaround of simply publishing multiple WebThing devices on the same physical device.

@Oscar: I can confirm, the MDNS.update() just helped to address a mDNS problem which is not related to the WebThingAdapter. I know the problem you’re mentioning and I used the described workaround…
I’m happy to test it again with the latest libs, but not sure when I find time to do it… I’ll keep you posted

Same problem. Workaround for me is to calls adapter->update after set value of each property. Like something:

tempProperty.setValue(tempValue);
adapter->update();
humProperty.setValue(humValue);
adapter->update();

1 Like

Yes, that worked perfectly. With just above mentioned changes I see all values now getting updated properly. Thanks a lot!

This is actually an issue with the Web Thing add-on. I’ll get it fixed later this week.

See: https://github.com/mozilla-iot/thing-url-adapter/issues/87

2 Likes

That’s great news! Thanks for the update.