From 33955ab40002939f4f05232c66f8b0830e0550a7 Mon Sep 17 00:00:00 2001 From: Christian Erhardt Date: Thu, 2 May 2019 12:05:06 +0200 Subject: [PATCH] Fixes #1 Improved Wire.h usage As recommended, the code was changed according to @Koepels recommendation. I verified the changes on my sensor and it is working. --- README.md | 2 +- src/esp-soil-moisture-sensor.cpp | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ef19074..d605f70 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # esp-soil-moisture-sensor -[![Latest Release](https://img.shields.io/badge/release-v1.0.0-yellow.svg?style=flat-square)](https://github.com/MoJo2600/esp-soil-moisture-sensor/releases) [![PlatformIO](https://img.shields.io/badge/Powered-PlatformIO-blue.png)](https://platformio.org/lib/show/555/Homie) [![Homie](https://img.shields.io/badge/Powered-Homie-red.svg)](https://github.com/homieiot/homie-esp8266) +[![Latest Release](https://img.shields.io/badge/release-v1.0.1-yellow.svg?style=flat-square)](https://github.com/MoJo2600/esp-soil-moisture-sensor/releases) [![PlatformIO](https://img.shields.io/badge/Powered-PlatformIO-blue.png)](https://platformio.org/lib/show/555/Homie) [![Homie](https://img.shields.io/badge/Powered-Homie-red.svg)](https://github.com/homieiot/homie-esp8266) This repository contains code to use the [Homie](https://homieiot.github.io/homie-esp8266/docs/develop-v3/quickstart/what-is-it/) framework and its IoT convention with a soil moisture sensor from [April Brothers](https://wiki.aprbrother.com/en/ESP_Soil_Moisture_Sensor.html) (Source and schematic: https://github.com/AprilBrother/esp-soil-moisture-sensor). When this firmware is running, the sensor will publish it's sensor readings in the homie [convention format](https://homieiot.github.io/specification/spec-core-v2_0_1/). Based on the work of ve2cuz - [Real Drouin](https://www.qsl.net/v/ve2cuz//garden/) diff --git a/src/esp-soil-moisture-sensor.cpp b/src/esp-soil-moisture-sensor.cpp index 2733c87..8ce837f 100644 --- a/src/esp-soil-moisture-sensor.cpp +++ b/src/esp-soil-moisture-sensor.cpp @@ -191,10 +191,9 @@ void getSendTemperature() { // Request 2 bytes , Msb first to get temperature Wire.requestFrom(TMP_ADDR, 2); // Read temperature as Celsius (the default) - while(Wire.available()) { + if(Wire.available() == 2) { int msb = Wire.read(); int lsb = Wire.read(); - Wire.endTransmission(); int rawtmp = msb << 8 | lsb; int value = rawtmp >> 4; @@ -272,7 +271,7 @@ void setup() { #endif } - Homie_setFirmware("esp-soil-moisture-sensor", "1.0.0"); + Homie_setFirmware("esp-soil-moisture-sensor", "1.0.1"); // Configure homie to use the build in button for configuration reset // Press and hold button for 2sec to reset the homie configuration